
Multidimensional algorithms and iteration in Julia - one-more-minute
http://julialang.org/blog/2016/02/iteration/
======
shoyer
This is a fantastic step forward for Julia, and array-oriented computing in
general.

Routines that smoothly generalize to arrays with an arbitrary number of
dimensions is also a strength of NumPy -- it's the core idea behind NumPy's
"universal functions" [1] like sin or exp.

Writing custom ufuncs in C is not easy, but Numba makes it straightforward to
write fast ufuncs in Python [2]. For many of the use cases described here,
it's a pretty solid alternative. In general, I think Numba's ufuncs are under-
appreciated -- they make it easy to write fast code that works on any number
of array dimensions, and even automatically respect metadata when called on
array-like objects from third party libraries like pandas.

Unfortunately, we don't have abstractions quite as powerful as eachindex and
CartesianRange in NumPy/Numba. This makes for some awkward work-arounds and
optimization constraints (e.g., see my project Numbagg [3], and discussions on
the Numba issue tracker [4]). That said, I don't think there's any reason why
these abstractions couldn't also be implemented in Numba, and I would love to
see that happen.

[1]
[http://docs.scipy.org/doc/numpy/reference/ufuncs.html](http://docs.scipy.org/doc/numpy/reference/ufuncs.html)
[2] [http://numba.pydata.org/numba-
doc/0.23.1/user/vectorize.html](http://numba.pydata.org/numba-
doc/0.23.1/user/vectorize.html) [3]
[https://github.com/shoyer/numbagg](https://github.com/shoyer/numbagg) [4]
e.g.,
[https://github.com/numba/numba/issues/841](https://github.com/numba/numba/issues/841)

~~~
tadlan
What about dynd? Iirc doesn't use iteration st all.

------
jordigh

        In many languages, writing a general (N-dimensional)
        implementation of this conceptually-simple algorithm is somewhat
        painful, but in Julia it’s a piece of cake:
    

Indeed, for the Octave implementation of bwlabeln[1] I had to do something
like that for considering the n-dimensional neighbours of each voxel in C++. I
ended up padding the Nd-array with zeros. What do people normally do in
languages that are not Julia?

\--

[http://sourceforge.net/p/octave/image/ci/default/tree/src/bw...](http://sourceforge.net/p/octave/image/ci/default/tree/src/bwlabeln.cc#l101)

------
jpfr
Python has itertools.product to iterate over the cartesian product of two
lists. Some of the most elegant code I ever wrote is due to this abstraction.

[https://docs.python.org/2/library/itertools.html#itertools.p...](https://docs.python.org/2/library/itertools.html#itertools.product)

~~~
elcritch
`itertools` comes in real handy in some cases. I just wish it didn't require a
special import. Have you used the itertools.partition much? It's pretty handy
as well.

The fun part with Julia is the ability to use these style of for-loops to
generate code to run arbitrary N-dimensional computations based on the
specific input array sizes. Not sure exactly what they're doing
[here]([https://medium.com/@acidflask/smoothing-data-with-julia-s-
ge...](https://medium.com/@acidflask/smoothing-data-with-julia-s-generated-
functions-c80e240e05f3#.ji8w9kehh)) but it looks cool!

