[Cython] accessing ctype array's b_ptr

Ondrej Certik ondrej at certik.cz
Wed Jul 1 06:24:15 CEST 2009


On Tue, Jun 30, 2009 at 10:11 PM, Robert
Bradshaw<robertwb at math.washington.edu> wrote:
> On Jun 30, 2009, at 7:08 PM, Ondrej Certik wrote:
>
>> On Tue, Jun 30, 2009 at 7:30 PM, Lisandro Dalcin<dalcinl at gmail.com>
>> wrote:
>>> On Tue, Jun 30, 2009 at 10:14 PM, Ondrej Certik<ondrej at certik.cz>
>>> wrote:
>>>>
>>>> Ah, I think I am wrong. Numpy's strides is exactly what I need,
>>>> right?
>>>>
>>>> http://docs.scipy.org/doc/numpy/reference/generated/
>>>> numpy.ndarray.strides.html
>>>>
>>>> so I just take *any*  numpy array, as long as it has the right
>>>> dtype,
>>>> and then just pass the pointer to .data and strides to the opengl
>>>> function.
>>>>
>>>
>>> Perhaps it works... Just in case, test it with a numpy array using
>>> Fortran ordering, perhaps OpenGL does not like it?
>>
>> So far all functions in opengl use 1D arrays only.
>>
>>>
>>> BTW, do arrays with more than two dimensions make sense in OpenGL? Do
>>> you know exactly what numpy strides mean (any nd-array have
>>> nd-strides, even the contiguous ones) ?
>>
>> Yes, a stride is the number of bytes you need to move your pointer to
>> get to the next element in the array. opengl only accepts 1D arrays,
>> but it *does* accept a stride.
>>
>> Can it happen, that a 1D numpy array has stride which is bigger than
>> sizeof(dtype)? so far I didn't manage to create one.
>
> Yes.
>
> sage: a = numpy.zeros(10)[::5]
> sage: a.strides
> (40,)

Cool example, thanks for that, I'll use it for tests.

Ondrej


More information about the Cython-dev mailing list