I need a function that is the inverse of PyArray_ITER_GOTO1D. A bit of
guesswork brought me to this, can anyone please tell me if it looks
correct?
inline npy_intp as_linear (PyArrayIterObject const* it) {
if (it->nd_m1 == 0)
return (it->dataptr - it->ao->data)/it->strides[0];
else if (it->contiguous)
return (it->dataptr - it->ao->data)/it->ao->descr->elsize;
else {
npy_intp loc = 0;
npy_intp offset = (it->dataptr - it->ao->data)/it->ao->descr->elsize;
for (int i = 0; i <= it->nd_m1; ++i) {
loc += offset / it->factors[i];
offset %= it->factors[i];
}
return loc;
}
}
_______________________________________________
Numpy-discussion mailing list
[email protected]
http://projects.scipy.org/mailman/listinfo/numpy-discussion