[SciPy-user] 2D arrays in weave.inline
Prabhu Ramachandran
prabhu at aero.iitb.ac.in
Sat Nov 17 20:13:43 EST 2007
Stefan van der Walt wrote:
> On Sat, Nov 17, 2007 at 04:44:52PM -0600, Alan Jackson wrote:
>> On Sat, 17 Nov 2007 22:46:59 +0100
>> Well, with my *real* code, blitz gave me several pages of errors - I tried
>> treating the 2D arrays as a 1D array, doing all the index arithmetic myself,
>> and that seems to work. Which strikes me as odd...
>
> With Blitz, you are allowed M(i,j) indexing. Otherwise, only the
> memory address of the data is passed and, as you noticed, you must
> calculate the offset yourself, i.e. M[i*nr_cols + j].
Travis added a few macros to automate this calculation (for non-blitz
cases). If you passed in 'a' then A1(i), A2(i, j) A3(i, j, k) and A4(i,
j, k, l) are all defined. Here are the macros:
#define A1(i) (*((long*)(a_array->data + (i)*Sa[0])))
#define A2(i,j) (*((long*)(a_array->data + (i)*Sa[0] + (j)*Sa[1])))
#define A3(i,j,k) (*((long*)(a_array->data + (i)*Sa[0] + (j)*Sa[1] +
(k)*Sa[2])))
#define A4(i,j,k,l) (*((long*)(a_array->data + (i)*Sa[0] + (j)*Sa[1] +
(k)*Sa[2] + (l)*Sa[3])))
cheers,
prabhu
More information about the SciPy-User
mailing list