array-api-compat icon indicating copy to clipboard operation
array-api-compat copied to clipboard

`xp.vecdot` output arrayness depends on NumPy version

Open mdhaber opened this issue 4 months ago • 0 comments

With NumPy >= 2.0:

import numpy as np
from scipy._lib._array_api import array_namespace
x1 = np.asarray([0.667, 0.667, 0.667])
x2 = np.asarray([0.123, 0.456, 0.789])
xp = array_namespace(x1, x2)
xp.vecdot(x1, x2)
# np.float64(0.912456)

With NumPy < 2.0, the result is a 0d array.

I'd suggest that array-api-compat should either:

  • make modern NumPy produce an array (for compliance with the standard) or
  • make old NumPy produce a NumPy float (for consistency with all NumPy functions).

The latter would be my preference for now. (Actually fixing NumPy would be the long term preference - https://github.com/mdhaber/numpy/pull/2).

mdhaber avatar Oct 01 '25 23:10 mdhaber