Skip to content

Instantly share code, notes, and snippets.

@anyuzx
anyuzx / pdist_cython_parallel.pyx
Last active Oct 24, 2019
setup.py for parallel Cython codes shown in the blog post
View pdist_cython_parallel.pyx
# cython: language_level=3
import cython
import numpy as np
from cython.parallel import prange, parallel
from libc.math cimport sqrt
from libc.math cimport nearbyint
@cython.boundscheck(False)
@cython.wraparound(False)
@anyuzx
anyuzx / pdist_benchmark_pure_python.ipynb
Last active Oct 7, 2019
pdist_benchmark_pure_python
View pdist_benchmark_pure_python.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View pivot_algorithm.cpp
//
// This is a lattice random walk config generator using pivot algorithm.
// can be self-avoid or not self-avoid
// lattice_SAW(chain array, number of steps(monomers), step length(bond), self-avoid or no-self-avoid)
//
// Created by guangshi on 8/25/14.
// Copyright (c) 2014 Guang Shi. All rights reserved.
//
#include <math.h>
@anyuzx
anyuzx / random-walk-pyodide.js
Last active Sep 24, 2019
A random walk example of using Pyodide
View random-walk-pyodide.js
// dynamically load the script on demand
class ScriptLoader {
constructor(script) {
this.script = script;
this.scriptElement = document.createElement('script');
this.head = document.querySelector('head');
}
load () {
return new Promise((resolve, reject) => {
@anyuzx
anyuzx / random_walk_2d.py
Last active Sep 23, 2019
Generate 2D random walk trajectory
View random_walk_2d.py
import numpy as np
def walk(n):
# check if the number of steps is an integer
if int(n) != n:
print('number of steps should be an integer')
return None
# the initial position is (0,0)
xy_0 = np.array([0.0, 0.0])
# generate displacements of each step
View test.py
import numpy as np
x = np.random.rand(1000)
y = np.random.rand(1000)
View mdrnn_blog_block4.py
def next_batch_nonlinear_map(bs, h, w, anisotropy=True):
# ... same code ...
y.append(np.dot(item, item)) # only changes here
# ... same code ...
View mdrnn_blog_block3.py
anisotropy = False
learning_rate = 0.005
batch_size = 200
h = 10
w = 10
channels = 1
x = tf.placeholder(tf.float32, [batch_size, h, w, channels])
y = tf.placeholder(tf.float32, [batch_size, h, w, channels])
linear_map = np.random.rand(h,w)
View pivot_algorithm_python.py
import numpy as np
import timeit
from scipy.spatial.distance import cdist
# define a dot product function used for the rotate operation
def v_dot(a):return lambda b: np.dot(a,b)
class lattice_SAW:
def __init__(self,N,l0):
self.N = N
@anyuzx
anyuzx / extract_pid.md
Created Feb 19, 2017
extract pid from ps aux command
View extract_pid.md
ps aux | grep name | grep -v grep
ps aux | grep name | grep -v grep | awk '{print $2}'