Skip to content

Instantly share code, notes, and snippets.

View upul's full-sized avatar
🎯
Focusing

Upul Bandara upul

🎯
Focusing
View GitHub Profile
@ctokheim
ctokheim / cython_tricks.md
Last active March 4, 2024 23:27
cython tricks

Cython

Cython has two major benefits:

  1. Making python code faster, particularly things that can't be done in scipy/numpy
  2. Wrapping/interfacing with C/C++ code

Cython gains most of it's benefit from statically typing arguments. However, statically typing is not required, in fact, regular python code is valid cython (but don't expect much of a speed up). By incrementally adding more type information, the code can speed up by several factors. This gist just provides a very basic usage of cython.

# Hello, and welcome to makefile basics.
#
# You will learn why `make` is so great, and why, despite its "weird" syntax,
# it is actually a highly expressive, efficient, and powerful way to build
# programs.
#
# Once you're done here, go to
# http://www.gnu.org/software/make/manual/make.html
# to learn SOOOO much more.
@karpathy
karpathy / min-char-rnn.py
Last active April 21, 2024 00:57
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)
@danoneata
danoneata / visitor.py
Created November 19, 2015 23:41
Visitor pattern in Python
class Expr(object):
def accept(self, visitor):
method_name = 'visit_{}'.format(self.__class__.__name__.lower())
visit = getattr(visitor, method_name)
return visit(self)
class Int(Expr):
def __init__(self, value):
self.value = value
@parmentf
parmentf / GitCommitEmoji.md
Last active April 23, 2024 10:28
Git Commit message Emoji
@twiecki
twiecki / bayesian_neural_network.ipynb
Last active February 22, 2022 01:28
Bayesian Neural Network in PyMC3
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@siemanko
siemanko / tf_lstm.py
Last active July 26, 2023 06:57
Simple implementation of LSTM in Tensorflow in 50 lines (+ 130 lines of data generation and comments)
"""Short and sweet LSTM implementation in Tensorflow.
Motivation:
When Tensorflow was released, adding RNNs was a bit of a hack - it required
building separate graphs for every number of timesteps and was a bit obscure
to use. Since then TF devs added things like `dynamic_rnn`, `scan` and `map_fn`.
Currently the APIs are decent, but all the tutorials that I am aware of are not
making the best use of the new APIs.
Advantages of this implementation:
@jaanli
jaanli / black_box_vi_bayesian_linear_regression.py
Created February 11, 2017 17:32
Black box variational inference for Bayesian linear regression. Numpy and scipy only.
"""Use black-box variational inference (https://arxiv.org/abs/1401.0118) to
fit Bayesian linear regression (https://en.wikipedia.org/wiki/Bayesian_linear_regression)
and ensure it gets the analytic posterior mean from wikipedia.
"""
import numpy as np
import scipy.stats
def generate_data(cfg):
"""synthetic data:
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@goldsborough
goldsborough / conv.cu
Last active November 27, 2023 05:59
Convolution with cuDNN
#include <cudnn.h>
#include <cassert>
#include <cstdlib>
#include <iostream>
#include <opencv2/opencv.hpp>
#define checkCUDNN(expression) \
{ \
cudnnStatus_t status = (expression); \
if (status != CUDNN_STATUS_SUCCESS) { \