-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Closed
Labels
array typesItems related to array API support and input array validation (see gh-18286)Items related to array API support and input array validation (see gh-18286)defectA clear bug or issue that prevents SciPy from being installed or used as expectedA clear bug or issue that prevents SciPy from being installed or used as expected
Milestone
Description
Describe your issue.
From offline discussion with @rgommers, behaviour with np
-coercible array-likes should not have regressed in #18668, but it has.
One potential solution is to attempt to use np.asarray
in compliance_scipy
on types unrecognised by array-api-compat
, a (definitely sub-optimal but I think correct) draft of which I have here: lucascolley@7ecfcc6.
Reproducing Code Example
>>> python dev.py ipython
>>> from scipy.cluster.vq import whiten
>>> whiten([[1.9, 2.3, 1.7],
...: [1.5, 2.5, 2.2],
...: [0.8, 0.6, 1.7,]])
# reset
>>> SCIPY_ARRAY_API=True python dev.py ipython
>>> from scipy.cluster.vq import whiten
>>> whiten([[1.9, 2.3, 1.7],
...: [1.5, 2.5, 2.2],
...: [0.8, 0.6, 1.7,]])
Error message
(scipy-dev) lucascolley@Lucass-MacBook-Air-2 scipy % python dev.py ipython
💻 ninja -C /Users/lucascolley/programming/scipy/build -j8
ninja: Entering directory `/Users/lucascolley/programming/scipy/build'
[4/4] Generating scipy/generate-version with a custom command
Build OK
💻 meson install -C build --only-changed
Installing, see meson-install.log...
Installation OK
Python 3.10.12 | packaged by conda-forge | (main, Jun 23 2023, 22:41:52) [Clang 15.0.7 ]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.14.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from scipy.cluster.vq import whiten
In [2]: whiten([[1.9, 2.3, 1.7],
...: [1.5, 2.5, 2.2],
...: [0.8, 0.6, 1.7,]])
Out[2]:
array([[4.17944278, 2.69811351, 7.21248917],
[3.29956009, 2.93273208, 9.33380951],
[1.75976538, 0.7038557 , 7.21248917]])
zsh: suspended python dev.py ipython
(scipy-dev) lucascolley@Lucass-MacBook-Air-2 scipy % SCIPY_ARRAY_API=True python dev.py ipython
💻 ninja -C /Users/lucascolley/programming/scipy/build -j8
ninja: Entering directory `/Users/lucascolley/programming/scipy/build'
[4/4] Generating scipy/generate-version with a custom command
Build OK
💻 meson install -C build --only-changed
Installing, see meson-install.log...
Installation OK
Python 3.10.12 | packaged by conda-forge | (main, Jun 23 2023, 22:41:52) [Clang 15.0.7 ]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.14.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from scipy.cluster.vq import whiten
In [2]: whiten([[1.9, 2.3, 1.7],
...: [1.5, 2.5, 2.2],
...: [0.8, 0.6, 1.7,]])
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[2], line 1
----> 1 whiten([[1.9, 2.3, 1.7],
2 [1.5, 2.5, 2.2],
3 [0.8, 0.6, 1.7,]])
File ~/programming/scipy/build-install/lib/python3.10/site-packages/scipy/cluster/vq.py:134, in whiten(obs, check_finite)
87 def whiten(obs, check_finite=True):
88 """
89 Normalize a group of observations on a per feature basis.
90
(...)
132
133 """
--> 134 xp = array_namespace(obs)
135 obs = as_xparray(obs, check_finite=check_finite, xp=xp)
136 std_dev = xp.std(obs, axis=0)
File ~/programming/scipy/build-install/lib/python3.10/site-packages/scipy/_lib/_array_api.py:93, in array_namespace(*arrays)
89 return array_api_compat_numpy
91 arrays = [array for array in arrays if array is not None]
---> 93 compliance_scipy(*arrays)
95 return array_api_compat.array_namespace(*arrays)
File ~/programming/scipy/build-install/lib/python3.10/site-packages/scipy/_lib/_array_api.py:46, in compliance_scipy(*arrays)
44 raise TypeError("'numpy.matrix' are not supported")
45 elif not array_api_compat.is_array_api_obj(array):
---> 46 raise TypeError("Only support Array API compatible arrays")
47 elif array.dtype is np.dtype('O'):
48 raise TypeError('object arrays are not supported')
TypeError: Only support Array API compatible arrays
SciPy/NumPy/Python version and system information
1.12.0.dev0+1533.23ed5fe 1.25.2 sys.version_info(major=3, minor=10, micro=12, releaselevel='final', serial=0)
Build Dependencies:
blas:
detection method: pkgconfig
found: true
include directory: /Users/lucascolley/mambaforge/envs/scipy-dev/include
lib directory: /Users/lucascolley/mambaforge/envs/scipy-dev/lib
name: openblas
openblas configuration: USE_64BITINT=0 DYNAMIC_ARCH=0 DYNAMIC_OLDER= NO_CBLAS=
NO_LAPACK=0 NO_LAPACKE= NO_AFFINITY=1 USE_OPENMP=1 VORTEX MAX_THREADS=128
pc file directory: /Users/lucascolley/mambaforge/envs/scipy-dev/lib/pkgconfig
version: 0.3.23
lapack:
detection method: pkgconfig
found: true
include directory: /Users/lucascolley/mambaforge/envs/scipy-dev/include
lib directory: /Users/lucascolley/mambaforge/envs/scipy-dev/lib
name: openblas
openblas configuration: USE_64BITINT=0 DYNAMIC_ARCH=0 DYNAMIC_OLDER= NO_CBLAS=
NO_LAPACK=0 NO_LAPACKE= NO_AFFINITY=1 USE_OPENMP=1 VORTEX MAX_THREADS=128
pc file directory: /Users/lucascolley/mambaforge/envs/scipy-dev/lib/pkgconfig
version: 0.3.23
pybind11:
detection method: pkgconfig
include directory: /Users/lucascolley/mambaforge/envs/scipy-dev/include
name: pybind11
version: 2.11.1
Compilers:
c:
args: -ftree-vectorize, -fPIC, -fPIE, -fstack-protector-strong, -O2, -pipe, -isystem,
/Users/lucascolley/mambaforge/envs/scipy-dev/include, -D_FORTIFY_SOURCE=2, -isystem,
/Users/lucascolley/mambaforge/envs/scipy-dev/include
commands: arm64-apple-darwin20.0.0-clang
linker: ld64
linker args: -Wl,-pie, -Wl,-headerpad_max_install_names, -Wl,-dead_strip_dylibs,
-Wl,-rpath,/Users/lucascolley/mambaforge/envs/scipy-dev/lib, -L/Users/lucascolley/mambaforge/envs/scipy-dev/lib,
-ftree-vectorize, -fPIC, -fPIE, -fstack-protector-strong, -O2, -pipe, -isystem,
/Users/lucascolley/mambaforge/envs/scipy-dev/include, -D_FORTIFY_SOURCE=2, -isystem,
/Users/lucascolley/mambaforge/envs/scipy-dev/include
name: clang
version: 15.0.7
c++:
args: -ftree-vectorize, -fPIC, -fPIE, -fstack-protector-strong, -O2, -pipe, -stdlib=libc++,
-fvisibility-inlines-hidden, -fmessage-length=0, -isystem, /Users/lucascolley/mambaforge/envs/scipy-dev/include,
-D_FORTIFY_SOURCE=2, -isystem, /Users/lucascolley/mambaforge/envs/scipy-dev/include
commands: arm64-apple-darwin20.0.0-clang++
linker: ld64
linker args: -Wl,-pie, -Wl,-headerpad_max_install_names, -Wl,-dead_strip_dylibs,
-Wl,-rpath,/Users/lucascolley/mambaforge/envs/scipy-dev/lib, -L/Users/lucascolley/mambaforge/envs/scipy-dev/lib,
-ftree-vectorize, -fPIC, -fPIE, -fstack-protector-strong, -O2, -pipe, -stdlib=libc++,
-fvisibility-inlines-hidden, -fmessage-length=0, -isystem, /Users/lucascolley/mambaforge/envs/scipy-dev/include,
-D_FORTIFY_SOURCE=2, -isystem, /Users/lucascolley/mambaforge/envs/scipy-dev/include
name: clang
version: 15.0.7
cython:
commands: cython
linker: cython
name: cython
version: 3.0.0
fortran:
args: -march=armv8.3-a, -ftree-vectorize, -fPIC, -fno-stack-protector, -O2, -pipe,
-isystem, /Users/lucascolley/mambaforge/envs/scipy-dev/include
commands: /Users/lucascolley/mambaforge/envs/scipy-dev/bin/arm64-apple-darwin20.0.0-gfortran
linker: ld64
linker args: -Wl,-pie, -Wl,-headerpad_max_install_names, -Wl,-dead_strip_dylibs,
-Wl,-rpath,/Users/lucascolley/mambaforge/envs/scipy-dev/lib, -L/Users/lucascolley/mambaforge/envs/scipy-dev/lib,
-march=armv8.3-a, -ftree-vectorize, -fPIC, -fno-stack-protector, -O2, -pipe,
-isystem, /Users/lucascolley/mambaforge/envs/scipy-dev/include
name: gcc
version: 12.3.0
pythran:
include directory: ../../../mambaforge/envs/scipy-dev/lib/python3.10/site-packages/pythran
version: 0.13.1
Machine Information:
build:
cpu: aarch64
endian: little
family: aarch64
system: darwin
cross-compiled: false
host:
cpu: aarch64
endian: little
family: aarch64
system: darwin
Python Information:
path: /Users/lucascolley/mambaforge/envs/scipy-dev/bin/python3.10
version: '3.10'
Metadata
Metadata
Assignees
Labels
array typesItems related to array API support and input array validation (see gh-18286)Items related to array API support and input array validation (see gh-18286)defectA clear bug or issue that prevents SciPy from being installed or used as expectedA clear bug or issue that prevents SciPy from being installed or used as expected