Lisandro Dalcin | 7 Aug 17:47

[Cython] about to buffer syntax

I'm still convinced that Fortran 90 array declarators could provide a
more powerfull syntax for buffers, For this, the dimensions should be
specified with a tuple, examples below:

cdef ndarray[int, ()] a # a  scalar

cdef ndarray[int, (3,)] # a1D array with 3 items

cdef ndarray[int, (:,)] # a 1D array of any size

cdef ndarray[int  (2,3)] # 2D array with 2 rows and 3 columns

cdef ndarray[int  (:,3)] # 2D array with any number of rows and 3 columns

cdef ndarray[int  (:,:)] # 2D array with any number of rows and columns

cdef ndarray[float,  (3,3,:)] # 3D array,  a 'sequence' of 3x3 array

We could even use Ellipsis '...' in a similar sense numpy uses them

cdef ndarray[int, (...)] # any number of dimension

cdef ndarray[int, (:, ...)] # at least 1D

cdef ndarray[int, (:, : ,...)] # at least 3D

cdef ndarray[int, (3, 5, ...)] # at least 2D, but required shape in
first two dims.

What do you think?
(Continue reading)

Robert Bradshaw | 8 Aug 06:23

Re: [Cython] about to buffer syntax

On Aug 7, 2008, at 8:49 AM, Lisandro Dalcin wrote:

> I'm still convinced that Fortran 90 array declarators could provide a
> more powerfull syntax for buffers, For this, the dimensions should be
> specified with a tuple, examples below:
>
> cdef ndarray[int, ()] a # a  scalar
>
> cdef ndarray[int, (3,)] # a1D array with 3 items
>
> cdef ndarray[int, (:,)] # a 1D array of any size
>
> cdef ndarray[int  (2,3)] # 2D array with 2 rows and 3 columns
>
> cdef ndarray[int  (:,3)] # 2D array with any number of rows and 3  
> columns
>
> cdef ndarray[int  (:,:)] # 2D array with any number of rows and  
> columns
>
> cdef ndarray[float,  (3,3,:)] # 3D array,  a 'sequence' of 3x3 array
>
>
> We could even use Ellipsis '...' in a similar sense numpy uses them
>
> cdef ndarray[int, (...)] # any number of dimension
>
> cdef ndarray[int, (:, ...)] # at least 1D
>
> cdef ndarray[int, (:, : ,...)] # at least 3D
(Continue reading)

Re: [Cython] about to buffer syntax

My initial reaction is that I like it! However it might not be needed...

It would have to be (:n, :) rather than (n, :) for consistency.

The thing is, you don't really need the shape in the syntax currently, only ndim. (One can use an assert
statement if one wants the check, there doesn't appear to be any advantages to knowing the shape
compile-time, unless perhaps if it is very small.)

however with this perhaps support for specifying a starting point (index start point, subtracted on all
lookups) could be added, that would be potentially very useful but also tend to "add cruft"...add
something that is not there in either Python or C...

Time and users will have to tell! But I enjoyed such a fresh idea in this discussion.

I think one could make the ndim keyword mandatory at first, to delay the decision about which positional
argument should be 2nd.

Dag Sverre Seljebotn

-----Original Message-----
From: "Lisandro Dalcin" <dalcinl@...>
Date: Thursday, Aug 7, 2008 5:49 pm
Subject: [Cython] about to buffer syntax
To: Cython-dev <cython-dev@...>Reply-To: cython-dev@...

I'm still convinced that Fortran 90 array declarators could provide a
>more powerfull syntax for buffers, For this, the dimensions should be
>specified with a tuple, examples below:
>
>cdef ndarray[int, ()] a # a  scalar
(Continue reading)

Lisandro Dalcin | 11 Aug 17:42

Re: [Cython] about to buffer syntax

2008/8/9 Dag Sverre Seljebotn <dagss@...>:
> My initial reaction is that I like it! However it might not be needed...
>
> It would have to be (:n, :) rather than (n, :) for consistency.
>
> The thing is, you don't really need the shape in the syntax currently, only ndim. (One can use an assert
statement if one wants the check, there doesn't appear to be any advantages to knowing the shape
compile-time, unless perhaps if it is very small.)
>
> however with this perhaps support for specifying a starting point (index start point, subtracted on all
lookups) could be added, that would be potentially very useful but also tend to "add cruft"...add
something that is not there in either Python or C...

> Time and users will have to tell! But I enjoyed such a fresh idea in this discussion.

Well, I believe that people with some background in Fortran 90 will
definitely like and support my proposal.

> I think one could make the ndim keyword mandatory at first, to delay the decision about which positional
argument should be 2nd.

Well, I believe that is a good approach. IMHO, declaring

cdef ndarray[int, 3] tmp

is not really clear that '3' means a 3D array. The intention of my
proposal is just to provide a syntax that is less ambiguous and have
room for more facilities (shape checking, negative starts, require
shape at least xD, etc.)

(Continue reading)

Robert Bradshaw | 22 Aug 10:13

Re: [Cython] about to buffer syntax

On Aug 11, 2008, at 8:42 AM, Lisandro Dalcin wrote:

> 2008/8/9 Dag Sverre Seljebotn <dagss@...>:
>> My initial reaction is that I like it! However it might not be  
>> needed...
>>
>> It would have to be (:n, :) rather than (n, :) for consistency.
>>
>> The thing is, you don't really need the shape in the syntax  
>> currently, only ndim. (One can use an assert statement if one  
>> wants the check, there doesn't appear to be any advantages to  
>> knowing the shape compile-time, unless perhaps if it is very small.)
>>
>> however with this perhaps support for specifying a starting point  
>> (index start point, subtracted on all lookups) could be added,  
>> that would be potentially very useful but also tend to "add  
>> cruft"...add something that is not there in either Python or C...
>
>> Time and users will have to tell! But I enjoyed such a fresh idea  
>> in this discussion.
>
> Well, I believe that people with some background in Fortran 90 will
> definitely like and support my proposal.
>
>> I think one could make the ndim keyword mandatory at first, to  
>> delay the decision about which positional argument should be 2nd.
>
> Well, I believe that is a good approach. IMHO, declaring
>
> cdef ndarray[int, 3] tmp
(Continue reading)


Gmane