Re: [Numpy-discussion] Proposal to make power return float, and other such things.
Charles R Harris charlesr.har...@gmail.com wrote: This is apropos issue #899 a href=https://github.com/numpy/numpy/issues/899;https://github.com/numpy/numpy/issues/899/a, where it is suggested that power promote integers to float. That sounds reasonable to me, but such a change in behavior makes it a bit iffy. Thoughts? Numpy should do the same as Python does. Sturla ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Proposal to make power return float, and other such things.
On Tue, Feb 18, 2014 at 9:51 AM, Sturla Molden sturla.mol...@gmail.com wrote: Charles R Harris charlesr.har...@gmail.com wrote: This is apropos issue #899 a href=https://github.com/numpy/numpy/issues/899;https://github.com/numpy/numpy/issues/899/a, where it is suggested that power promote integers to float. That sounds reasonable to me, but such a change in behavior makes it a bit iffy. Thoughts? Numpy should do the same as Python does. That's problematic because Python's behavior is value dependent. Python 3.3.1 (default, May 16 2013, 17:20:13) [GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin Type help, copyright, credits or license for more information. 2 ** 2 4 2 ** -2 0.25 That's fine if you only have one value for each operand. When you have multiple values for each operand, say an exponent array containing both positive and negative integers, that becomes a problem. Generally, we try to make ufuncs return types that are predictable from the types of the operands, not the values of the operands. I am -1 on the proposal to make power(x:int, y:int) always return a float. It is usually trivial to just make the exponent a float if one wants a float returned. Or we could introduce an fpow() that always coerces the inputs to the best inexact type. -- Robert Kern ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Proposal to make power return float, and other such things.
On Feb 18, 2014 11:55 AM, Robert Kern robert.k...@gmail.com wrote: On Tue, Feb 18, 2014 at 9:51 AM, Sturla Molden sturla.mol...@gmail.com wrote: Charles R Harris charlesr.har...@gmail.com wrote: This is apropos issue #899 a href=https://github.com/numpy/numpy/issues/899; https://github.com/numpy/numpy/issues/899/a, where it is suggested that power promote integers to float. That sounds reasonable to me, but such a change in behavior makes it a bit iffy. Thoughts? Numpy should do the same as Python does. That's problematic because Python's behavior is value dependent. Python 3.3.1 (default, May 16 2013, 17:20:13) [GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin Type help, copyright, credits or license for more information. 2 ** 2 4 2 ** -2 0.25 That's fine if you only have one value for each operand. When you have multiple values for each operand, say an exponent array containing both positive and negative integers, that becomes a problem. Generally, we try to make ufuncs return types that are predictable from the types of the operands, not the values of the operands. I am -1 on the proposal to make power(x:int, y:int) always return a float. It is usually trivial to just make the exponent a float if one wants a float returned. Or we could introduce an fpow() that always coerces the inputs to the best inexact type. What about making it floats for int types but int for uint types? ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Proposal to make power return float, and other such things.
On Tue, Feb 18, 2014 at 10:59 AM, Todd toddr...@gmail.com wrote: On Feb 18, 2014 11:55 AM, Robert Kern robert.k...@gmail.com wrote: I am -1 on the proposal to make power(x:int, y:int) always return a float. It is usually trivial to just make the exponent a float if one wants a float returned. Or we could introduce an fpow() that always coerces the inputs to the best inexact type. What about making it floats for int types but int for uint types? Doesn't really do it for me. int_array**2 would now return a float for no good reason. -- Robert Kern ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Proposal to make power return float, and other such things.
Robert Kern robert.k...@gmail.com wrote: That's fine if you only have one value for each operand. When you have multiple values for each operand, say an exponent array containing both positive and negative integers, that becomes a problem. I don't really see why. If you have a negative integer in there you get a float array returned, otherwise it stays integer. Generally, we try to make ufuncs return types that are predictable from the types of the operands, not the values of the operands. Isn't that unpractical in this case? Who cares if the power operator behaves as an ufunc? Sturla ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Proposal to make power return float, and other such things.
On Tue, Feb 18, 2014 at 11:19 AM, Sturla Molden sturla.mol...@gmail.com wrote: Robert Kern robert.k...@gmail.com wrote: That's fine if you only have one value for each operand. When you have multiple values for each operand, say an exponent array containing both positive and negative integers, that becomes a problem. I don't really see why. If you have a negative integer in there you get a float array returned, otherwise it stays integer. We don't do this for any other ufunc. Generally, we try to make ufuncs return types that are predictable from the types of the operands, not the values of the operands. Isn't that unpractical in this case? Who cares if the power operator behaves as an ufunc? We're talking about numpy.power(), not just ndarray.__pow__(). The equivalence of the two is indeed an implementation detail, but I do think that it is useful to maintain the equivalence. If we didn't, it would be the only exception, to my knowledge. -- Robert Kern ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Proposal to make power return float, and other such things.
Robert Kern robert.k...@gmail.com wrote: We're talking about numpy.power(), not just ndarray.__pow__(). The equivalence of the two is indeed an implementation detail, but I do think that it is useful to maintain the equivalence. If we didn't, it would be the only exception, to my knowledge. But in this case it makes sence. math.pow(2,2) and 2**2 does not do the same. That is how Python behaves. Sturla ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Proposal to make power return float, and other such things.
On Tue, Feb 18, 2014 at 11:44 AM, Sturla Molden sturla.mol...@gmail.com wrote: Robert Kern robert.k...@gmail.com wrote: We're talking about numpy.power(), not just ndarray.__pow__(). The equivalence of the two is indeed an implementation detail, but I do think that it is useful to maintain the equivalence. If we didn't, it would be the only exception, to my knowledge. But in this case it makes sence. Every proposed special case we come up with makes sense in some way. That doesn't mean that they are special enough to break the rules. In my opinion, this is not special enough to break the rules. In your opinion, it is. math.pow(2,2) and 2**2 does not do the same. That is how Python behaves. Yes, because the functions in the math module are explicitly thin wrappers around floating-point C library functions and don't have any particular relationship to the special methods on int objects. numpy does have largely 1:1 relationship between its ndarray operator special methods and the ufuncs that implement them. I believe this is a useful relationship for learning the API and predicting what a given expression is going to do. -- Robert Kern ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Proposal to make power return float, and other such things.
Perhaps integer power should raise an error on negative powers? That way people will at least be directed to use arr ** -1.0 instead of silently getting nonsense from arr ** -1. On 18 Feb 2014 06:57, Robert Kern robert.k...@gmail.com wrote: On Tue, Feb 18, 2014 at 11:44 AM, Sturla Molden sturla.mol...@gmail.com wrote: Robert Kern robert.k...@gmail.com wrote: We're talking about numpy.power(), not just ndarray.__pow__(). The equivalence of the two is indeed an implementation detail, but I do think that it is useful to maintain the equivalence. If we didn't, it would be the only exception, to my knowledge. But in this case it makes sence. Every proposed special case we come up with makes sense in some way. That doesn't mean that they are special enough to break the rules. In my opinion, this is not special enough to break the rules. In your opinion, it is. math.pow(2,2) and 2**2 does not do the same. That is how Python behaves. Yes, because the functions in the math module are explicitly thin wrappers around floating-point C library functions and don't have any particular relationship to the special methods on int objects. numpy does have largely 1:1 relationship between its ndarray operator special methods and the ufuncs that implement them. I believe this is a useful relationship for learning the API and predicting what a given expression is going to do. -- Robert Kern ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Proposal to make power return float, and other such things.
On Tue, Feb 18, 2014 at 12:00 PM, Nathaniel Smith n...@pobox.com wrote: Perhaps integer power should raise an error on negative powers? That way people will at least be directed to use arr ** -1.0 instead of silently getting nonsense from arr ** -1. Controllable by np.seterr(invalid=...)? I could get behind that. -- Robert Kern ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Proposal to make power return float, and other such things.
On Di, 2014-02-18 at 11:44 +, Sturla Molden wrote: Robert Kern robert.k...@gmail.com wrote: We're talking about numpy.power(), not just ndarray.__pow__(). The equivalence of the two is indeed an implementation detail, but I do think that it is useful to maintain the equivalence. If we didn't, it would be the only exception, to my knowledge. But in this case it makes sence. math.pow(2,2) and 2**2 does not do the same. That is how Python behaves. To be honest, that comparison only makes half sense to me. `math` are all float (double precision) functions, basically you could just as well call the library `fmath`... I am -0.5 right now. `__pow__` already has special behaviour as opposed to `np.power`, but these are for speed and don't change behaviour. T he `uint` idea seems to just make things more complicated. If I am aware of uint vs int, I am already aware I can just cast to float. - Sebastian Sturla ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Proposal to make power return float, and other such things.
Nathaniel Smith n...@pobox.com wrote: Perhaps integer power should raise an error on negative powers? That way people will at least be directed to use arr ** -1.0 instead of silently getting nonsense from arr ** -1. That sounds far better than silently returning errorneous results. Sturla ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Proposal to make power return float, and other such things.
On 18 Feb 2014 07:07, Robert Kern robert.k...@gmail.com wrote: On Tue, Feb 18, 2014 at 12:00 PM, Nathaniel Smith n...@pobox.com wrote: Perhaps integer power should raise an error on negative powers? That way people will at least be directed to use arr ** -1.0 instead of silently getting nonsense from arr ** -1. Controllable by np.seterr(invalid=...)? I could get behind that. I'm not sure the np.seterr part would work or be a good idea, given that we have no way to return or propagate NaN... I vote for just an unconditional error. -n ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Proposal to make power return float, and other such things.
On Tue, Feb 18, 2014 at 1:46 PM, Nathaniel Smith n...@pobox.com wrote: On 18 Feb 2014 07:07, Robert Kern robert.k...@gmail.com wrote: On Tue, Feb 18, 2014 at 12:00 PM, Nathaniel Smith n...@pobox.com wrote: Perhaps integer power should raise an error on negative powers? That way people will at least be directed to use arr ** -1.0 instead of silently getting nonsense from arr ** -1. Controllable by np.seterr(invalid=...)? I could get behind that. I'm not sure the np.seterr part would work or be a good idea, given that we have no way to return or propagate NaN... I vote for just an unconditional error. shrug We issue configurable warning/error/ignore behavior for integer 0/0 through this mechanism too without any NaNs. However, that's `divide` and not `invalid`. Your point is taken that `invalid` usually implies that a `NaN` is generated, though I don't think this is ever stated anywhere. I just suggested `invalid` as that is usually what we use for function domain violations. -- Robert Kern ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Proposal to make power return float, and other such things.
On Tue, Feb 18, 2014 at 8:53 AM, Robert Kern robert.k...@gmail.com wrote: On Tue, Feb 18, 2014 at 1:46 PM, Nathaniel Smith n...@pobox.com wrote: On 18 Feb 2014 07:07, Robert Kern robert.k...@gmail.com wrote: On Tue, Feb 18, 2014 at 12:00 PM, Nathaniel Smith n...@pobox.com wrote: Perhaps integer power should raise an error on negative powers? That way people will at least be directed to use arr ** -1.0 instead of silently getting nonsense from arr ** -1. Controllable by np.seterr(invalid=...)? I could get behind that. I'm not sure the np.seterr part would work or be a good idea, given that we have no way to return or propagate NaN... I vote for just an unconditional error. shrug We issue configurable warning/error/ignore behavior for integer 0/0 through this mechanism too without any NaNs. However, that's `divide` and not `invalid`. Your point is taken that `invalid` usually implies that a `NaN` is generated, though I don't think this is ever stated anywhere. I just suggested `invalid` as that is usually what we use for function domain violations. I thought 0/0 = 0 has been removed a few versions ago. Does numpy still have silent casting of nan to 0 in ints. I thought invalid and divide error/warnings are for floating point when we want to signal that the outcome is nan or inf, not that we are casting and return a result that is just wrong. Josef -- Robert Kern ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Proposal to make power return float, and other such things.
On Tue, Feb 18, 2014 at 2:37 PM, josef.p...@gmail.com wrote: On Tue, Feb 18, 2014 at 8:53 AM, Robert Kern robert.k...@gmail.com wrote: On Tue, Feb 18, 2014 at 1:46 PM, Nathaniel Smith n...@pobox.com wrote: On 18 Feb 2014 07:07, Robert Kern robert.k...@gmail.com wrote: On Tue, Feb 18, 2014 at 12:00 PM, Nathaniel Smith n...@pobox.com wrote: Perhaps integer power should raise an error on negative powers? That way people will at least be directed to use arr ** -1.0 instead of silently getting nonsense from arr ** -1. Controllable by np.seterr(invalid=...)? I could get behind that. I'm not sure the np.seterr part would work or be a good idea, given that we have no way to return or propagate NaN... I vote for just an unconditional error. shrug We issue configurable warning/error/ignore behavior for integer 0/0 through this mechanism too without any NaNs. However, that's `divide` and not `invalid`. Your point is taken that `invalid` usually implies that a `NaN` is generated, though I don't think this is ever stated anywhere. I just suggested `invalid` as that is usually what we use for function domain violations. I thought 0/0 = 0 has been removed a few versions ago. Does numpy still have silent casting of nan to 0 in ints. There is no casting involved. I thought invalid and divide error/warnings are for floating point when we want to signal that the outcome is nan or inf, not that we are casting and return a result that is just wrong. No, they are also for some integer operations without going through a floating point intermediate. -- Robert Kern ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Proposal to make power return float, and other such things.
On Tue, Feb 18, 2014 at 9:42 AM, Robert Kern robert.k...@gmail.com wrote: On Tue, Feb 18, 2014 at 2:37 PM, josef.p...@gmail.com wrote: On Tue, Feb 18, 2014 at 8:53 AM, Robert Kern robert.k...@gmail.com wrote: On Tue, Feb 18, 2014 at 1:46 PM, Nathaniel Smith n...@pobox.com wrote: On 18 Feb 2014 07:07, Robert Kern robert.k...@gmail.com wrote: On Tue, Feb 18, 2014 at 12:00 PM, Nathaniel Smith n...@pobox.com wrote: Perhaps integer power should raise an error on negative powers? That way people will at least be directed to use arr ** -1.0 instead of silently getting nonsense from arr ** -1. Controllable by np.seterr(invalid=...)? I could get behind that. I'm not sure the np.seterr part would work or be a good idea, given that we have no way to return or propagate NaN... I vote for just an unconditional error. shrug We issue configurable warning/error/ignore behavior for integer 0/0 through this mechanism too without any NaNs. However, that's `divide` and not `invalid`. Your point is taken that `invalid` usually implies that a `NaN` is generated, though I don't think this is ever stated anywhere. I just suggested `invalid` as that is usually what we use for function domain violations. I thought 0/0 = 0 has been removed a few versions ago. Does numpy still have silent casting of nan to 0 in ints. There is no casting involved. numpy still creates a return dtype, that holds the wrong result. I thought invalid and divide error/warnings are for floating point when we want to signal that the outcome is nan or inf, not that we are casting and return a result that is just wrong. No, they are also for some integer operations without going through a floating point intermediate. good that I don't like integers, I didn't see a bug because of this in years. at least for division, we can go into the __future__ with python 3.3: np.array(0) ** np.array(-1) -2147483648 np.divide(np.array(0), np.array(0)) nan np.array(0) / np.array(0) nan Josef -- Robert Kern ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Proposal to make power return float, and other such things.
On 2/17/2014 8:13 PM, Charles R Harris wrote: This is apropos issue #899 https://github.com/numpy/numpy/issues/899, where it is suggested that power promote integers to float. Even when base and exponent are both positive integers? Alan Isaac ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Proposal to make power return float, and other such things.
On Mon, Feb 17, 2014 at 8:13 PM, Charles R Harris charlesr.har...@gmail.com wrote: This is apropos issue #899, where it is suggested that power promote integers to float. That sounds reasonable to me, but such a change in behavior makes it a bit iffy. Thoughts? After this change, what would be the recommended way to get entrywise positive integer powers of an array with integer entries? ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion