[SciPy-user] 2D arrays in weave.inline

Stefan van der Walt stefan at sun.ac.za
Sat Nov 17 18:13:44 EST 2007


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].

I modified your code to work with ctypes, which you may find
interesting.

Use

  python setup.py build_ext -i

to build the C file.  Then run alan.py.

Cheers
Stéfan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: setup.py
Type: text/x-python
Size: 461 bytes
Desc: not available
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20071118/bf802271/attachment.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: alan.c
Type: text/x-csrc
Size: 243 bytes
Desc: not available
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20071118/bf802271/attachment.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: alan.py
Type: text/x-python
Size: 1973 bytes
Desc: not available
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20071118/bf802271/attachment-0001.py>


More information about the SciPy-User mailing list