liberfa/erfa-wrapping-experiments — pull request #9 by jwoillez (2014-10-23 12:56:30+00:00)
Title: New Python iterator approach: vectorise without dtype

Have a look only a the last two commit. This is a continuation of another PR.

To give it a spin:

import erfa.nditer as erfa

import numpy as np

pnat = np.zeros([2,3], dtype=np.double)
v = np.zeros([5,1,3], dtype=np.double)
s = 1.0
bm1 = np.sqrt(1.0-0.1**2)

pnat[:,0] = 1.0
v[:,:,1] = 0.01

print(pnat)
print(v)
print(s)
print(bm1)

ppr = erfa.ab(pnat, v, s, bm1)

print(ppr)

The only tricky part in the implementation is that `NpyIter` is not exposed in `numpy.pxd`. This requires the use of private `NpyIter_GetDataPtrArray()` from `numpy/arrayobject.h`. This implementation is inspired from https://github.com/rainwoodman/chealpy/blob/master/chealpy/npyiter.pxd

It could be further improved by including the output parameter `ppr` in the iterator itself. This would save indexation time, after the call to `eraAb`...