Skip to content

Instantly share code, notes, and snippets.

View synapticarbors's full-sized avatar

Joshua Adelman synapticarbors

View GitHub Profile
@synapticarbors
synapticarbors / make_data.py
Created November 24, 2014 15:55
StrPack test
import numpy as np
import mmap
import os
N = 5
dtype = [('a', np.float64), ('b', np.int32), ('c', np.float32), ('d', np.int16), ('e', 'S4')]
names = [a[0] for a in dtype]
columns = [np.random.normal(size=(N,)).astype(np.float64),
np.random.normal(size=(N,)).astype(np.int32),
@synapticarbors
synapticarbors / gen_bstate.py
Created November 4, 2014 02:06
NetCDFReporter problem
import os
import numpy as np
import argparse
import simtk
import simtk.unit as units
import simtk.openmm as openmm
import wcadimer
import numpy as np
cimport numpy as np
cimport cython
@cython.boundscheck(False)
@cython.wraparound(False)
cpdef cython_lstsqr(x_ary, y_ary):
""" Computes the least-squares solution to a linear matrix equation. """
cdef double x_avg, y_avg, var_x, cov_xy,\
slope, y_interc
cdef double[:] x = x_ary # memory view
@synapticarbors
synapticarbors / integrators.py
Last active August 29, 2015 14:01
Modified WCA-dimer script that uses CustomIntegrator for GHMC propagation. The Integrator module is available at: https://github.com/choderalab/openmm-tests/blob/master/energy-rms/integrators.py
#=============================================================================================
# MODULE DOCSTRING
#=============================================================================================
"""
Custom integrators.
DESCRIPTION
@synapticarbors
synapticarbors / base.pxd
Created April 18, 2014 19:36
Compile error under master branch of Cython but not v0.19.2
import numpy as np
cimport numpy as np
cdef unsigned int fix

I made a few optimizations to the cython code. The timings on my machine are:

from sequences import P53_HUMAN, P53_MOUSE
from alignment import align as py_align
from align_numpy import align as cy_align
from align_numpy2 import align as cy_align2
 
%timeit py_align(P53_HUMAN, P53_MOUSE)
1 loops, best of 3: 442 ms per loop
@synapticarbors
synapticarbors / feed.xml
Created February 7, 2014 21:39
Snapshot of Journal of Chemical Physics RSS feed
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel rdf:about="http://scitation.aip.org">
<title>New content is available for The Journal of Chemical Physics</title>
<link>http://scitation.aip.org</link>
<description>New content is now available online. Please follow the links to view the content.</description>
<items>
<rdf:Seq>
<rdf:li/>
<rdf:li/>
@synapticarbors
synapticarbors / numba_bench.ipynb
Created January 13, 2014 01:28
Benchmarking some code from the numba mailing list
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@synapticarbors
synapticarbors / Timings.py
Last active August 10, 2023 01:08
Attempt to create a faster version of a Euclidean pairwise distance method in cython using BLAS. Strategy for including BLAS taken from the Tokyo project.
In [1]: import numpy as np
In [2]: from scipy.spatial.distance import cdist
In [3]: from distlib import pairwise_cython_blas, pairwise_cython
In [4]: a = np.random.random(size=(1000,3))
In [5]: %timeit cdist(a,a)
100 loops, best of 3: 11.3 ms per loop
from numba import jit, random, int_, float32, void, object_, double, uint32, ulong
import math
import numpy as np
float32_2d = float32[:,::1]
@jit
class Force(object):
@int_(float32[::1], float32[::1])