[Numpy-discussion] Re: Change definition of complex sign (and use it in copysign)

2024-01-04 Thread Robert Kern
On Wed, Jan 3, 2024 at 4:09 PM Aaron Meurer  wrote:

> sign(z) = z/|z| is a fairly standard definition. See
> https://oeis.org/wiki/Sign_function and
> https://en.wikipedia.org/wiki/Sign_function. It's also implemented
> this way in MATLAB and Mathematica (see
> https://www.mathworks.com/help/symbolic/sign.html and
> https://reference.wolfram.com/language/ref/Sign.html). The function
> z/|z| is useful because it represents a normalization of z as a vector
> in the complex plane onto the unit circle.
>
> With that being said, I'm not so sure about the suggestion about
> extending copysign(x1, x2) as |x1|*sign(x2). I generally think of
> copysign as a function to manipulate the floating-point representation
> of a number. It literally copies the sign *bit* from x2 into x1. It's
> useful because of things like -0.0, which is otherwise difficult to
> work with since it compares equal to 0.0. I would find it surprising
> for copysign to do a numeric calculation on complex numbers. Also,
> your suggested definition would be wrong for 0.0 and -0.0, since
> sign(0) is 0, and this is precisely where copysign matters.
>

Agreed on all points.

-- 
Robert Kern
___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com


[Numpy-discussion] Re: Change definition of complex sign (and use it in copysign)

2024-01-04 Thread Dom Grigonis
I think this suggestion regarding sign is solid. From both theoretical and 
practical points of view.

And agree with all of Aaron’s points as well.

Regards,
DG

> On 4 Jan 2024, at 22:58, Robert Kern  wrote:
> 
> On Wed, Jan 3, 2024 at 4:09 PM Aaron Meurer  > wrote:
> sign(z) = z/|z| is a fairly standard definition. See
> https://oeis.org/wiki/Sign_function  and
> https://en.wikipedia.org/wiki/Sign_function 
> . It's also implemented
> this way in MATLAB and Mathematica (see
> https://www.mathworks.com/help/symbolic/sign.html 
>  and
> https://reference.wolfram.com/language/ref/Sign.html 
> ). The function
> z/|z| is useful because it represents a normalization of z as a vector
> in the complex plane onto the unit circle.
> 
> With that being said, I'm not so sure about the suggestion about
> extending copysign(x1, x2) as |x1|*sign(x2). I generally think of
> copysign as a function to manipulate the floating-point representation
> of a number. It literally copies the sign *bit* from x2 into x1. It's
> useful because of things like -0.0, which is otherwise difficult to
> work with since it compares equal to 0.0. I would find it surprising
> for copysign to do a numeric calculation on complex numbers. Also,
> your suggested definition would be wrong for 0.0 and -0.0, since
> sign(0) is 0, and this is precisely where copysign matters.
> 
> Agreed on all points.
> 
> -- 
> Robert Kern
> ___
> NumPy-Discussion mailing list -- numpy-discussion@python.org
> To unsubscribe send an email to numpy-discussion-le...@python.org
> https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
> Member address: dom.grigo...@gmail.com

___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com


[Numpy-discussion] Re: Change definition of complex sign (and use it in copysign)

2024-01-04 Thread Marten van Kerkwijk
Hi All,

Thanks for the comments on complex sign - it seems there is good support
for it.

On copysign, currently it is not supported for complex values at all.  I
think given the responses so far, it looks like we should just keep it
like that; although my extension was fairly logical, I cannot say that I
know that I can think of a clear use case!  Anyway, I'm fine with
removing it from the PR.

All the best,

Marten
___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com