jstac/quant-econ — pull request #46 by albop (2014-08-10 18:37:52+00:00)
Title: Added cartesian product.

This is one step to adress #35 .
After some experiments, I wrote a new function `cartesian` to compute the cartesian product of a series of vectors. The function accepts an `order` keyword to switch between `C` and Fortran order. It is meant to replace the function in `ce_tool`.
The behaviour of the current `gridmake` function can be replicated by `def gridmake(*a): return cartesian(*a, order='C')` (or `F` during the transition).
There is also a `mlinspace(a,b,ndims,order='C')` function which naturally extends `linspace` for multidimensional vectors spaces.
The intensive work is done in a numba helper function that essentially merges `repeat` and `tile` for 1d vectors (inspired by Julia's `repeat` function). It is very simple and njitted. Because there is no creation of intermediary arrays, the new function is approximately 30% faster on my laptop than the stackoverflow solution.
I wrote simple performance and compliance tests, but I didn't know how to distinguish them so I kept them on the same level.