Re: [Numpy-discussion] Integers to negative integer powers, time for a decision.

2016-10-09 Thread Stephan Hoyer
On Sun, Oct 9, 2016 at 6:25 AM, Sebastian Berg 
wrote:

> For what its worth, I still feel it is probably the only real option to
> go with error, changing to float may have weird effects. Which does not
> mean it is impossible, I admit, though I would like some data on how
> downstream would handle it. Also would we need an int power? The fpower
> seems more straight forward/common pattern.
> If errors turned out annoying in some cases, a seterr might be
> plausible too (as well as a deprecation).
>

I agree with Sebastian and Nathaniel. I don't think we can deviating from
the existing behavior (int ** int -> int) without breaking lots of existing
code, and if we did, yes, we would need a new integer power function.

I think it's better to preserve the existing behavior when it gives
sensible results, and error when it doesn't. Adding another function
float_power for the case that is currently broken seems like the right way
to go.
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Integers to negative integer powers, time for a decision.

2016-10-09 Thread Sebastian Berg
On Fr, 2016-10-07 at 19:12 -0600, Charles R Harris wrote:
> Hi All,
> 
> The time for NumPy 1.12.0 approaches and I like to have a final
> decision on the treatment of integers to negative integer powers with
> the `**` operator. The two alternatives looked to be
> 
> Raise an error for arrays and numpy scalars, including 1 and -1 to
> negative powers.
> 

For what its worth, I still feel it is probably the only real option to
go with error, changing to float may have weird effects. Which does not
mean it is impossible, I admit, though I would like some data on how
downstream would handle it. Also would we need an int power? The fpower
seems more straight forward/common pattern.
If errors turned out annoying in some cases, a seterr might be
plausible too (as well as a deprecation).

- Sebastian


> Pluses
> Backward compatible
> Allows common powers to be integer, e.g., arange(3)**2
> Consistent with inplace operators
> Fixes current wrong behavior.
> Preserves type
> 
> Minuses
> Integer overflow
> Computational inconvenience
> Inconsistent with Python integers
> 
> Always return a float 
> 
> Pluses
> Computational convenience
> 
> Minuses
> Loss of type
> Possible backward incompatibilities
> Not applicable to inplace operators
> 
> 
> Thoughts?
> 
> Chuck
> 
> 
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> https://mail.scipy.org/mailman/listinfo/numpy-discussion

signature.asc
Description: This is a digitally signed message part
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Integers to negative integer powers, time for a decision.

2016-10-09 Thread Krisztián Horváth
> Sounds good to me. I agree that we should prioritize within-numpy
> consistency over consistency with Python.
>

I agree with that. Because of numpy consitetncy, the `**` operator should
always return float. Right now the case is:

>>> aa = np.arange(2, 10, dtype=int)
array([2, 3, 4, 5, 6, 7, 8, 9])

>>> bb = np.linspace(0, 7, 8, dtype=int)
array([0, 1, 2, 3, 4, 5, 6, 7])

>>> 1/aa
array([ 0.5   ,  0.,  0.25  ,  0.2   ,  0.1667,
0.14285714,  0.125 ,  0.])

>>> aa**-1
array([0, 0, 0, 0, 0, 0, 0, 0])

>>> 1/aa**2
array([ 0.25  ,  0.,  0.0625,  0.04  ,  0.0278,
0.02040816,  0.015625  ,  0.01234568])

>>> aa**-2
array([0, 0, 0, 0, 0, 0, 0, 0])

>>> aa**bb
array([  1,   3,  16, 125,1296,   16807,  262144,
   4782969])

>>> 1/aa**bb
array([  1.e+00,   3.e-01,   6.2500e-02,
 8.e-03,   7.71604938e-04,   5.94990183e-05,
 3.81469727e-06,   2.09075158e-07])

>>> aa**(-bb)
array([1, 0, 0, 0, 0, 0, 0, 0])

For me this behaviour is confusing. But I am not an expert just a user. I
can live together with anything if I know what to expect. And I greatly
appreciate the work of any developer for this excellent package.
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Integers to negative integer powers, time for a decision.

2016-10-09 Thread Ralf Gommers
On Sun, Oct 9, 2016 at 4:12 AM, Nathaniel Smith  wrote:

> On Sat, Oct 8, 2016 at 6:59 AM, Charles R Harris
>  wrote:
> >
> >
> > On Sat, Oct 8, 2016 at 4:40 AM, Nathaniel Smith  wrote:
> >>
> >> On Fri, Oct 7, 2016 at 6:12 PM, Charles R Harris
> >>  wrote:
> >> > Hi All,
> >> >
> >> > The time for NumPy 1.12.0 approaches and I like to have a final
> decision
> >> > on
> >> > the treatment of integers to negative integer powers with the `**`
> >> > operator.
> >> > The two alternatives looked to be
> >> >
> >> > Raise an error for arrays and numpy scalars, including 1 and -1 to
> >> > negative
> >> > powers.
> >> >
> >> > Pluses
> >> >
> >> > Backward compatible
> >> > Allows common powers to be integer, e.g., arange(3)**2
> >> > Consistent with inplace operators
> >> > Fixes current wrong behavior.
> >> > Preserves type
> >> >
> >> >
> >> > Minuses
> >> >
> >> > Integer overflow
> >> > Computational inconvenience
> >> > Inconsistent with Python integers
> >> >
> >> >
> >> > Always return a float
> >> >
> >> > Pluses
> >> >
> >> > Computational convenience
> >> >
> >> >
> >> > Minuses
> >> >
> >> > Loss of type
> >> > Possible backward incompatibilities
> >> > Not applicable to inplace operators
> >>
> >> I guess I could be wrong, but I think the backwards incompatibilities
> >> are going to be *way* too severe to make option 2 possible in
> >> practice.
> >>
> >
> > Backwards compatibility is also a major concern for me.  Here are my
> current
> > thoughts
> >
> > Add an fpow ufunc that always converts to float, it would not accept
> object
> > arrays.
>
> Maybe call it `fpower` or even `float_power`, for consistency with `power`?
>
> > Raise errors in current power ufunc (**), for ints to negative ints.
> >
> > The power ufunc will change in the following ways
> >
> > +1, -1 to negative ints will error, currently they work
> > n > 1 ints to negative ints will error, currently warn and return zero
> > 0 to negative ints will error, they currently return the minimum integer
> >
> > The `**` operator currently calls the power ufunc, leave that as is for
> > backward almost compatibility. The remaining question is numpy scalars,
> > which we can make either compatible with Python, or with NumPy arrays.
> I'm
> > leaning towards NumPy array compatibility mostly on account of type
> > preservation and the close relationship between zero dimensionaly arrays
> and
> > scalars.
>
> Sounds good to me. I agree that we should prioritize within-numpy
> consistency over consistency with Python.
>

+1 sounds good to me too.


>
> > The fpow function could be backported to NumPy 1.11 if that would be
> helpful
> > going forward.
>
> I'm not a big fan of this kind of backport. Violating the
> "bug-fixes-only" rule makes it hard for people to understand our
> release versions. And it creates the situation where people can write
> code that they think requires numpy 1.11 (because it works with their
> numpy 1.11!), but then breaks on other people's computers (because
> those users have 1.11.(x-1)). And if there's some reason why people
> aren't willing to upgrade to 1.12 for new features, then probably
> better to spend energy addressing those instead of on putting together
> 1.11-and-a-half releases.
>

Agreed, this is not something we want to backport.

Ralf



>
> -n
>
> --
> Nathaniel J. Smith -- https://vorpus.org
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> https://mail.scipy.org/mailman/listinfo/numpy-discussion
>
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion