Skip to content

Commit

Permalink
modified setup and short dot
Browse files Browse the repository at this point in the history
  • Loading branch information
cemoody committed Nov 11, 2013
1 parent 4369f22 commit b20bdea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 11 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
#!/usr/bin/env python

from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
from Cython.Distutils import build_ext

import numpy


setup(
ext_modules = cythonize("shortdot.pyx")
cmdclass = {'build_ext': build_ext},
ext_modules = [Extension("shortdot",
sources=["shortdot.pyx"],
include_dirs=[numpy.get_include()])],
)
6 changes: 2 additions & 4 deletions shortdot.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ cimport numpy as np

@cython.boundscheck(False)
@cython.wraparound(False)
cdef np.ndarray[double, ndim=1] shortdot(
def shortdot(
np.ndarray[float, ndim=2] A,
np.ndarray[float, ndim=1] B,
np.ndarray[double, ndim=1] C,
float threshold = -3.0):
'''
Matrix-vector multiplication.
Expand All @@ -20,14 +21,11 @@ cdef np.ndarray[double, ndim=1] shortdot(
int A_m = A.shape[1]
int B_n = B.shape[0]
double tot = 0.0
np.ndarray[double, ndim=1] C

# Initialize the results matrix.
C = np.zeros(A_n)
for i in xrange(A_n):
for j in xrange(A_m):
tot += A[i, j] * B[j]
if j > 10 and tot < threshold:
break
C[i] = tot
return C

0 comments on commit b20bdea

Please sign in to comment.