Skip to content

Instantly share code, notes, and snippets.

@rohanp
Created January 6, 2015 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rohanp/a7d2048954377fa9e2bb to your computer and use it in GitHub Desktop.
Save rohanp/a7d2048954377fa9e2bb to your computer and use it in GitHub Desktop.
Cython Example
cdef DTYPE_t getEpsilon(int xi, DTYPE_t[:,:] RMSD, DTYPE_t[:] epsilonList, DTYPE_t[:] derivativeEpsilonList, int N):
cdef DTYPE_t e,k
cdef int i,j,x,y,neighborsLength
cdef DTYPE_t[:,:] eigenValues=np.zeros((len(derivativeEpsilonList),N), dtype=DTYPE)
cdef DTYPE_t[:,:] neighborsMatrix
cdef DTYPE_t[:] A
for i,e in enumerate(derivativeEpsilonList):
neighbors=[]
for j in range(N):
if(RMSD[xi,j]<=e+.01):
neighbors.append(j)
neighborsLength=len(neighbors)
if neighborsLength>1:
neighborsMatrix=np.zeros((neighborsLength,neighborsLength), dtype=DTYPE)
for x in range(neighborsLength):
for y in range(neighborsLength):
neighborsMatrix[x][y]=RMSD[x,neighbors[y]]
A=np.linalg.svd(neighborsMatrix, compute_uv=False)
for j,k in enumerate(A):
eigenValues[i][j]=k*k
else:
print "maxEpsilon too small! Try again with a larger maxEpsilon value."
return derivativeEpsilonList[i+3]
eps= getIntrinsicScaleAndDim(xi,eigenValues, epsilonList, derivativeEpsilonList)
return eps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment