From: Todd M. <jm...@st...> - 2003-03-08 12:01:03
|
Sebastian Haase wrote: >Thanks, SO MUCH ... >I almost went crazy yesterday - and was really desperate by the time= I wrote >that email. >Somehow I newer needed that offset field until now. So: when I do t= he >NA_InputArray call I get a "proper" C-array >just that it does NOT necessarily start at NAimg->data >but rather at >NAimg->data + NAimg->byteoffset > =20 > The numarray-0.4 manual (available at:=20 http://prdownloads.sourceforge.net/numpy/numarray-0.4.pdf?download)= =20 documents how to write Python stubs using the "high level" API on Pag= e=20 70. The thing you appear to be missing is a call to NA_OFFSETDATA wh= ich=20 gets a pointer to the data in an array by adding the buffer pointer a= nd=20 byteoffset together. Todd >Again: thanks so much. >BTW: Is there general interest in my SWIG typemaps. (SWIG is maybe t= he >easiest way to wrap C/C++ functions (and classes) >into Python (and/or Perl, Java, Ruby,...) ? I think especially for >numerical stuff, that "link" in of interest. > >Sebastian > > >----- Original Message ----- >From: "Francesc Alted" <fa...@op...> >To: "Sebastian Haase" <ha...@ms...>; ><Num...@li...> >Sent: Thursday, March 06, 2003 9:40 PM >Subject: Re: [Numpy-discussion] Please help - pointer to slice > > >A Divendres 07 Mar=E7 2003 01:42, Sebastian Haase va escriure: > =20 > >>if I try to debug this by doing: >>for z in range(nz): >> print repr(arr[z]._data) >> >>that also tells be that python / numarray thinks all slices are loc= ated at >>the same address, that is: >>every slice looks just like the full array. >> =20 >> > >You can access the slices by taking into account the byte offset >attribute. Look at the next example: > >In [20]: a=3Dnumarray.arange(100, shape=3D(10,10)) > >In [21]: a._data >Out[21]: <memory at 083e58e8 with size:400 held by object at 083e58d= 0> > >In [22]: a[1]._data >Out[22]: <memory at 083e58e8 with size:400 held by object at 083e58d= 0> > >as you already know, both memory buffers point to the same address. = I guess >this is implemented in that way so as to not copy data unnecessarily= . > >now, look at: > >In [23]: a._byteoffset >Out[23]: 0 > >In [24]: a[1]._byteoffset >Out[24]: 40 > >So, you can know where the data actually starts by looking at the >_byteoffset property. In fact, you should always look at it in order= to get >proper results!. > >In C, you can access to this information by looking at the byteoffse= t field >in the PyArrayObject struct (look at chapter 10 in the User's Manual= ). > >Hope that helps, > >-- >Francesc Alted > > > > > >------------------------------------------------------- >This SF.net email is sponsored by: Etnus, makers of TotalView, The d= ebugger=20 >for complex code. Debugging C/C++ programs can leave you feeling los= t and=20 >disoriented. TotalView can help you find your way. Available on majo= r UNIX=20 >and Linux platforms. Try it free. www.etnus.com >_______________________________________________ >Numpy-discussion mailing list >Num...@li... >https://lists.sourceforge.net/lists/listinfo/numpy-discussion > =20 > |