[Numpy-discussion] Unexpected return values for np.mod with x2=np.inf and similar

2024-06-08 Thread jesse . livezey
Hi all,

I ran into an odd edge-case with np.mod and was wondering if this is the 
expected behavior, and if so why. This is on a fresh install of python 3.10.14 
with numpy 1.26.4 from conda-forge.

>>> import numpy as np

# I have a hard time coming up with a rationale for why 2 of these produce 
non-inf values and the other 2 produce inf values.
>>> np.mod(1., np.inf)
1.0
>>> np.mod(1., -np.inf)
-inf
>>> np.mod(-1., -np.inf)
-1.0
>>> np.mod(-1., np.inf)
inf

# these are possibly sensible although the signed zero pattern is unexpected to 
me.
>>> np.mod(0., np.inf)
0.0
>>> np.mod(0., -np.inf)
-0.0
>>> np.mod(-0., -np.inf)
-0.0
>>> np.mod(-0., np.inf)
0.0

Any ideas why these are the return values? I had a hard time tracking down 
where in the numpy source np.mod was coming from.
Jesse
___
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] ENH: Adds cross2d to core and linalg (with API compatibility) #26640

2024-06-08 Thread Ben Woodruff
At the community meeting on Wednesday, we discussed adding `cross2d` as a new 
function, partly because of the deprecation of 2d arrays in `cross` (two issues 
are linked in the PR). Whether or not this is the right approach to take is 
something we want to have a bigger discussion about. One option discussed was 
adding both `cross2d` and `linalg.cross2d`. Another was just adding Array API 
compatible `linalg.cross2d`. Another was referring users to using `linalg.det` 
(though the return value is always floats which could be an issue). 

I volunteered to write the functions (partly as an exercise to learn the ins 
and outs of NumPy) and submitted the new functions as a PR. See 
https://github.com/numpy/numpy/pull/26640. I'm not offended at all if we decide 
on another route. 

We did discuss at the meeting that we need to provide some kind of alternative 
for people who use `cross` currently. One of the examples I updated for `cross` 
in the PR shows an option to pad 2D vectors and then use `cross`, though this 
will most likely be computationally much slower than `cross2d`.
___
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