Created
October 16, 2012 18:37
-
-
Save mattjj/3901139 to your computer and use it in GitHub Desktop.
hn wes benchmark followup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
cimport numpy as np | |
ctypedef np.float64_t float64_t | |
def inner(np.ndarray[float64_t] x, np.ndarray[float64_t] y): | |
cdef Py_ssize_t i, n = len(x) | |
cdef float64_t result = 0 | |
for i in range(n): | |
result += x[i] * y[i] | |
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from distutils.core import setup | |
from distutils.extension import Extension | |
from Cython.Distutils import build_ext | |
import numpy | |
setup( | |
cmdclass = {'build_ext': build_ext}, | |
ext_modules = [Extension("inner", ["inner.pyx"],include_dirs=[numpy.get_include()])] | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Aaaand finally array operations in Julia (via
sum(x.*y)
), which is really the better comparison to the numpy example, took 91.3 ms.