Live data from Hacker News

Using D and std.ndslice as a Numpy Replacement

jackstouffer.com

1–10 of 59 posts

Re: Using D and std.ndslice as a Numpy Replacement

#3
post #2

Use numba to compile python loops or array expressions to fast llvm, and problem solved. I'm sticking with python.

Considering that in the benchmarked example, only one like of Numpy code was used which already uses compiled C, I have a hard time believing that that would catch up to using all compiled code.

Re: Using D and std.ndslice as a Numpy Replacement

#4
Am I correct in thinking that this is only reasonable if you're already using D? The switching cost seems too high if you're python everything.

I tried the Armadillo C++ library a while ago (http://arma.sourceforge.net/). The speed up and time spend learning the syntax didn't seem worth it.

Re: Using D and std.ndslice as a Numpy Replacement

#5
post #4

Am I correct in thinking that this is only reasonable if you're already using D? The switching cost seems too high if you're python everything. I tried the Armadillo C++ library a while ago ( http://arma.sourceforge.net/ ). The speed up and time spend learning the syntax didn't seem worth it.

I completely understand that for existing projects it might not make sense to switch, but as I say at the start of the article

    why you should consider D for your next numerical project.

Re: Using D and std.ndslice as a Numpy Replacement

#6
post #3
post #2

Use numba to compile python loops or array expressions to fast llvm, and problem solved. I'm sticking with python.

Considering that in the benchmarked example, only one like of Numpy code was used which already uses compiled C, I have a hard time believing that that would catch up to using all compiled code.

Numbs compiles entire functions on and allows array expressions with allocation and loop fusion. I don't see the problem

Re: Using D and std.ndslice as a Numpy Replacement

#7
post #6
post #3

Earlier quoted context omitted.

Considering that in the benchmarked example, only one like of Numpy code was used which already uses compiled C, I have a hard time believing that that would catch up to using all compiled code.

Numbs compiles entire functions on and allows array expressions with allocation and loop fusion. I don't see the problem

The benchmarked code is ALREADY a comiled C function called from Python and it still lost.

Re: Using D and std.ndslice as a Numpy Replacement

#8
Does D have code for: plotting, optimization, probability distributions, machine learning, Fourier transformations, masked arrays, finanial calculations, structured arrays (read a CSV from disk, get named columns based on the header), SVD, QR and Cholesky decomposition, eigens, least squares, Levenberg Marquardt, matrix inverse and pseudoinverses, integration, Runge Kutta, interpolation, bsplines, fft convolves, multidimensional images, KDTrees, symbolic equation solvers, merge/join of data sets, etc.?

Because I use almost all of these every single day (I don't do multidimensional images or b-splines much at all). Are those all in standard libraries, fully documented, backed by 60 year old, fully debugge code (LAPACK, etc), that I reliably email to anyone across the world and they can immediately run and modify my code because it is such a standard? I honestly don't know, but I'm guessing not.

I use Python/Numpy/Scipy/Pandas/Matplotlib because everyone else in the world knows and uses them; they are a standard. Yes, my np.mean() might be slower than your map(). I almost always don't care. That misses the forest for the trees.

The article might be a good argument for why library writers might consider building out D's standard library to support numerical computation, I dunno. But no one is going to use D for serious number crunching without that infrastructure in place. People moved from Fortran and Matlab to Python not because it is fast, but for the environment. These language tricks are cute and all (I like D well enough, don't get me wrong), but it ain't why we are using Python.

At this point, if I were to switch languages to something without a lot of adoption I'd lean towards Julia. It also have a modern language design, but it is written from the ground up for numerical computation. I can't think of any reason I'd ever reach for D.

Re: Using D and std.ndslice as a Numpy Replacement

#9
post #7
post #6

Earlier quoted context omitted.

Numbs compiles entire functions on and allows array expressions with allocation and loop fusion. I don't see the problem

The benchmarked code is ALREADY a comiled C function called from Python and it still lost.

Numba would still be faster. It would fuse away any intermediates in the code and remove any Overhead to the compiled code.

also have the option of devecting to loops.

both of which are generally faster than vectorized jumpy code.

Re: Using D and std.ndslice as a Numpy Replacement

#10
And here we have a case of why microbenchmarks don't work. What you're measuring here isn't a speed difference in the mathematical code, its a constant time overhead from calling into the numerical libs. Up your array size by 100 times and this will become evident.

Why do I say this? Because inlining the python function to

means = numpy.mean(numpy.arange(100000).reshape((100, 1000)), axis=0)

from the original example in the article cut the benchmark time in down from around 215us to 205 us in my testing. That was done by removing a single python bytecode instruction.

Its quite likely that the D numerical code is actually slower than the LAPACK based python numerical code, but you're hiding this in the constant time overhead of a few python function calls.

Post reply on HN