numpy/numpy — pull request #4509 by jaimefrio (2014-03-17 21:54:33+00:00)
Title: ENH: speed-up of triangular matrix functions

* `np.tri` now produces less intermediate arrays. Runs about 40% faster for
general dtypes, up to 3x faster for boolean arrays. Added an `invert`
keyword to generate the inverse of the array without intermediate calls.
* `np.triu` uses the `invert` keyword in its call to `np.tri`, which avoids
an intermediate array. It now runs at the same speed as `np.tril` (used to
be 50% slower). Both `np.triu` and `np.tril` run about 10% faster than
`np.tril` used to, due to the speed-up of `np.tri`.
* `np.triu_indices` and `np.tril_indices` do not call `np.mask_indices`,
instead they call `np.where` directly on a boolean array created with
`np.tri`. They now run roughly 2x faster.
* Removed the constraint for the array to be square in calls to
`np.triu_indices`, `np.tril_indices`, `np.triu_indices_from` and
`np.tril_indices_from`.