Skip to content

Instantly share code, notes, and snippets.

Heikki Arponen harpone

Block or report user

Report or block harpone

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Tensorflow_py_func_with_grad.py
import tensorflow as tf
from tensorflow.python.framework import ops
import numpy as np
# Define custom py_func which takes also a grad op as argument:
def py_func(func, inp, Tout, stateful=True, name=None, grad=None):
# Need to generate a unique name to avoid duplicates:
rnd_name = 'PyFuncGrad' + str(np.random.randint(0, 1E+8))
View gist:3e5f53edee3ecb615f8f
import numpy as np
cimport cython
cimport numpy as np
from libc.stdint cimport uint32_t, int32_t
from libc.math cimport sqrt
from libc.math cimport fabs
from libc.math cimport pow
View gist:401b91d48652d7138844
def simulation(L = 0, N = 100000, dt = 1E-3, init = .1):
"""Simulate a stochastic differential equation.
"""
#Set up some parameters:
f1 = .1
g1 = .01
g2 = .1
dW = np.random.randn(N)*np.sqrt(dt)
@harpone
harpone / Cython
Last active Aug 29, 2015
Stochastic differential equations: Python+Numpy vs. Cython. FIGHT!!
View Cython
# Same with Cython:
import numpy as np
cimport cython
cimport numpy as np
from libc.stdint cimport uint32_t, int32_t
from libc.math cimport sqrt
from libc.math cimport fabs
from libc.math cimport pow
You can’t perform that action at this time.