Ndarray static typing: Order of generic types

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Ndarray static typing: Order of generic types

BvB93

Hey all,

 

With the recent merging of numpy/numpy#16759 we’re at the point where `ndarray` can be made generic w.r.t. its dtype and shape.

An open question which yet remains is to order in which these two parameters should appear (numpy/numpy#16547):

·         `ndarray[Dtype, Shape]`

·         `ndarray[Shape, Dtype]`

 

There has been a some discussion about this question in issue 16547, but a consensus has not yet to be reached.

Most people seem to slightly preferring one option over the other.

 

Are there any further thoughts on this subject?

 

Regards,

Bas van Beek

 


_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: Ndarray static typing: Order of generic types

Stephan Hoyer-2
On Wed, Oct 28, 2020 at 2:44 PM bas van beek <[hidden email]> wrote:

Hey all,

 

With the recent merging of numpy/numpy#16759 we’re at the point where `ndarray` can be made generic w.r.t. its dtype and shape.

An open question which yet remains is to order in which these two parameters should appear (numpy/numpy#16547):

·         `ndarray[Dtype, Shape]`

·         `ndarray[Shape, Dtype]`


Hi Bas,

Thanks for driving this forward!

Just to speak for myself, I don't think the precise choice matters very much. There are arguments for consistency both ways. In the end Dtype and Shape are different enough that I doubt it will be a point of confusion.

Also, I would guess many users will define their own type aliases, so can write something more succinct like Float64[shape] rather than ndarray[float64, shape].  We might even consider including some of these in numpy.typing.

Cheers,
Stephan
 
 

 

There has been a some discussion about this question in issue 16547, but a consensus has not yet to be reached.

Most people seem to slightly preferring one option over the other.

 

Are there any further thoughts on this subject?

 

Regards,

Bas van Beek

 

_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion

_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: Ndarray static typing: Order of generic types

Joshua Wilson
> Just to speak for myself, I don't think the precise choice matters very much. There are arguments for consistency both ways.

I agree with this. In the absence of strong theoretical considerations
I'd fall back to a practical one-we can make ndarray generic over
dtype _right now_, while for shape we will need to wait 1+ years for
the variadic type variable PEP to settle etc. To me that suggests:

- Do ndarray[DType] now
- When the shape stuff is ready, do ndarray[DType, ShapeStuff] (or
however ShapeStuff ends up being spelled)
- Write a mypy plugin that rewrites ndarray[DType] to ndarray[DType,
AnyShape] (or whatever) for backwards compatibility

On Thu, Oct 29, 2020 at 1:37 PM Stephan Hoyer <[hidden email]> wrote:

>
> On Wed, Oct 28, 2020 at 2:44 PM bas van beek <[hidden email]> wrote:
>>
>> Hey all,
>>
>>
>>
>> With the recent merging of numpy/numpy#16759 we’re at the point where `ndarray` can be made generic w.r.t. its dtype and shape.
>>
>> An open question which yet remains is to order in which these two parameters should appear (numpy/numpy#16547):
>>
>> ·         `ndarray[Dtype, Shape]`
>>
>> ·         `ndarray[Shape, Dtype]`
>
>
> Hi Bas,
>
> Thanks for driving this forward!
>
> Just to speak for myself, I don't think the precise choice matters very much. There are arguments for consistency both ways. In the end Dtype and Shape are different enough that I doubt it will be a point of confusion.
>
> Also, I would guess many users will define their own type aliases, so can write something more succinct like Float64[shape] rather than ndarray[float64, shape].  We might even consider including some of these in numpy.typing.
>
> Cheers,
> Stephan
>
>
>>
>>
>>
>> There has been a some discussion about this question in issue 16547, but a consensus has not yet to be reached.
>>
>> Most people seem to slightly preferring one option over the other.
>>
>>
>>
>> Are there any further thoughts on this subject?
>>
>>
>>
>> Regards,
>>
>> Bas van Beek
>>
>>
>>
>> _______________________________________________
>> NumPy-Discussion mailing list
>> [hidden email]
>> https://mail.python.org/mailman/listinfo/numpy-discussion
>
> _______________________________________________
> NumPy-Discussion mailing list
> [hidden email]
> https://mail.python.org/mailman/listinfo/numpy-discussion
_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion