Re: [Numpy-discussion] `keepdims=True` for argmin/argmx and C-API `PyArray_ArgMaxWithKeepdims`

2021-07-01 Thread Stefan van der Walt
Hi Sebastian,

On Wed, Jun 30, 2021, at 18:23, Sebastian Berg wrote:
> The PR https://github.com/numpy/numpy/pull/19211 proposes to extend
> argmin and argmax with a `keepdims=False` keyword-only argument.

This seems consistent with existing APIs, so I'm not concerned.

For those wondering, `keepdims` preserves the number of dimensions of the 
original array in a reduction operation like `sum`:

In [1]: X = np.random.random((10, 15))

In [2]: np.sum(X).shape
Out[2]: ()

In [3]: np.sum(X, keepdims=True).shape
Out[3]: (1, 1)

This is sometimes useful for broadcasting.

> The PR  also proposes to add:
> 
> * `PyArray_ArgMinWithKeepdims`
> * `PyArray_ArgMaxWithKeepdims`

I am curious whether this is our general pattern for adding keyword argument 
functionality to functions in the C-API.  It seems a bit excessive!

Stéfan
___
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] `keepdims=True` for argmin/argmx and C-API `PyArray_ArgMaxWithKeepdims`

2021-07-01 Thread Sebastian Berg
On Thu, 2021-07-01 at 00:39 -0700, Stefan van der Walt wrote:
> Hi Sebastian,
> 
> On Wed, Jun 30, 2021, at 18:23, Sebastian Berg wrote:
> > The PR https://github.com/numpy/numpy/pull/19211 proposes to extend
> > argmin and argmax with a `keepdims=False` keyword-only argument.
> 
> This seems consistent with existing APIs, so I'm not concerned.
> 
> For those wondering, `keepdims` preserves the number of dimensions of
> the original array in a reduction operation like `sum`:
> 
> In [1]: X = np.random.random((10, 15))
> 
> In [2]: np.sum(X).shape
> Out[2]: ()
> 
> In [3]: np.sum(X, keepdims=True).shape
> Out[3]: (1, 1)
> 
> This is sometimes useful for broadcasting.
> 
> > The PR  also proposes to add:
> > 
> > * `PyArray_ArgMinWithKeepdims`
> > * `PyArray_ArgMaxWithKeepdims`
> 
> I am curious whether this is our general pattern for adding keyword
> argument functionality to functions in the C-API.  It seems a bit
> excessive!

True, I am now tending a bit towards delaying this until someone
actually asks for it...
In most use-cases just using the Python API is likely only a small
overhead anyway if done right.

I do not think we have a pattern.  We do have some functions with the
pattern of `With...And...` to allow signatures of different complexity.
But very few of this type of python additions ever made it into the C-
API.  For `Reshape`, `order=` was added by introducing `NewShape`.

I have some hope that very long-term, HPy might solve this for us...

Cheers,

Sebastian



> 
> Stéfan
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion


___
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] `keepdims=True` for argmin/argmx and C-API `PyArray_ArgMaxWithKeepdims`

2021-07-01 Thread Gagandeep Singh
Hi,

So should I remove these new functions from public C-API? Let me know. I
will do that.

On Thu, 1 Jul, 2021, 10:02 pm Sebastian Berg, 
wrote:

> On Thu, 2021-07-01 at 00:39 -0700, Stefan van der Walt wrote:
> > Hi Sebastian,
> >
> > On Wed, Jun 30, 2021, at 18:23, Sebastian Berg wrote:
> > > The PR https://github.com/numpy/numpy/pull/19211 proposes to extend
> > > argmin and argmax with a `keepdims=False` keyword-only argument.
> >
> > This seems consistent with existing APIs, so I'm not concerned.
> >
> > For those wondering, `keepdims` preserves the number of dimensions of
> > the original array in a reduction operation like `sum`:
> >
> > In [1]: X = np.random.random((10, 15))
> >
> > In [2]: np.sum(X).shape
> > Out[2]: ()
> >
> > In [3]: np.sum(X, keepdims=True).shape
> > Out[3]: (1, 1)
> >
> > This is sometimes useful for broadcasting.
> >
> > > The PR  also proposes to add:
> > >
> > > * `PyArray_ArgMinWithKeepdims`
> > > * `PyArray_ArgMaxWithKeepdims`
> >
> > I am curious whether this is our general pattern for adding keyword
> > argument functionality to functions in the C-API.  It seems a bit
> > excessive!
>
> True, I am now tending a bit towards delaying this until someone
> actually asks for it...
> In most use-cases just using the Python API is likely only a small
> overhead anyway if done right.
>
> I do not think we have a pattern.  We do have some functions with the
> pattern of `With...And...` to allow signatures of different complexity.
> But very few of this type of python additions ever made it into the C-
> API.  For `Reshape`, `order=` was added by introducing `NewShape`.
>
> I have some hope that very long-term, HPy might solve this for us...
>
> Cheers,
>
> Sebastian
>
>
>
> >
> > Stéfan
> > ___
> > NumPy-Discussion mailing list
> > NumPy-Discussion@python.org
> > https://mail.python.org/mailman/listinfo/numpy-discussion
>
>
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
>
___
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] `keepdims=True` for argmin/argmx and C-API `PyArray_ArgMaxWithKeepdims`

2021-07-01 Thread Matti Picus



On 1/7/21 7:49 pm, Gagandeep Singh wrote:

Hi,

So should I remove these new functions from public C-API? Let me know. 
I will do that.





Yes please. If needed we can add them, but once in we cannot remove them.

Matti

___
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] `keepdims=True` for argmin/argmx and C-API `PyArray_ArgMaxWithKeepdims`

2021-07-01 Thread Gagandeep Singh
Hi,

I have removed the two new C functions

from public C-API. Let me know if anything else is needed.

Thanks.

On Fri, Jul 2, 2021 at 2:10 AM Matti Picus  wrote:

>
> On 1/7/21 7:49 pm, Gagandeep Singh wrote:
> > Hi,
> >
> > So should I remove these new functions from public C-API? Let me know.
> > I will do that.
> >
> >
>
> Yes please. If needed we can add them, but once in we cannot remove them.
>
> Matti
>
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
>
___
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion