ADAPT-Chase commited on
Commit
e696cfc
·
verified ·
1 Parent(s): 9c31fe9

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +64 -0
  2. tool_server/.venv/lib/python3.12/site-packages/scipy/__pycache__/__config__.cpython-312.pyc +0 -0
  3. tool_server/.venv/lib/python3.12/site-packages/scipy/__pycache__/__init__.cpython-312.pyc +0 -0
  4. tool_server/.venv/lib/python3.12/site-packages/scipy/__pycache__/_distributor_init.cpython-312.pyc +0 -0
  5. tool_server/.venv/lib/python3.12/site-packages/scipy/__pycache__/conftest.cpython-312.pyc +0 -0
  6. tool_server/.venv/lib/python3.12/site-packages/scipy/__pycache__/version.cpython-312.pyc +0 -0
  7. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/__init__.cpython-312.pyc +0 -0
  8. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_array_api.cpython-312.pyc +0 -0
  9. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_array_api_compat_vendor.cpython-312.pyc +0 -0
  10. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_array_api_no_0d.cpython-312.pyc +0 -0
  11. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_bunch.cpython-312.pyc +0 -0
  12. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_ccallback.cpython-312.pyc +0 -0
  13. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_disjoint_set.cpython-312.pyc +0 -0
  14. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_docscrape.cpython-312.pyc +0 -0
  15. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_elementwise_iterative_method.cpython-312.pyc +0 -0
  16. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_gcutils.cpython-312.pyc +0 -0
  17. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_pep440.cpython-312.pyc +0 -0
  18. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_sparse.cpython-312.pyc +0 -0
  19. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_testutils.cpython-312.pyc +0 -0
  20. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_threadsafety.cpython-312.pyc +0 -0
  21. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_tmpdirs.cpython-312.pyc +0 -0
  22. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_util.cpython-312.pyc +0 -0
  23. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/decorator.cpython-312.pyc +0 -0
  24. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/deprecation.cpython-312.pyc +0 -0
  25. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/doccer.cpython-312.pyc +0 -0
  26. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/uarray.cpython-312.pyc +0 -0
  27. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/_uarray/LICENSE +29 -0
  28. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/_uarray/__init__.py +116 -0
  29. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/_uarray/__pycache__/__init__.cpython-312.pyc +0 -0
  30. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/_uarray/__pycache__/_backend.cpython-312.pyc +0 -0
  31. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/_uarray/_backend.py +707 -0
  32. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/_uarray/_uarray.cpython-312-x86_64-linux-gnu.so +3 -0
  33. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/__init__.py +22 -0
  34. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/__pycache__/__init__.cpython-312.pyc +0 -0
  35. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/__pycache__/_internal.cpython-312.pyc +0 -0
  36. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/_internal.py +59 -0
  37. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/common/__init__.py +1 -0
  38. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/common/__pycache__/__init__.cpython-312.pyc +0 -0
  39. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/common/__pycache__/_aliases.cpython-312.pyc +0 -0
  40. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/common/__pycache__/_fft.cpython-312.pyc +0 -0
  41. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/common/__pycache__/_helpers.cpython-312.pyc +0 -0
  42. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/common/__pycache__/_linalg.cpython-312.pyc +0 -0
  43. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/common/__pycache__/_typing.cpython-312.pyc +0 -0
  44. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/common/_aliases.py +727 -0
  45. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/common/_fft.py +213 -0
  46. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/common/_helpers.py +1058 -0
  47. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/common/_linalg.py +232 -0
  48. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/common/_typing.py +192 -0
  49. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/cupy/__init__.py +13 -0
  50. tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/cupy/__pycache__/__init__.cpython-312.pyc +0 -0
.gitattributes CHANGED
@@ -4230,3 +4230,67 @@ tool_server/.venv/lib/python3.12/site-packages/scipy/integrate/_odepack.cpython-
4230
  tool_server/.venv/lib/python3.12/site-packages/scipy/integrate/_quadpack.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4231
  tool_server/.venv/lib/python3.12/site-packages/scipy/integrate/_test_odeint_banded.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4232
  tool_server/.venv/lib/python3.12/site-packages/scipy/integrate/_vode.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4230
  tool_server/.venv/lib/python3.12/site-packages/scipy/integrate/_quadpack.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4231
  tool_server/.venv/lib/python3.12/site-packages/scipy/integrate/_test_odeint_banded.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4232
  tool_server/.venv/lib/python3.12/site-packages/scipy/integrate/_vode.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4233
+ tool_server/.venv/lib/python3.12/site-packages/scipy/interpolate/_dfitpack.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4234
+ tool_server/.venv/lib/python3.12/site-packages/scipy/interpolate/_dierckx.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4235
+ tool_server/.venv/lib/python3.12/site-packages/scipy/interpolate/_interpnd.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4236
+ tool_server/.venv/lib/python3.12/site-packages/scipy/interpolate/_ppoly.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4237
+ tool_server/.venv/lib/python3.12/site-packages/scipy/interpolate/_rbfinterp_pythran.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4238
+ tool_server/.venv/lib/python3.12/site-packages/scipy/interpolate/_rgi_cython.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4239
+ tool_server/.venv/lib/python3.12/site-packages/scipy/linalg/_cythonized_array_utils.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4240
+ tool_server/.venv/lib/python3.12/site-packages/scipy/linalg/_decomp_interpolative.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4241
+ tool_server/.venv/lib/python3.12/site-packages/scipy/linalg/_decomp_lu_cython.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4242
+ tool_server/.venv/lib/python3.12/site-packages/scipy/linalg/_decomp_update.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4243
+ tool_server/.venv/lib/python3.12/site-packages/scipy/linalg/_fblas.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4244
+ tool_server/.venv/lib/python3.12/site-packages/scipy/linalg/_flapack.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4245
+ tool_server/.venv/lib/python3.12/site-packages/scipy/linalg/_linalg_pythran.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4246
+ tool_server/.venv/lib/python3.12/site-packages/scipy/linalg/_matfuncs_expm.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4247
+ tool_server/.venv/lib/python3.12/site-packages/scipy/linalg/_matfuncs_schur_sqrtm.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4248
+ tool_server/.venv/lib/python3.12/site-packages/scipy/linalg/_matfuncs_sqrtm_triu.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4249
+ tool_server/.venv/lib/python3.12/site-packages/scipy/linalg/_solve_toeplitz.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4250
+ tool_server/.venv/lib/python3.12/site-packages/scipy/linalg/cython_blas.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4251
+ tool_server/.venv/lib/python3.12/site-packages/scipy/linalg/cython_lapack.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4252
+ tool_server/.venv/lib/python3.12/site-packages/scipy/ndimage/_nd_image.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4253
+ tool_server/.venv/lib/python3.12/site-packages/scipy/ndimage/_ni_label.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4254
+ tool_server/.venv/lib/python3.12/site-packages/scipy/odr/__odrpack.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4255
+ tool_server/.venv/lib/python3.12/site-packages/scipy/optimize/_bglu_dense.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4256
+ tool_server/.venv/lib/python3.12/site-packages/scipy/optimize/_lbfgsb.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4257
+ tool_server/.venv/lib/python3.12/site-packages/scipy/optimize/_moduleTNC.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4258
+ tool_server/.venv/lib/python3.12/site-packages/scipy/optimize/_pava_pybind.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4259
+ tool_server/.venv/lib/python3.12/site-packages/scipy/optimize/_slsqplib.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4260
+ tool_server/.venv/lib/python3.12/site-packages/scipy/signal/_peak_finding_utils.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4261
+ tool_server/.venv/lib/python3.12/site-packages/scipy/signal/_sigtools.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4262
+ tool_server/.venv/lib/python3.12/site-packages/scipy/signal/_sosfilt.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4263
+ tool_server/.venv/lib/python3.12/site-packages/scipy/signal/_upfirdn_apply.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4264
+ tool_server/.venv/lib/python3.12/site-packages/scipy/sparse/_csparsetools.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4265
+ tool_server/.venv/lib/python3.12/site-packages/scipy/sparse/_sparsetools.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4266
+ tool_server/.venv/lib/python3.12/site-packages/scipy/spatial/_ckdtree.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4267
+ tool_server/.venv/lib/python3.12/site-packages/scipy/spatial/_distance_pybind.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4268
+ tool_server/.venv/lib/python3.12/site-packages/scipy/spatial/_distance_wrap.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4269
+ tool_server/.venv/lib/python3.12/site-packages/scipy/spatial/_hausdorff.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4270
+ tool_server/.venv/lib/python3.12/site-packages/scipy/spatial/_qhull.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4271
+ tool_server/.venv/lib/python3.12/site-packages/scipy/special/_ellip_harm_2.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4272
+ tool_server/.venv/lib/python3.12/site-packages/scipy/special/_gufuncs.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4273
+ tool_server/.venv/lib/python3.12/site-packages/scipy/special/_specfun.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4274
+ tool_server/.venv/lib/python3.12/site-packages/scipy/special/_special_ufuncs.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4275
+ tool_server/.venv/lib/python3.12/site-packages/scipy/special/_test_internal.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4276
+ tool_server/.venv/lib/python3.12/site-packages/scipy/special/_ufuncs.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4277
+ tool_server/.venv/lib/python3.12/site-packages/scipy/special/_ufuncs_cxx.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4278
+ tool_server/.venv/lib/python3.12/site-packages/scipy/special/cython_special.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4279
+ tool_server/.venv/lib/python3.12/site-packages/scipy/stats/_ansari_swilk_statistics.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4280
+ tool_server/.venv/lib/python3.12/site-packages/scipy/stats/_biasedurn.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4281
+ tool_server/.venv/lib/python3.12/site-packages/scipy/stats/_qmc_cy.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4282
+ tool_server/.venv/lib/python3.12/site-packages/scipy/stats/_qmvnt_cy.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4283
+ tool_server/.venv/lib/python3.12/site-packages/scipy/stats/_sobol.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4284
+ tool_server/.venv/lib/python3.12/site-packages/scipy/stats/_stats.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4285
+ tool_server/.venv/lib/python3.12/site-packages/scipy/stats/_stats_pythran.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4286
+ tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/_uarray/_uarray.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4287
+ tool_server/.venv/lib/python3.12/site-packages/scipy/cluster/__pycache__/hierarchy.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
4288
+ tool_server/.venv/lib/python3.12/site-packages/scipy/constants/__pycache__/_codata.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
4289
+ tool_server/.venv/lib/python3.12/site-packages/scipy/fft/_pocketfft/pypocketfft.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4290
+ tool_server/.venv/lib/python3.12/site-packages/scipy/integrate/__pycache__/_lebedev.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
4291
+ tool_server/.venv/lib/python3.12/site-packages/scipy/interpolate/__pycache__/_fitpack2.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
4292
+ tool_server/.venv/lib/python3.12/site-packages/scipy/interpolate/tests/__pycache__/test_bsplines.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
4293
+ tool_server/.venv/lib/python3.12/site-packages/scipy/interpolate/tests/__pycache__/test_interpolate.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
4294
+ tool_server/.venv/lib/python3.12/site-packages/scipy/io/_fast_matrix_market/_fmm_core.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4295
+ tool_server/.venv/lib/python3.12/site-packages/scipy/io/matlab/_mio5_utils.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4296
+ tool_server/.venv/lib/python3.12/site-packages/scipy/io/matlab/_streams.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
tool_server/.venv/lib/python3.12/site-packages/scipy/__pycache__/__config__.cpython-312.pyc ADDED
Binary file (4.57 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (4.19 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/__pycache__/_distributor_init.cpython-312.pyc ADDED
Binary file (843 Bytes). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/__pycache__/conftest.cpython-312.pyc ADDED
Binary file (24.7 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/__pycache__/version.cpython-312.pyc ADDED
Binary file (550 Bytes). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (562 Bytes). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_array_api.cpython-312.pyc ADDED
Binary file (35.1 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_array_api_compat_vendor.cpython-312.pyc ADDED
Binary file (321 Bytes). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_array_api_no_0d.cpython-312.pyc ADDED
Binary file (4.07 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_bunch.cpython-312.pyc ADDED
Binary file (9.01 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_ccallback.cpython-312.pyc ADDED
Binary file (9.4 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_disjoint_set.cpython-312.pyc ADDED
Binary file (8.3 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_docscrape.cpython-312.pyc ADDED
Binary file (32.6 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_elementwise_iterative_method.cpython-312.pyc ADDED
Binary file (14.9 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_gcutils.cpython-312.pyc ADDED
Binary file (3.6 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_pep440.cpython-312.pyc ADDED
Binary file (18.8 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_sparse.cpython-312.pyc ADDED
Binary file (1.31 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_testutils.cpython-312.pyc ADDED
Binary file (16.4 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_threadsafety.cpython-312.pyc ADDED
Binary file (2.97 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_tmpdirs.cpython-312.pyc ADDED
Binary file (3.21 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/_util.cpython-312.pyc ADDED
Binary file (56.5 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/decorator.cpython-312.pyc ADDED
Binary file (17.5 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/deprecation.cpython-312.pyc ADDED
Binary file (11.2 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/doccer.cpython-312.pyc ADDED
Binary file (12.6 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/__pycache__/uarray.cpython-312.pyc ADDED
Binary file (918 Bytes). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/_uarray/LICENSE ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2018, Quansight-Labs
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ * Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/_uarray/__init__.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ .. note:
3
+ If you are looking for overrides for NumPy-specific methods, see the
4
+ documentation for :obj:`unumpy`. This page explains how to write
5
+ back-ends and multimethods.
6
+
7
+ ``uarray`` is built around a back-end protocol, and overridable multimethods.
8
+ It is necessary to define multimethods for back-ends to be able to override them.
9
+ See the documentation of :obj:`generate_multimethod` on how to write multimethods.
10
+
11
+
12
+
13
+ Let's start with the simplest:
14
+
15
+ ``__ua_domain__`` defines the back-end *domain*. The domain consists of period-
16
+ separated string consisting of the modules you extend plus the submodule. For
17
+ example, if a submodule ``module2.submodule`` extends ``module1``
18
+ (i.e., it exposes dispatchables marked as types available in ``module1``),
19
+ then the domain string should be ``"module1.module2.submodule"``.
20
+
21
+
22
+ For the purpose of this demonstration, we'll be creating an object and setting
23
+ its attributes directly. However, note that you can use a module or your own type
24
+ as a backend as well.
25
+
26
+ >>> class Backend: pass
27
+ >>> be = Backend()
28
+ >>> be.__ua_domain__ = "ua_examples"
29
+
30
+ It might be useful at this point to sidetrack to the documentation of
31
+ :obj:`generate_multimethod` to find out how to generate a multimethod
32
+ overridable by :obj:`uarray`. Needless to say, writing a backend and
33
+ creating multimethods are mostly orthogonal activities, and knowing
34
+ one doesn't necessarily require knowledge of the other, although it
35
+ is certainly helpful. We expect core API designers/specifiers to write the
36
+ multimethods, and implementors to override them. But, as is often the case,
37
+ similar people write both.
38
+
39
+ Without further ado, here's an example multimethod:
40
+
41
+ >>> import uarray as ua
42
+ >>> from uarray import Dispatchable
43
+ >>> def override_me(a, b):
44
+ ... return Dispatchable(a, int),
45
+ >>> def override_replacer(args, kwargs, dispatchables):
46
+ ... return (dispatchables[0], args[1]), {}
47
+ >>> overridden_me = ua.generate_multimethod(
48
+ ... override_me, override_replacer, "ua_examples"
49
+ ... )
50
+
51
+ Next comes the part about overriding the multimethod. This requires
52
+ the ``__ua_function__`` protocol, and the ``__ua_convert__``
53
+ protocol. The ``__ua_function__`` protocol has the signature
54
+ ``(method, args, kwargs)`` where ``method`` is the passed
55
+ multimethod, ``args``/``kwargs`` specify the arguments and ``dispatchables``
56
+ is the list of converted dispatchables passed in.
57
+
58
+ >>> def __ua_function__(method, args, kwargs):
59
+ ... return method.__name__, args, kwargs
60
+ >>> be.__ua_function__ = __ua_function__
61
+
62
+ The other protocol of interest is the ``__ua_convert__`` protocol. It has the
63
+ signature ``(dispatchables, coerce)``. When ``coerce`` is ``False``, conversion
64
+ between the formats should ideally be an ``O(1)`` operation, but it means that
65
+ no memory copying should be involved, only views of the existing data.
66
+
67
+ >>> def __ua_convert__(dispatchables, coerce):
68
+ ... for d in dispatchables:
69
+ ... if d.type is int:
70
+ ... if coerce and d.coercible:
71
+ ... yield str(d.value)
72
+ ... else:
73
+ ... yield d.value
74
+ >>> be.__ua_convert__ = __ua_convert__
75
+
76
+ Now that we have defined the backend, the next thing to do is to call the multimethod.
77
+
78
+ >>> with ua.set_backend(be):
79
+ ... overridden_me(1, "2")
80
+ ('override_me', (1, '2'), {})
81
+
82
+ Note that the marked type has no effect on the actual type of the passed object.
83
+ We can also coerce the type of the input.
84
+
85
+ >>> with ua.set_backend(be, coerce=True):
86
+ ... overridden_me(1, "2")
87
+ ... overridden_me(1.0, "2")
88
+ ('override_me', ('1', '2'), {})
89
+ ('override_me', ('1.0', '2'), {})
90
+
91
+ Another feature is that if you remove ``__ua_convert__``, the arguments are not
92
+ converted at all and it's up to the backend to handle that.
93
+
94
+ >>> del be.__ua_convert__
95
+ >>> with ua.set_backend(be):
96
+ ... overridden_me(1, "2")
97
+ ('override_me', (1, '2'), {})
98
+
99
+ You also have the option to return ``NotImplemented``, in which case processing moves on
100
+ to the next back-end, which in this case, doesn't exist. The same applies to
101
+ ``__ua_convert__``.
102
+
103
+ >>> be.__ua_function__ = lambda *a, **kw: NotImplemented
104
+ >>> with ua.set_backend(be):
105
+ ... overridden_me(1, "2")
106
+ Traceback (most recent call last):
107
+ ...
108
+ uarray.BackendNotImplementedError: ...
109
+
110
+ The last possibility is if we don't have ``__ua_convert__``, in which case the job is
111
+ left up to ``__ua_function__``, but putting things back into arrays after conversion
112
+ will not be possible.
113
+ """
114
+
115
+ from ._backend import *
116
+ __version__ = '0.8.8.dev0+aa94c5a4.scipy'
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/_uarray/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (4.71 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/_uarray/__pycache__/_backend.cpython-312.pyc ADDED
Binary file (25.1 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/_uarray/_backend.py ADDED
@@ -0,0 +1,707 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import typing
2
+ import types
3
+ import inspect
4
+ import functools
5
+ from . import _uarray
6
+ import copyreg
7
+ import pickle
8
+ import contextlib
9
+ import threading
10
+
11
+ from ._uarray import ( # type: ignore
12
+ BackendNotImplementedError,
13
+ _Function,
14
+ _SkipBackendContext,
15
+ _SetBackendContext,
16
+ _BackendState,
17
+ )
18
+
19
+ __all__ = [
20
+ "set_backend",
21
+ "set_global_backend",
22
+ "skip_backend",
23
+ "register_backend",
24
+ "determine_backend",
25
+ "determine_backend_multi",
26
+ "clear_backends",
27
+ "create_multimethod",
28
+ "generate_multimethod",
29
+ "_Function",
30
+ "BackendNotImplementedError",
31
+ "Dispatchable",
32
+ "wrap_single_convertor",
33
+ "wrap_single_convertor_instance",
34
+ "all_of_type",
35
+ "mark_as",
36
+ "set_state",
37
+ "get_state",
38
+ "reset_state",
39
+ "_BackendState",
40
+ "_SkipBackendContext",
41
+ "_SetBackendContext",
42
+ ]
43
+
44
+ ArgumentExtractorType = typing.Callable[..., tuple["Dispatchable", ...]]
45
+ ArgumentReplacerType = typing.Callable[
46
+ [tuple, dict, tuple], tuple[tuple, dict]
47
+ ]
48
+
49
+ def unpickle_function(mod_name, qname, self_):
50
+ import importlib
51
+
52
+ try:
53
+ module = importlib.import_module(mod_name)
54
+ qname = qname.split(".")
55
+ func = module
56
+ for q in qname:
57
+ func = getattr(func, q)
58
+
59
+ if self_ is not None:
60
+ func = types.MethodType(func, self_)
61
+
62
+ return func
63
+ except (ImportError, AttributeError) as e:
64
+ from pickle import UnpicklingError
65
+
66
+ raise UnpicklingError from e
67
+
68
+
69
+ def pickle_function(func):
70
+ mod_name = getattr(func, "__module__", None)
71
+ qname = getattr(func, "__qualname__", None)
72
+ self_ = getattr(func, "__self__", None)
73
+
74
+ try:
75
+ test = unpickle_function(mod_name, qname, self_)
76
+ except pickle.UnpicklingError:
77
+ test = None
78
+
79
+ if test is not func:
80
+ raise pickle.PicklingError(
81
+ f"Can't pickle {func}: it's not the same object as {test}"
82
+ )
83
+
84
+ return unpickle_function, (mod_name, qname, self_)
85
+
86
+
87
+ def pickle_state(state):
88
+ return _uarray._BackendState._unpickle, state._pickle()
89
+
90
+
91
+ def pickle_set_backend_context(ctx):
92
+ return _SetBackendContext, ctx._pickle()
93
+
94
+
95
+ def pickle_skip_backend_context(ctx):
96
+ return _SkipBackendContext, ctx._pickle()
97
+
98
+
99
+ copyreg.pickle(_Function, pickle_function)
100
+ copyreg.pickle(_uarray._BackendState, pickle_state)
101
+ copyreg.pickle(_SetBackendContext, pickle_set_backend_context)
102
+ copyreg.pickle(_SkipBackendContext, pickle_skip_backend_context)
103
+
104
+
105
+ def get_state():
106
+ """
107
+ Returns an opaque object containing the current state of all the backends.
108
+
109
+ Can be used for synchronization between threads/processes.
110
+
111
+ See Also
112
+ --------
113
+ set_state
114
+ Sets the state returned by this function.
115
+ """
116
+ return _uarray.get_state()
117
+
118
+
119
+ @contextlib.contextmanager
120
+ def reset_state():
121
+ """
122
+ Returns a context manager that resets all state once exited.
123
+
124
+ See Also
125
+ --------
126
+ set_state
127
+ Context manager that sets the backend state.
128
+ get_state
129
+ Gets a state to be set by this context manager.
130
+ """
131
+ with set_state(get_state()):
132
+ yield
133
+
134
+
135
+ @contextlib.contextmanager
136
+ def set_state(state):
137
+ """
138
+ A context manager that sets the state of the backends to one returned by :obj:`get_state`.
139
+
140
+ See Also
141
+ --------
142
+ get_state
143
+ Gets a state to be set by this context manager.
144
+ """ # noqa: E501
145
+ old_state = get_state()
146
+ _uarray.set_state(state)
147
+ try:
148
+ yield
149
+ finally:
150
+ _uarray.set_state(old_state, True)
151
+
152
+
153
+ def create_multimethod(*args, **kwargs):
154
+ """
155
+ Creates a decorator for generating multimethods.
156
+
157
+ This function creates a decorator that can be used with an argument
158
+ extractor in order to generate a multimethod. Other than for the
159
+ argument extractor, all arguments are passed on to
160
+ :obj:`generate_multimethod`.
161
+
162
+ See Also
163
+ --------
164
+ generate_multimethod
165
+ Generates a multimethod.
166
+ """
167
+
168
+ def wrapper(a):
169
+ return generate_multimethod(a, *args, **kwargs)
170
+
171
+ return wrapper
172
+
173
+
174
+ def generate_multimethod(
175
+ argument_extractor: ArgumentExtractorType,
176
+ argument_replacer: ArgumentReplacerType,
177
+ domain: str,
178
+ default: typing.Callable | None = None,
179
+ ):
180
+ """
181
+ Generates a multimethod.
182
+
183
+ Parameters
184
+ ----------
185
+ argument_extractor : ArgumentExtractorType
186
+ A callable which extracts the dispatchable arguments. Extracted arguments
187
+ should be marked by the :obj:`Dispatchable` class. It has the same signature
188
+ as the desired multimethod.
189
+ argument_replacer : ArgumentReplacerType
190
+ A callable with the signature (args, kwargs, dispatchables), which should also
191
+ return an (args, kwargs) pair with the dispatchables replaced inside the
192
+ args/kwargs.
193
+ domain : str
194
+ A string value indicating the domain of this multimethod.
195
+ default: Optional[Callable], optional
196
+ The default implementation of this multimethod, where ``None`` (the default)
197
+ specifies there is no default implementation.
198
+
199
+ Examples
200
+ --------
201
+ In this example, ``a`` is to be dispatched over, so we return it, while marking it
202
+ as an ``int``.
203
+ The trailing comma is needed because the args have to be returned as an iterable.
204
+
205
+ >>> def override_me(a, b):
206
+ ... return Dispatchable(a, int),
207
+
208
+ Next, we define the argument replacer that replaces the dispatchables inside
209
+ args/kwargs with the supplied ones.
210
+
211
+ >>> def override_replacer(args, kwargs, dispatchables):
212
+ ... return (dispatchables[0], args[1]), {}
213
+
214
+ Next, we define the multimethod.
215
+
216
+ >>> overridden_me = generate_multimethod(
217
+ ... override_me, override_replacer, "ua_examples"
218
+ ... )
219
+
220
+ Notice that there's no default implementation, unless you supply one.
221
+
222
+ >>> overridden_me(1, "a")
223
+ Traceback (most recent call last):
224
+ ...
225
+ uarray.BackendNotImplementedError: ...
226
+
227
+ >>> overridden_me2 = generate_multimethod(
228
+ ... override_me, override_replacer, "ua_examples", default=lambda x, y: (x, y)
229
+ ... )
230
+ >>> overridden_me2(1, "a")
231
+ (1, 'a')
232
+
233
+ See Also
234
+ --------
235
+ uarray
236
+ See the module documentation for how to override the method by creating
237
+ backends.
238
+ """
239
+ kw_defaults, arg_defaults, opts = get_defaults(argument_extractor)
240
+ ua_func = _Function(
241
+ argument_extractor,
242
+ argument_replacer,
243
+ domain,
244
+ arg_defaults,
245
+ kw_defaults,
246
+ default,
247
+ )
248
+
249
+ return functools.update_wrapper(ua_func, argument_extractor)
250
+
251
+
252
+ def set_backend(backend, coerce=False, only=False):
253
+ """
254
+ A context manager that sets the preferred backend.
255
+
256
+ Parameters
257
+ ----------
258
+ backend
259
+ The backend to set.
260
+ coerce
261
+ Whether or not to coerce to a specific backend's types. Implies ``only``.
262
+ only
263
+ Whether or not this should be the last backend to try.
264
+
265
+ See Also
266
+ --------
267
+ skip_backend: A context manager that allows skipping of backends.
268
+ set_global_backend: Set a single, global backend for a domain.
269
+ """
270
+ tid = threading.get_native_id()
271
+ try:
272
+ return backend.__ua_cache__[tid, "set", coerce, only]
273
+ except AttributeError:
274
+ backend.__ua_cache__ = {}
275
+ except KeyError:
276
+ pass
277
+
278
+ ctx = _SetBackendContext(backend, coerce, only)
279
+ backend.__ua_cache__[tid, "set", coerce, only] = ctx
280
+ return ctx
281
+
282
+
283
+ def skip_backend(backend):
284
+ """
285
+ A context manager that allows one to skip a given backend from processing
286
+ entirely. This allows one to use another backend's code in a library that
287
+ is also a consumer of the same backend.
288
+
289
+ Parameters
290
+ ----------
291
+ backend
292
+ The backend to skip.
293
+
294
+ See Also
295
+ --------
296
+ set_backend: A context manager that allows setting of backends.
297
+ set_global_backend: Set a single, global backend for a domain.
298
+ """
299
+ tid = threading.get_native_id()
300
+ try:
301
+ return backend.__ua_cache__[tid, "skip"]
302
+ except AttributeError:
303
+ backend.__ua_cache__ = {}
304
+ except KeyError:
305
+ pass
306
+
307
+ ctx = _SkipBackendContext(backend)
308
+ backend.__ua_cache__[tid, "skip"] = ctx
309
+ return ctx
310
+
311
+
312
+ def get_defaults(f):
313
+ sig = inspect.signature(f)
314
+ kw_defaults = {}
315
+ arg_defaults = []
316
+ opts = set()
317
+ for k, v in sig.parameters.items():
318
+ if v.default is not inspect.Parameter.empty:
319
+ kw_defaults[k] = v.default
320
+ if v.kind in (
321
+ inspect.Parameter.POSITIONAL_ONLY,
322
+ inspect.Parameter.POSITIONAL_OR_KEYWORD,
323
+ ):
324
+ arg_defaults.append(v.default)
325
+ opts.add(k)
326
+
327
+ return kw_defaults, tuple(arg_defaults), opts
328
+
329
+
330
+ def set_global_backend(backend, coerce=False, only=False, *, try_last=False):
331
+ """
332
+ This utility method replaces the default backend for permanent use. It
333
+ will be tried in the list of backends automatically, unless the
334
+ ``only`` flag is set on a backend. This will be the first tried
335
+ backend outside the :obj:`set_backend` context manager.
336
+
337
+ Note that this method is not thread-safe.
338
+
339
+ .. warning::
340
+ We caution library authors against using this function in
341
+ their code. We do *not* support this use-case. This function
342
+ is meant to be used only by users themselves, or by a reference
343
+ implementation, if one exists.
344
+
345
+ Parameters
346
+ ----------
347
+ backend
348
+ The backend to register.
349
+ coerce : bool
350
+ Whether to coerce input types when trying this backend.
351
+ only : bool
352
+ If ``True``, no more backends will be tried if this fails.
353
+ Implied by ``coerce=True``.
354
+ try_last : bool
355
+ If ``True``, the global backend is tried after registered backends.
356
+
357
+ See Also
358
+ --------
359
+ set_backend: A context manager that allows setting of backends.
360
+ skip_backend: A context manager that allows skipping of backends.
361
+ """
362
+ _uarray.set_global_backend(backend, coerce, only, try_last)
363
+
364
+
365
+ def register_backend(backend):
366
+ """
367
+ This utility method sets registers backend for permanent use. It
368
+ will be tried in the list of backends automatically, unless the
369
+ ``only`` flag is set on a backend.
370
+
371
+ Note that this method is not thread-safe.
372
+
373
+ Parameters
374
+ ----------
375
+ backend
376
+ The backend to register.
377
+ """
378
+ _uarray.register_backend(backend)
379
+
380
+
381
+ def clear_backends(domain, registered=True, globals=False):
382
+ """
383
+ This utility method clears registered backends.
384
+
385
+ .. warning::
386
+ We caution library authors against using this function in
387
+ their code. We do *not* support this use-case. This function
388
+ is meant to be used only by users themselves.
389
+
390
+ .. warning::
391
+ Do NOT use this method inside a multimethod call, or the
392
+ program is likely to crash.
393
+
394
+ Parameters
395
+ ----------
396
+ domain : Optional[str]
397
+ The domain for which to de-register backends. ``None`` means
398
+ de-register for all domains.
399
+ registered : bool
400
+ Whether or not to clear registered backends. See :obj:`register_backend`.
401
+ globals : bool
402
+ Whether or not to clear global backends. See :obj:`set_global_backend`.
403
+
404
+ See Also
405
+ --------
406
+ register_backend : Register a backend globally.
407
+ set_global_backend : Set a global backend.
408
+ """
409
+ _uarray.clear_backends(domain, registered, globals)
410
+
411
+
412
+ class Dispatchable:
413
+ """
414
+ A utility class which marks an argument with a specific dispatch type.
415
+
416
+
417
+ Attributes
418
+ ----------
419
+ value
420
+ The value of the Dispatchable.
421
+
422
+ type
423
+ The type of the Dispatchable.
424
+
425
+ Examples
426
+ --------
427
+ >>> x = Dispatchable(1, str)
428
+ >>> x
429
+ <Dispatchable: type=<class 'str'>, value=1>
430
+
431
+ See Also
432
+ --------
433
+ all_of_type
434
+ Marks all unmarked parameters of a function.
435
+
436
+ mark_as
437
+ Allows one to create a utility function to mark as a given type.
438
+ """
439
+
440
+ def __init__(self, value, dispatch_type, coercible=True):
441
+ self.value = value
442
+ self.type = dispatch_type
443
+ self.coercible = coercible
444
+
445
+ def __getitem__(self, index):
446
+ return (self.type, self.value)[index]
447
+
448
+ def __str__(self):
449
+ return f"<{type(self).__name__}: type={self.type!r}, value={self.value!r}>"
450
+
451
+ __repr__ = __str__
452
+
453
+
454
+ def mark_as(dispatch_type):
455
+ """
456
+ Creates a utility function to mark something as a specific type.
457
+
458
+ Examples
459
+ --------
460
+ >>> mark_int = mark_as(int)
461
+ >>> mark_int(1)
462
+ <Dispatchable: type=<class 'int'>, value=1>
463
+ """
464
+ return functools.partial(Dispatchable, dispatch_type=dispatch_type)
465
+
466
+
467
+ def all_of_type(arg_type):
468
+ """
469
+ Marks all unmarked arguments as a given type.
470
+
471
+ Examples
472
+ --------
473
+ >>> @all_of_type(str)
474
+ ... def f(a, b):
475
+ ... return a, Dispatchable(b, int)
476
+ >>> f('a', 1)
477
+ (<Dispatchable: type=<class 'str'>, value='a'>,
478
+ <Dispatchable: type=<class 'int'>, value=1>)
479
+ """
480
+
481
+ def outer(func):
482
+ @functools.wraps(func)
483
+ def inner(*args, **kwargs):
484
+ extracted_args = func(*args, **kwargs)
485
+ return tuple(
486
+ Dispatchable(arg, arg_type)
487
+ if not isinstance(arg, Dispatchable)
488
+ else arg
489
+ for arg in extracted_args
490
+ )
491
+
492
+ return inner
493
+
494
+ return outer
495
+
496
+
497
+ def wrap_single_convertor(convert_single):
498
+ """
499
+ Wraps a ``__ua_convert__`` defined for a single element to all elements.
500
+ If any of them return ``NotImplemented``, the operation is assumed to be
501
+ undefined.
502
+
503
+ Accepts a signature of (value, type, coerce).
504
+ """
505
+
506
+ @functools.wraps(convert_single)
507
+ def __ua_convert__(dispatchables, coerce):
508
+ converted = []
509
+ for d in dispatchables:
510
+ c = convert_single(d.value, d.type, coerce and d.coercible)
511
+
512
+ if c is NotImplemented:
513
+ return NotImplemented
514
+
515
+ converted.append(c)
516
+
517
+ return converted
518
+
519
+ return __ua_convert__
520
+
521
+
522
+ def wrap_single_convertor_instance(convert_single):
523
+ """
524
+ Wraps a ``__ua_convert__`` defined for a single element to all elements.
525
+ If any of them return ``NotImplemented``, the operation is assumed to be
526
+ undefined.
527
+
528
+ Accepts a signature of (value, type, coerce).
529
+ """
530
+
531
+ @functools.wraps(convert_single)
532
+ def __ua_convert__(self, dispatchables, coerce):
533
+ converted = []
534
+ for d in dispatchables:
535
+ c = convert_single(self, d.value, d.type, coerce and d.coercible)
536
+
537
+ if c is NotImplemented:
538
+ return NotImplemented
539
+
540
+ converted.append(c)
541
+
542
+ return converted
543
+
544
+ return __ua_convert__
545
+
546
+
547
+ def determine_backend(value, dispatch_type, *, domain, only=True, coerce=False):
548
+ """Set the backend to the first active backend that supports ``value``
549
+
550
+ This is useful for functions that call multimethods without any dispatchable
551
+ arguments. You can use :func:`determine_backend` to ensure the same backend
552
+ is used everywhere in a block of multimethod calls.
553
+
554
+ Parameters
555
+ ----------
556
+ value
557
+ The value being tested
558
+ dispatch_type
559
+ The dispatch type associated with ``value``, aka
560
+ ":ref:`marking <MarkingGlossary>`".
561
+ domain: string
562
+ The domain to query for backends and set.
563
+ coerce: bool
564
+ Whether or not to allow coercion to the backend's types. Implies ``only``.
565
+ only: bool
566
+ Whether or not this should be the last backend to try.
567
+
568
+ See Also
569
+ --------
570
+ set_backend: For when you know which backend to set
571
+
572
+ Notes
573
+ -----
574
+
575
+ Support is determined by the ``__ua_convert__`` protocol. Backends not
576
+ supporting the type must return ``NotImplemented`` from their
577
+ ``__ua_convert__`` if they don't support input of that type.
578
+
579
+ Examples
580
+ --------
581
+
582
+ Suppose we have two backends ``BackendA`` and ``BackendB`` each supporting
583
+ different types, ``TypeA`` and ``TypeB``. Neither supporting the other type:
584
+
585
+ >>> with ua.set_backend(ex.BackendA):
586
+ ... ex.call_multimethod(ex.TypeB(), ex.TypeB())
587
+ Traceback (most recent call last):
588
+ ...
589
+ uarray.BackendNotImplementedError: ...
590
+
591
+ Now consider a multimethod that creates a new object of ``TypeA``, or
592
+ ``TypeB`` depending on the active backend.
593
+
594
+ >>> with ua.set_backend(ex.BackendA), ua.set_backend(ex.BackendB):
595
+ ... res = ex.creation_multimethod()
596
+ ... ex.call_multimethod(res, ex.TypeA())
597
+ Traceback (most recent call last):
598
+ ...
599
+ uarray.BackendNotImplementedError: ...
600
+
601
+ ``res`` is an object of ``TypeB`` because ``BackendB`` is set in the
602
+ innermost with statement. So, ``call_multimethod`` fails since the types
603
+ don't match.
604
+
605
+ Instead, we need to first find a backend suitable for all of our objects.
606
+
607
+ >>> with ua.set_backend(ex.BackendA), ua.set_backend(ex.BackendB):
608
+ ... x = ex.TypeA()
609
+ ... with ua.determine_backend(x, "mark", domain="ua_examples"):
610
+ ... res = ex.creation_multimethod()
611
+ ... ex.call_multimethod(res, x)
612
+ TypeA
613
+
614
+ """
615
+ dispatchables = (Dispatchable(value, dispatch_type, coerce),)
616
+ backend = _uarray.determine_backend(domain, dispatchables, coerce)
617
+
618
+ return set_backend(backend, coerce=coerce, only=only)
619
+
620
+
621
+ def determine_backend_multi(
622
+ dispatchables, *, domain, only=True, coerce=False, **kwargs
623
+ ):
624
+ """Set a backend supporting all ``dispatchables``
625
+
626
+ This is useful for functions that call multimethods without any dispatchable
627
+ arguments. You can use :func:`determine_backend_multi` to ensure the same
628
+ backend is used everywhere in a block of multimethod calls involving
629
+ multiple arrays.
630
+
631
+ Parameters
632
+ ----------
633
+ dispatchables: Sequence[Union[uarray.Dispatchable, Any]]
634
+ The dispatchables that must be supported
635
+ domain: string
636
+ The domain to query for backends and set.
637
+ coerce: bool
638
+ Whether or not to allow coercion to the backend's types. Implies ``only``.
639
+ only: bool
640
+ Whether or not this should be the last backend to try.
641
+ dispatch_type: Optional[Any]
642
+ The default dispatch type associated with ``dispatchables``, aka
643
+ ":ref:`marking <MarkingGlossary>`".
644
+
645
+ See Also
646
+ --------
647
+ determine_backend: For a single dispatch value
648
+ set_backend: For when you know which backend to set
649
+
650
+ Notes
651
+ -----
652
+
653
+ Support is determined by the ``__ua_convert__`` protocol. Backends not
654
+ supporting the type must return ``NotImplemented`` from their
655
+ ``__ua_convert__`` if they don't support input of that type.
656
+
657
+ Examples
658
+ --------
659
+
660
+ :func:`determine_backend` allows the backend to be set from a single
661
+ object. :func:`determine_backend_multi` allows multiple objects to be
662
+ checked simultaneously for support in the backend. Suppose we have a
663
+ ``BackendAB`` which supports ``TypeA`` and ``TypeB`` in the same call,
664
+ and a ``BackendBC`` that doesn't support ``TypeA``.
665
+
666
+ >>> with ua.set_backend(ex.BackendAB), ua.set_backend(ex.BackendBC):
667
+ ... a, b = ex.TypeA(), ex.TypeB()
668
+ ... with ua.determine_backend_multi(
669
+ ... [ua.Dispatchable(a, "mark"), ua.Dispatchable(b, "mark")],
670
+ ... domain="ua_examples"
671
+ ... ):
672
+ ... res = ex.creation_multimethod()
673
+ ... ex.call_multimethod(res, a, b)
674
+ TypeA
675
+
676
+ This won't call ``BackendBC`` because it doesn't support ``TypeA``.
677
+
678
+ We can also use leave out the ``ua.Dispatchable`` if we specify the
679
+ default ``dispatch_type`` for the ``dispatchables`` argument.
680
+
681
+ >>> with ua.set_backend(ex.BackendAB), ua.set_backend(ex.BackendBC):
682
+ ... a, b = ex.TypeA(), ex.TypeB()
683
+ ... with ua.determine_backend_multi(
684
+ ... [a, b], dispatch_type="mark", domain="ua_examples"
685
+ ... ):
686
+ ... res = ex.creation_multimethod()
687
+ ... ex.call_multimethod(res, a, b)
688
+ TypeA
689
+
690
+ """
691
+ if "dispatch_type" in kwargs:
692
+ disp_type = kwargs.pop("dispatch_type")
693
+ dispatchables = tuple(
694
+ d if isinstance(d, Dispatchable) else Dispatchable(d, disp_type)
695
+ for d in dispatchables
696
+ )
697
+ else:
698
+ dispatchables = tuple(dispatchables)
699
+ if not all(isinstance(d, Dispatchable) for d in dispatchables):
700
+ raise TypeError("dispatchables must be instances of uarray.Dispatchable")
701
+
702
+ if len(kwargs) != 0:
703
+ raise TypeError(f"Received unexpected keyword arguments: {kwargs}")
704
+
705
+ backend = _uarray.determine_backend(domain, dispatchables, coerce)
706
+
707
+ return set_backend(backend, coerce=coerce, only=only)
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/_uarray/_uarray.cpython-312-x86_64-linux-gnu.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:db3ec45a5b6b13203ce8abdb9dc7530e1bc9fbfff394e651228b4a43a40c8e6c
3
+ size 178040
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/__init__.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ NumPy Array API compatibility library
3
+
4
+ This is a small wrapper around NumPy, CuPy, JAX, sparse and others that are
5
+ compatible with the Array API standard https://data-apis.org/array-api/latest/.
6
+ See also NEP 47 https://numpy.org/neps/nep-0047-array-api-standard.html.
7
+
8
+ Unlike array_api_strict, this is not a strict minimal implementation of the
9
+ Array API, but rather just an extension of the main NumPy namespace with
10
+ changes needed to be compliant with the Array API. See
11
+ https://numpy.org/doc/stable/reference/array_api.html for a full list of
12
+ changes. In particular, unlike array_api_strict, this package does not use a
13
+ separate Array object, but rather just uses numpy.ndarray directly.
14
+
15
+ Library authors using the Array API may wish to test against array_api_strict
16
+ to ensure they are not using functionality outside of the standard, but prefer
17
+ this implementation for the default when working with NumPy arrays.
18
+
19
+ """
20
+ __version__ = '1.12.0'
21
+
22
+ from .common import * # noqa: F401, F403
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (1.2 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/__pycache__/_internal.cpython-312.pyc ADDED
Binary file (2.42 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/_internal.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Internal helpers
3
+ """
4
+
5
+ from collections.abc import Callable
6
+ from functools import wraps
7
+ from inspect import signature
8
+ from types import ModuleType
9
+ from typing import TypeVar
10
+
11
+ _T = TypeVar("_T")
12
+
13
+
14
+ def get_xp(xp: ModuleType) -> Callable[[Callable[..., _T]], Callable[..., _T]]:
15
+ """
16
+ Decorator to automatically replace xp with the corresponding array module.
17
+
18
+ Use like
19
+
20
+ import numpy as np
21
+
22
+ @get_xp(np)
23
+ def func(x, /, xp, kwarg=None):
24
+ return xp.func(x, kwarg=kwarg)
25
+
26
+ Note that xp must be a keyword argument and come after all non-keyword
27
+ arguments.
28
+
29
+ """
30
+
31
+ def inner(f: Callable[..., _T], /) -> Callable[..., _T]:
32
+ @wraps(f)
33
+ def wrapped_f(*args: object, **kwargs: object) -> object:
34
+ return f(*args, xp=xp, **kwargs)
35
+
36
+ sig = signature(f)
37
+ new_sig = sig.replace(
38
+ parameters=[par for i, par in sig.parameters.items() if i != "xp"]
39
+ )
40
+
41
+ if wrapped_f.__doc__ is None:
42
+ wrapped_f.__doc__ = f"""\
43
+ Array API compatibility wrapper for {f.__name__}.
44
+
45
+ See the corresponding documentation in NumPy/CuPy and/or the array API
46
+ specification for more details.
47
+
48
+ """
49
+ wrapped_f.__signature__ = new_sig # pyright: ignore[reportAttributeAccessIssue]
50
+ return wrapped_f # pyright: ignore[reportReturnType]
51
+
52
+ return inner
53
+
54
+
55
+ __all__ = ["get_xp"]
56
+
57
+
58
+ def __dir__() -> list[str]:
59
+ return __all__
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/common/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ from ._helpers import * # noqa: F403
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/common/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (234 Bytes). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/common/__pycache__/_aliases.cpython-312.pyc ADDED
Binary file (22.1 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/common/__pycache__/_fft.cpython-312.pyc ADDED
Binary file (7.44 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/common/__pycache__/_helpers.cpython-312.pyc ADDED
Binary file (31.8 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/common/__pycache__/_linalg.cpython-312.pyc ADDED
Binary file (9.68 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/common/__pycache__/_typing.cpython-312.pyc ADDED
Binary file (5.99 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/common/_aliases.py ADDED
@@ -0,0 +1,727 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ These are functions that are just aliases of existing functions in NumPy.
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ import inspect
8
+ from typing import TYPE_CHECKING, Any, NamedTuple, Optional, Sequence, cast
9
+
10
+ from ._helpers import _check_device, array_namespace
11
+ from ._helpers import device as _get_device
12
+ from ._helpers import is_cupy_namespace as _is_cupy_namespace
13
+ from ._typing import Array, Device, DType, Namespace
14
+
15
+ if TYPE_CHECKING:
16
+ # TODO: import from typing (requires Python >=3.13)
17
+ from typing_extensions import TypeIs
18
+
19
+ # These functions are modified from the NumPy versions.
20
+
21
+ # Creation functions add the device keyword (which does nothing for NumPy and Dask)
22
+
23
+
24
+ def arange(
25
+ start: float,
26
+ /,
27
+ stop: float | None = None,
28
+ step: float = 1,
29
+ *,
30
+ xp: Namespace,
31
+ dtype: DType | None = None,
32
+ device: Device | None = None,
33
+ **kwargs: object,
34
+ ) -> Array:
35
+ _check_device(xp, device)
36
+ return xp.arange(start, stop=stop, step=step, dtype=dtype, **kwargs)
37
+
38
+
39
+ def empty(
40
+ shape: int | tuple[int, ...],
41
+ xp: Namespace,
42
+ *,
43
+ dtype: DType | None = None,
44
+ device: Device | None = None,
45
+ **kwargs: object,
46
+ ) -> Array:
47
+ _check_device(xp, device)
48
+ return xp.empty(shape, dtype=dtype, **kwargs)
49
+
50
+
51
+ def empty_like(
52
+ x: Array,
53
+ /,
54
+ xp: Namespace,
55
+ *,
56
+ dtype: DType | None = None,
57
+ device: Device | None = None,
58
+ **kwargs: object,
59
+ ) -> Array:
60
+ _check_device(xp, device)
61
+ return xp.empty_like(x, dtype=dtype, **kwargs)
62
+
63
+
64
+ def eye(
65
+ n_rows: int,
66
+ n_cols: int | None = None,
67
+ /,
68
+ *,
69
+ xp: Namespace,
70
+ k: int = 0,
71
+ dtype: DType | None = None,
72
+ device: Device | None = None,
73
+ **kwargs: object,
74
+ ) -> Array:
75
+ _check_device(xp, device)
76
+ return xp.eye(n_rows, M=n_cols, k=k, dtype=dtype, **kwargs)
77
+
78
+
79
+ def full(
80
+ shape: int | tuple[int, ...],
81
+ fill_value: complex,
82
+ xp: Namespace,
83
+ *,
84
+ dtype: DType | None = None,
85
+ device: Device | None = None,
86
+ **kwargs: object,
87
+ ) -> Array:
88
+ _check_device(xp, device)
89
+ return xp.full(shape, fill_value, dtype=dtype, **kwargs)
90
+
91
+
92
+ def full_like(
93
+ x: Array,
94
+ /,
95
+ fill_value: complex,
96
+ *,
97
+ xp: Namespace,
98
+ dtype: DType | None = None,
99
+ device: Device | None = None,
100
+ **kwargs: object,
101
+ ) -> Array:
102
+ _check_device(xp, device)
103
+ return xp.full_like(x, fill_value, dtype=dtype, **kwargs)
104
+
105
+
106
+ def linspace(
107
+ start: float,
108
+ stop: float,
109
+ /,
110
+ num: int,
111
+ *,
112
+ xp: Namespace,
113
+ dtype: DType | None = None,
114
+ device: Device | None = None,
115
+ endpoint: bool = True,
116
+ **kwargs: object,
117
+ ) -> Array:
118
+ _check_device(xp, device)
119
+ return xp.linspace(start, stop, num, dtype=dtype, endpoint=endpoint, **kwargs)
120
+
121
+
122
+ def ones(
123
+ shape: int | tuple[int, ...],
124
+ xp: Namespace,
125
+ *,
126
+ dtype: DType | None = None,
127
+ device: Device | None = None,
128
+ **kwargs: object,
129
+ ) -> Array:
130
+ _check_device(xp, device)
131
+ return xp.ones(shape, dtype=dtype, **kwargs)
132
+
133
+
134
+ def ones_like(
135
+ x: Array,
136
+ /,
137
+ xp: Namespace,
138
+ *,
139
+ dtype: DType | None = None,
140
+ device: Device | None = None,
141
+ **kwargs: object,
142
+ ) -> Array:
143
+ _check_device(xp, device)
144
+ return xp.ones_like(x, dtype=dtype, **kwargs)
145
+
146
+
147
+ def zeros(
148
+ shape: int | tuple[int, ...],
149
+ xp: Namespace,
150
+ *,
151
+ dtype: DType | None = None,
152
+ device: Device | None = None,
153
+ **kwargs: object,
154
+ ) -> Array:
155
+ _check_device(xp, device)
156
+ return xp.zeros(shape, dtype=dtype, **kwargs)
157
+
158
+
159
+ def zeros_like(
160
+ x: Array,
161
+ /,
162
+ xp: Namespace,
163
+ *,
164
+ dtype: DType | None = None,
165
+ device: Device | None = None,
166
+ **kwargs: object,
167
+ ) -> Array:
168
+ _check_device(xp, device)
169
+ return xp.zeros_like(x, dtype=dtype, **kwargs)
170
+
171
+
172
+ # np.unique() is split into four functions in the array API:
173
+ # unique_all, unique_counts, unique_inverse, and unique_values (this is done
174
+ # to remove polymorphic return types).
175
+
176
+ # The functions here return namedtuples (np.unique() returns a normal
177
+ # tuple).
178
+
179
+
180
+ # Note that these named tuples aren't actually part of the standard namespace,
181
+ # but I don't see any issue with exporting the names here regardless.
182
+ class UniqueAllResult(NamedTuple):
183
+ values: Array
184
+ indices: Array
185
+ inverse_indices: Array
186
+ counts: Array
187
+
188
+
189
+ class UniqueCountsResult(NamedTuple):
190
+ values: Array
191
+ counts: Array
192
+
193
+
194
+ class UniqueInverseResult(NamedTuple):
195
+ values: Array
196
+ inverse_indices: Array
197
+
198
+
199
+ def _unique_kwargs(xp: Namespace) -> dict[str, bool]:
200
+ # Older versions of NumPy and CuPy do not have equal_nan. Rather than
201
+ # trying to parse version numbers, just check if equal_nan is in the
202
+ # signature.
203
+ s = inspect.signature(xp.unique)
204
+ if "equal_nan" in s.parameters:
205
+ return {"equal_nan": False}
206
+ return {}
207
+
208
+
209
+ def unique_all(x: Array, /, xp: Namespace) -> UniqueAllResult:
210
+ kwargs = _unique_kwargs(xp)
211
+ values, indices, inverse_indices, counts = xp.unique(
212
+ x,
213
+ return_counts=True,
214
+ return_index=True,
215
+ return_inverse=True,
216
+ **kwargs,
217
+ )
218
+ # np.unique() flattens inverse indices, but they need to share x's shape
219
+ # See https://github.com/numpy/numpy/issues/20638
220
+ inverse_indices = inverse_indices.reshape(x.shape)
221
+ return UniqueAllResult(
222
+ values,
223
+ indices,
224
+ inverse_indices,
225
+ counts,
226
+ )
227
+
228
+
229
+ def unique_counts(x: Array, /, xp: Namespace) -> UniqueCountsResult:
230
+ kwargs = _unique_kwargs(xp)
231
+ res = xp.unique(
232
+ x, return_counts=True, return_index=False, return_inverse=False, **kwargs
233
+ )
234
+
235
+ return UniqueCountsResult(*res)
236
+
237
+
238
+ def unique_inverse(x: Array, /, xp: Namespace) -> UniqueInverseResult:
239
+ kwargs = _unique_kwargs(xp)
240
+ values, inverse_indices = xp.unique(
241
+ x,
242
+ return_counts=False,
243
+ return_index=False,
244
+ return_inverse=True,
245
+ **kwargs,
246
+ )
247
+ # xp.unique() flattens inverse indices, but they need to share x's shape
248
+ # See https://github.com/numpy/numpy/issues/20638
249
+ inverse_indices = inverse_indices.reshape(x.shape)
250
+ return UniqueInverseResult(values, inverse_indices)
251
+
252
+
253
+ def unique_values(x: Array, /, xp: Namespace) -> Array:
254
+ kwargs = _unique_kwargs(xp)
255
+ return xp.unique(
256
+ x,
257
+ return_counts=False,
258
+ return_index=False,
259
+ return_inverse=False,
260
+ **kwargs,
261
+ )
262
+
263
+
264
+ # These functions have different keyword argument names
265
+
266
+
267
+ def std(
268
+ x: Array,
269
+ /,
270
+ xp: Namespace,
271
+ *,
272
+ axis: int | tuple[int, ...] | None = None,
273
+ correction: float = 0.0, # correction instead of ddof
274
+ keepdims: bool = False,
275
+ **kwargs: object,
276
+ ) -> Array:
277
+ return xp.std(x, axis=axis, ddof=correction, keepdims=keepdims, **kwargs)
278
+
279
+
280
+ def var(
281
+ x: Array,
282
+ /,
283
+ xp: Namespace,
284
+ *,
285
+ axis: int | tuple[int, ...] | None = None,
286
+ correction: float = 0.0, # correction instead of ddof
287
+ keepdims: bool = False,
288
+ **kwargs: object,
289
+ ) -> Array:
290
+ return xp.var(x, axis=axis, ddof=correction, keepdims=keepdims, **kwargs)
291
+
292
+
293
+ # cumulative_sum is renamed from cumsum, and adds the include_initial keyword
294
+ # argument
295
+
296
+
297
+ def cumulative_sum(
298
+ x: Array,
299
+ /,
300
+ xp: Namespace,
301
+ *,
302
+ axis: int | None = None,
303
+ dtype: DType | None = None,
304
+ include_initial: bool = False,
305
+ **kwargs: object,
306
+ ) -> Array:
307
+ wrapped_xp = array_namespace(x)
308
+
309
+ # TODO: The standard is not clear about what should happen when x.ndim == 0.
310
+ if axis is None:
311
+ if x.ndim > 1:
312
+ raise ValueError(
313
+ "axis must be specified in cumulative_sum for more than one dimension"
314
+ )
315
+ axis = 0
316
+
317
+ res = xp.cumsum(x, axis=axis, dtype=dtype, **kwargs)
318
+
319
+ # np.cumsum does not support include_initial
320
+ if include_initial:
321
+ initial_shape = list(x.shape)
322
+ initial_shape[axis] = 1
323
+ res = xp.concatenate(
324
+ [
325
+ wrapped_xp.zeros(
326
+ shape=initial_shape, dtype=res.dtype, device=_get_device(res)
327
+ ),
328
+ res,
329
+ ],
330
+ axis=axis,
331
+ )
332
+ return res
333
+
334
+
335
+ def cumulative_prod(
336
+ x: Array,
337
+ /,
338
+ xp: Namespace,
339
+ *,
340
+ axis: int | None = None,
341
+ dtype: DType | None = None,
342
+ include_initial: bool = False,
343
+ **kwargs: object,
344
+ ) -> Array:
345
+ wrapped_xp = array_namespace(x)
346
+
347
+ if axis is None:
348
+ if x.ndim > 1:
349
+ raise ValueError(
350
+ "axis must be specified in cumulative_prod for more than one dimension"
351
+ )
352
+ axis = 0
353
+
354
+ res = xp.cumprod(x, axis=axis, dtype=dtype, **kwargs)
355
+
356
+ # np.cumprod does not support include_initial
357
+ if include_initial:
358
+ initial_shape = list(x.shape)
359
+ initial_shape[axis] = 1
360
+ res = xp.concatenate(
361
+ [
362
+ wrapped_xp.ones(
363
+ shape=initial_shape, dtype=res.dtype, device=_get_device(res)
364
+ ),
365
+ res,
366
+ ],
367
+ axis=axis,
368
+ )
369
+ return res
370
+
371
+
372
+ # The min and max argument names in clip are different and not optional in numpy, and type
373
+ # promotion behavior is different.
374
+ def clip(
375
+ x: Array,
376
+ /,
377
+ min: float | Array | None = None,
378
+ max: float | Array | None = None,
379
+ *,
380
+ xp: Namespace,
381
+ # TODO: np.clip has other ufunc kwargs
382
+ out: Array | None = None,
383
+ ) -> Array:
384
+ def _isscalar(a: object) -> TypeIs[int | float | None]:
385
+ return isinstance(a, (int, float, type(None)))
386
+
387
+ min_shape = () if _isscalar(min) else min.shape
388
+ max_shape = () if _isscalar(max) else max.shape
389
+
390
+ wrapped_xp = array_namespace(x)
391
+
392
+ result_shape = xp.broadcast_shapes(x.shape, min_shape, max_shape)
393
+
394
+ # np.clip does type promotion but the array API clip requires that the
395
+ # output have the same dtype as x. We do this instead of just downcasting
396
+ # the result of xp.clip() to handle some corner cases better (e.g.,
397
+ # avoiding uint64 -> float64 promotion).
398
+
399
+ # Note: cases where min or max overflow (integer) or round (float) in the
400
+ # wrong direction when downcasting to x.dtype are unspecified. This code
401
+ # just does whatever NumPy does when it downcasts in the assignment, but
402
+ # other behavior could be preferred, especially for integers. For example,
403
+ # this code produces:
404
+
405
+ # >>> clip(asarray(0, dtype=int8), asarray(128, dtype=int16), None)
406
+ # -128
407
+
408
+ # but an answer of 0 might be preferred. See
409
+ # https://github.com/numpy/numpy/issues/24976 for more discussion on this issue.
410
+
411
+ # At least handle the case of Python integers correctly (see
412
+ # https://github.com/numpy/numpy/pull/26892).
413
+ if wrapped_xp.isdtype(x.dtype, "integral"):
414
+ if type(min) is int and min <= wrapped_xp.iinfo(x.dtype).min:
415
+ min = None
416
+ if type(max) is int and max >= wrapped_xp.iinfo(x.dtype).max:
417
+ max = None
418
+
419
+ dev = _get_device(x)
420
+ if out is None:
421
+ out = wrapped_xp.empty(result_shape, dtype=x.dtype, device=dev)
422
+ assert out is not None # workaround for a type-narrowing issue in pyright
423
+ out[()] = x
424
+
425
+ if min is not None:
426
+ a = wrapped_xp.asarray(min, dtype=x.dtype, device=dev)
427
+ a = xp.broadcast_to(a, result_shape)
428
+ ia = (out < a) | xp.isnan(a)
429
+ out[ia] = a[ia]
430
+
431
+ if max is not None:
432
+ b = wrapped_xp.asarray(max, dtype=x.dtype, device=dev)
433
+ b = xp.broadcast_to(b, result_shape)
434
+ ib = (out > b) | xp.isnan(b)
435
+ out[ib] = b[ib]
436
+
437
+ # Return a scalar for 0-D
438
+ return out[()]
439
+
440
+
441
+ # Unlike transpose(), the axes argument to permute_dims() is required.
442
+ def permute_dims(x: Array, /, axes: tuple[int, ...], xp: Namespace) -> Array:
443
+ return xp.transpose(x, axes)
444
+
445
+
446
+ # np.reshape calls the keyword argument 'newshape' instead of 'shape'
447
+ def reshape(
448
+ x: Array,
449
+ /,
450
+ shape: tuple[int, ...],
451
+ xp: Namespace,
452
+ *,
453
+ copy: Optional[bool] = None,
454
+ **kwargs: object,
455
+ ) -> Array:
456
+ if copy is True:
457
+ x = x.copy()
458
+ elif copy is False:
459
+ y = x.view()
460
+ y.shape = shape
461
+ return y
462
+ return xp.reshape(x, shape, **kwargs)
463
+
464
+
465
+ # The descending keyword is new in sort and argsort, and 'kind' replaced with
466
+ # 'stable'
467
+ def argsort(
468
+ x: Array,
469
+ /,
470
+ xp: Namespace,
471
+ *,
472
+ axis: int = -1,
473
+ descending: bool = False,
474
+ stable: bool = True,
475
+ **kwargs: object,
476
+ ) -> Array:
477
+ # Note: this keyword argument is different, and the default is different.
478
+ # We set it in kwargs like this because numpy.sort uses kind='quicksort'
479
+ # as the default whereas cupy.sort uses kind=None.
480
+ if stable:
481
+ kwargs["kind"] = "stable"
482
+ if not descending:
483
+ res = xp.argsort(x, axis=axis, **kwargs)
484
+ else:
485
+ # As NumPy has no native descending sort, we imitate it here. Note that
486
+ # simply flipping the results of xp.argsort(x, ...) would not
487
+ # respect the relative order like it would in native descending sorts.
488
+ res = xp.flip(
489
+ xp.argsort(xp.flip(x, axis=axis), axis=axis, **kwargs),
490
+ axis=axis,
491
+ )
492
+ # Rely on flip()/argsort() to validate axis
493
+ normalised_axis = axis if axis >= 0 else x.ndim + axis
494
+ max_i = x.shape[normalised_axis] - 1
495
+ res = max_i - res
496
+ return res
497
+
498
+
499
+ def sort(
500
+ x: Array,
501
+ /,
502
+ xp: Namespace,
503
+ *,
504
+ axis: int = -1,
505
+ descending: bool = False,
506
+ stable: bool = True,
507
+ **kwargs: object,
508
+ ) -> Array:
509
+ # Note: this keyword argument is different, and the default is different.
510
+ # We set it in kwargs like this because numpy.sort uses kind='quicksort'
511
+ # as the default whereas cupy.sort uses kind=None.
512
+ if stable:
513
+ kwargs["kind"] = "stable"
514
+ res = xp.sort(x, axis=axis, **kwargs)
515
+ if descending:
516
+ res = xp.flip(res, axis=axis)
517
+ return res
518
+
519
+
520
+ # nonzero should error for zero-dimensional arrays
521
+ def nonzero(x: Array, /, xp: Namespace, **kwargs: object) -> tuple[Array, ...]:
522
+ if x.ndim == 0:
523
+ raise ValueError("nonzero() does not support zero-dimensional arrays")
524
+ return xp.nonzero(x, **kwargs)
525
+
526
+
527
+ # ceil, floor, and trunc return integers for integer inputs
528
+
529
+
530
+ def ceil(x: Array, /, xp: Namespace, **kwargs: object) -> Array:
531
+ if xp.issubdtype(x.dtype, xp.integer):
532
+ return x
533
+ return xp.ceil(x, **kwargs)
534
+
535
+
536
+ def floor(x: Array, /, xp: Namespace, **kwargs: object) -> Array:
537
+ if xp.issubdtype(x.dtype, xp.integer):
538
+ return x
539
+ return xp.floor(x, **kwargs)
540
+
541
+
542
+ def trunc(x: Array, /, xp: Namespace, **kwargs: object) -> Array:
543
+ if xp.issubdtype(x.dtype, xp.integer):
544
+ return x
545
+ return xp.trunc(x, **kwargs)
546
+
547
+
548
+ # linear algebra functions
549
+
550
+
551
+ def matmul(x1: Array, x2: Array, /, xp: Namespace, **kwargs: object) -> Array:
552
+ return xp.matmul(x1, x2, **kwargs)
553
+
554
+
555
+ # Unlike transpose, matrix_transpose only transposes the last two axes.
556
+ def matrix_transpose(x: Array, /, xp: Namespace) -> Array:
557
+ if x.ndim < 2:
558
+ raise ValueError("x must be at least 2-dimensional for matrix_transpose")
559
+ return xp.swapaxes(x, -1, -2)
560
+
561
+
562
+ def tensordot(
563
+ x1: Array,
564
+ x2: Array,
565
+ /,
566
+ xp: Namespace,
567
+ *,
568
+ axes: int | tuple[Sequence[int], Sequence[int]] = 2,
569
+ **kwargs: object,
570
+ ) -> Array:
571
+ return xp.tensordot(x1, x2, axes=axes, **kwargs)
572
+
573
+
574
+ def vecdot(x1: Array, x2: Array, /, xp: Namespace, *, axis: int = -1) -> Array:
575
+ if x1.shape[axis] != x2.shape[axis]:
576
+ raise ValueError("x1 and x2 must have the same size along the given axis")
577
+
578
+ if hasattr(xp, "broadcast_tensors"):
579
+ _broadcast = xp.broadcast_tensors
580
+ else:
581
+ _broadcast = xp.broadcast_arrays
582
+
583
+ x1_ = xp.moveaxis(x1, axis, -1)
584
+ x2_ = xp.moveaxis(x2, axis, -1)
585
+ x1_, x2_ = _broadcast(x1_, x2_)
586
+
587
+ res = xp.conj(x1_[..., None, :]) @ x2_[..., None]
588
+ return res[..., 0, 0]
589
+
590
+
591
+ # isdtype is a new function in the 2022.12 array API specification.
592
+
593
+
594
+ def isdtype(
595
+ dtype: DType,
596
+ kind: DType | str | tuple[DType | str, ...],
597
+ xp: Namespace,
598
+ *,
599
+ _tuple: bool = True, # Disallow nested tuples
600
+ ) -> bool:
601
+ """
602
+ Returns a boolean indicating whether a provided dtype is of a specified data type ``kind``.
603
+
604
+ Note that outside of this function, this compat library does not yet fully
605
+ support complex numbers.
606
+
607
+ See
608
+ https://data-apis.org/array-api/latest/API_specification/generated/array_api.isdtype.html
609
+ for more details
610
+ """
611
+ if isinstance(kind, tuple) and _tuple:
612
+ return any(
613
+ isdtype(dtype, k, xp, _tuple=False)
614
+ for k in cast("tuple[DType | str, ...]", kind)
615
+ )
616
+ elif isinstance(kind, str):
617
+ if kind == "bool":
618
+ return dtype == xp.bool_
619
+ elif kind == "signed integer":
620
+ return xp.issubdtype(dtype, xp.signedinteger)
621
+ elif kind == "unsigned integer":
622
+ return xp.issubdtype(dtype, xp.unsignedinteger)
623
+ elif kind == "integral":
624
+ return xp.issubdtype(dtype, xp.integer)
625
+ elif kind == "real floating":
626
+ return xp.issubdtype(dtype, xp.floating)
627
+ elif kind == "complex floating":
628
+ return xp.issubdtype(dtype, xp.complexfloating)
629
+ elif kind == "numeric":
630
+ return xp.issubdtype(dtype, xp.number)
631
+ else:
632
+ raise ValueError(f"Unrecognized data type kind: {kind!r}")
633
+ else:
634
+ # This will allow things that aren't required by the spec, like
635
+ # isdtype(np.float64, float) or isdtype(np.int64, 'l'). Should we be
636
+ # more strict here to match the type annotation? Note that the
637
+ # array_api_strict implementation will be very strict.
638
+ return dtype == kind
639
+
640
+
641
+ # unstack is a new function in the 2023.12 array API standard
642
+ def unstack(x: Array, /, xp: Namespace, *, axis: int = 0) -> tuple[Array, ...]:
643
+ if x.ndim == 0:
644
+ raise ValueError("Input array must be at least 1-d.")
645
+ return tuple(xp.moveaxis(x, axis, 0))
646
+
647
+
648
+ # numpy 1.26 does not use the standard definition for sign on complex numbers
649
+
650
+
651
+ def sign(x: Array, /, xp: Namespace, **kwargs: object) -> Array:
652
+ if isdtype(x.dtype, "complex floating", xp=xp):
653
+ out = (x / xp.abs(x, **kwargs))[...]
654
+ # sign(0) = 0 but the above formula would give nan
655
+ out[x == 0j] = 0j
656
+ else:
657
+ out = xp.sign(x, **kwargs)
658
+ # CuPy sign() does not propagate nans. See
659
+ # https://github.com/data-apis/array-api-compat/issues/136
660
+ if _is_cupy_namespace(xp) and isdtype(x.dtype, "real floating", xp=xp):
661
+ out[xp.isnan(x)] = xp.nan
662
+ return out[()]
663
+
664
+
665
+ def finfo(type_: DType | Array, /, xp: Namespace) -> Any:
666
+ # It is surprisingly difficult to recognize a dtype apart from an array.
667
+ # np.int64 is not the same as np.asarray(1).dtype!
668
+ try:
669
+ return xp.finfo(type_)
670
+ except (ValueError, TypeError):
671
+ return xp.finfo(type_.dtype)
672
+
673
+
674
+ def iinfo(type_: DType | Array, /, xp: Namespace) -> Any:
675
+ try:
676
+ return xp.iinfo(type_)
677
+ except (ValueError, TypeError):
678
+ return xp.iinfo(type_.dtype)
679
+
680
+
681
+ __all__ = [
682
+ "arange",
683
+ "empty",
684
+ "empty_like",
685
+ "eye",
686
+ "full",
687
+ "full_like",
688
+ "linspace",
689
+ "ones",
690
+ "ones_like",
691
+ "zeros",
692
+ "zeros_like",
693
+ "UniqueAllResult",
694
+ "UniqueCountsResult",
695
+ "UniqueInverseResult",
696
+ "unique_all",
697
+ "unique_counts",
698
+ "unique_inverse",
699
+ "unique_values",
700
+ "std",
701
+ "var",
702
+ "cumulative_sum",
703
+ "cumulative_prod",
704
+ "clip",
705
+ "permute_dims",
706
+ "reshape",
707
+ "argsort",
708
+ "sort",
709
+ "nonzero",
710
+ "ceil",
711
+ "floor",
712
+ "trunc",
713
+ "matmul",
714
+ "matrix_transpose",
715
+ "tensordot",
716
+ "vecdot",
717
+ "isdtype",
718
+ "unstack",
719
+ "sign",
720
+ "finfo",
721
+ "iinfo",
722
+ ]
723
+ _all_ignore = ["inspect", "array_namespace", "NamedTuple"]
724
+
725
+
726
+ def __dir__() -> list[str]:
727
+ return __all__
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/common/_fft.py ADDED
@@ -0,0 +1,213 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ from collections.abc import Sequence
4
+ from typing import Literal, TypeAlias
5
+
6
+ from ._typing import Array, Device, DType, Namespace
7
+
8
+ _Norm: TypeAlias = Literal["backward", "ortho", "forward"]
9
+
10
+ # Note: NumPy fft functions improperly upcast float32 and complex64 to
11
+ # complex128, which is why we require wrapping them all here.
12
+
13
+ def fft(
14
+ x: Array,
15
+ /,
16
+ xp: Namespace,
17
+ *,
18
+ n: int | None = None,
19
+ axis: int = -1,
20
+ norm: _Norm = "backward",
21
+ ) -> Array:
22
+ res = xp.fft.fft(x, n=n, axis=axis, norm=norm)
23
+ if x.dtype in [xp.float32, xp.complex64]:
24
+ return res.astype(xp.complex64)
25
+ return res
26
+
27
+ def ifft(
28
+ x: Array,
29
+ /,
30
+ xp: Namespace,
31
+ *,
32
+ n: int | None = None,
33
+ axis: int = -1,
34
+ norm: _Norm = "backward",
35
+ ) -> Array:
36
+ res = xp.fft.ifft(x, n=n, axis=axis, norm=norm)
37
+ if x.dtype in [xp.float32, xp.complex64]:
38
+ return res.astype(xp.complex64)
39
+ return res
40
+
41
+ def fftn(
42
+ x: Array,
43
+ /,
44
+ xp: Namespace,
45
+ *,
46
+ s: Sequence[int] | None = None,
47
+ axes: Sequence[int] | None = None,
48
+ norm: _Norm = "backward",
49
+ ) -> Array:
50
+ res = xp.fft.fftn(x, s=s, axes=axes, norm=norm)
51
+ if x.dtype in [xp.float32, xp.complex64]:
52
+ return res.astype(xp.complex64)
53
+ return res
54
+
55
+ def ifftn(
56
+ x: Array,
57
+ /,
58
+ xp: Namespace,
59
+ *,
60
+ s: Sequence[int] | None = None,
61
+ axes: Sequence[int] | None = None,
62
+ norm: _Norm = "backward",
63
+ ) -> Array:
64
+ res = xp.fft.ifftn(x, s=s, axes=axes, norm=norm)
65
+ if x.dtype in [xp.float32, xp.complex64]:
66
+ return res.astype(xp.complex64)
67
+ return res
68
+
69
+ def rfft(
70
+ x: Array,
71
+ /,
72
+ xp: Namespace,
73
+ *,
74
+ n: int | None = None,
75
+ axis: int = -1,
76
+ norm: _Norm = "backward",
77
+ ) -> Array:
78
+ res = xp.fft.rfft(x, n=n, axis=axis, norm=norm)
79
+ if x.dtype == xp.float32:
80
+ return res.astype(xp.complex64)
81
+ return res
82
+
83
+ def irfft(
84
+ x: Array,
85
+ /,
86
+ xp: Namespace,
87
+ *,
88
+ n: int | None = None,
89
+ axis: int = -1,
90
+ norm: _Norm = "backward",
91
+ ) -> Array:
92
+ res = xp.fft.irfft(x, n=n, axis=axis, norm=norm)
93
+ if x.dtype == xp.complex64:
94
+ return res.astype(xp.float32)
95
+ return res
96
+
97
+ def rfftn(
98
+ x: Array,
99
+ /,
100
+ xp: Namespace,
101
+ *,
102
+ s: Sequence[int] | None = None,
103
+ axes: Sequence[int] | None = None,
104
+ norm: _Norm = "backward",
105
+ ) -> Array:
106
+ res = xp.fft.rfftn(x, s=s, axes=axes, norm=norm)
107
+ if x.dtype == xp.float32:
108
+ return res.astype(xp.complex64)
109
+ return res
110
+
111
+ def irfftn(
112
+ x: Array,
113
+ /,
114
+ xp: Namespace,
115
+ *,
116
+ s: Sequence[int] | None = None,
117
+ axes: Sequence[int] | None = None,
118
+ norm: _Norm = "backward",
119
+ ) -> Array:
120
+ res = xp.fft.irfftn(x, s=s, axes=axes, norm=norm)
121
+ if x.dtype == xp.complex64:
122
+ return res.astype(xp.float32)
123
+ return res
124
+
125
+ def hfft(
126
+ x: Array,
127
+ /,
128
+ xp: Namespace,
129
+ *,
130
+ n: int | None = None,
131
+ axis: int = -1,
132
+ norm: _Norm = "backward",
133
+ ) -> Array:
134
+ res = xp.fft.hfft(x, n=n, axis=axis, norm=norm)
135
+ if x.dtype in [xp.float32, xp.complex64]:
136
+ return res.astype(xp.float32)
137
+ return res
138
+
139
+ def ihfft(
140
+ x: Array,
141
+ /,
142
+ xp: Namespace,
143
+ *,
144
+ n: int | None = None,
145
+ axis: int = -1,
146
+ norm: _Norm = "backward",
147
+ ) -> Array:
148
+ res = xp.fft.ihfft(x, n=n, axis=axis, norm=norm)
149
+ if x.dtype in [xp.float32, xp.complex64]:
150
+ return res.astype(xp.complex64)
151
+ return res
152
+
153
+ def fftfreq(
154
+ n: int,
155
+ /,
156
+ xp: Namespace,
157
+ *,
158
+ d: float = 1.0,
159
+ dtype: DType | None = None,
160
+ device: Device | None = None,
161
+ ) -> Array:
162
+ if device not in ["cpu", None]:
163
+ raise ValueError(f"Unsupported device {device!r}")
164
+ res = xp.fft.fftfreq(n, d=d)
165
+ if dtype is not None:
166
+ return res.astype(dtype)
167
+ return res
168
+
169
+ def rfftfreq(
170
+ n: int,
171
+ /,
172
+ xp: Namespace,
173
+ *,
174
+ d: float = 1.0,
175
+ dtype: DType | None = None,
176
+ device: Device | None = None,
177
+ ) -> Array:
178
+ if device not in ["cpu", None]:
179
+ raise ValueError(f"Unsupported device {device!r}")
180
+ res = xp.fft.rfftfreq(n, d=d)
181
+ if dtype is not None:
182
+ return res.astype(dtype)
183
+ return res
184
+
185
+ def fftshift(
186
+ x: Array, /, xp: Namespace, *, axes: int | Sequence[int] | None = None
187
+ ) -> Array:
188
+ return xp.fft.fftshift(x, axes=axes)
189
+
190
+ def ifftshift(
191
+ x: Array, /, xp: Namespace, *, axes: int | Sequence[int] | None = None
192
+ ) -> Array:
193
+ return xp.fft.ifftshift(x, axes=axes)
194
+
195
+ __all__ = [
196
+ "fft",
197
+ "ifft",
198
+ "fftn",
199
+ "ifftn",
200
+ "rfft",
201
+ "irfft",
202
+ "rfftn",
203
+ "irfftn",
204
+ "hfft",
205
+ "ihfft",
206
+ "fftfreq",
207
+ "rfftfreq",
208
+ "fftshift",
209
+ "ifftshift",
210
+ ]
211
+
212
+ def __dir__() -> list[str]:
213
+ return __all__
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/common/_helpers.py ADDED
@@ -0,0 +1,1058 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Various helper functions which are not part of the spec.
3
+
4
+ Functions which start with an underscore are for internal use only but helpers
5
+ that are in __all__ are intended as additional helper functions for use by end
6
+ users of the compat library.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import inspect
12
+ import math
13
+ import sys
14
+ import warnings
15
+ from collections.abc import Collection, Hashable
16
+ from functools import lru_cache
17
+ from typing import (
18
+ TYPE_CHECKING,
19
+ Any,
20
+ Final,
21
+ Literal,
22
+ SupportsIndex,
23
+ TypeAlias,
24
+ TypeGuard,
25
+ TypeVar,
26
+ cast,
27
+ overload,
28
+ )
29
+
30
+ from ._typing import Array, Device, HasShape, Namespace, SupportsArrayNamespace
31
+
32
+ if TYPE_CHECKING:
33
+
34
+ import dask.array as da
35
+ import jax
36
+ import ndonnx as ndx
37
+ import numpy as np
38
+ import numpy.typing as npt
39
+ import sparse # pyright: ignore[reportMissingTypeStubs]
40
+ import torch
41
+
42
+ # TODO: import from typing (requires Python >=3.13)
43
+ from typing_extensions import TypeIs, TypeVar
44
+
45
+ _SizeT = TypeVar("_SizeT", bound = int | None)
46
+
47
+ _ZeroGradientArray: TypeAlias = npt.NDArray[np.void]
48
+ _CupyArray: TypeAlias = Any # cupy has no py.typed
49
+
50
+ _ArrayApiObj: TypeAlias = (
51
+ npt.NDArray[Any]
52
+ | da.Array
53
+ | jax.Array
54
+ | ndx.Array
55
+ | sparse.SparseArray
56
+ | torch.Tensor
57
+ | SupportsArrayNamespace[Any]
58
+ | _CupyArray
59
+ )
60
+
61
+ _API_VERSIONS_OLD: Final = frozenset({"2021.12", "2022.12", "2023.12"})
62
+ _API_VERSIONS: Final = _API_VERSIONS_OLD | frozenset({"2024.12"})
63
+
64
+
65
+ @lru_cache(100)
66
+ def _issubclass_fast(cls: type, modname: str, clsname: str) -> bool:
67
+ try:
68
+ mod = sys.modules[modname]
69
+ except KeyError:
70
+ return False
71
+ parent_cls = getattr(mod, clsname)
72
+ return issubclass(cls, parent_cls)
73
+
74
+
75
+ def _is_jax_zero_gradient_array(x: object) -> TypeGuard[_ZeroGradientArray]:
76
+ """Return True if `x` is a zero-gradient array.
77
+
78
+ These arrays are a design quirk of Jax that may one day be removed.
79
+ See https://github.com/google/jax/issues/20620.
80
+ """
81
+ # Fast exit
82
+ try:
83
+ dtype = x.dtype # type: ignore[attr-defined]
84
+ except AttributeError:
85
+ return False
86
+ cls = cast(Hashable, type(dtype))
87
+ if not _issubclass_fast(cls, "numpy.dtypes", "VoidDType"):
88
+ return False
89
+
90
+ if "jax" not in sys.modules:
91
+ return False
92
+
93
+ import jax
94
+ # jax.float0 is a np.dtype([('float0', 'V')])
95
+ return dtype == jax.float0
96
+
97
+
98
+ def is_numpy_array(x: object) -> TypeGuard[npt.NDArray[Any]]:
99
+ """
100
+ Return True if `x` is a NumPy array.
101
+
102
+ This function does not import NumPy if it has not already been imported
103
+ and is therefore cheap to use.
104
+
105
+ This also returns True for `ndarray` subclasses and NumPy scalar objects.
106
+
107
+ See Also
108
+ --------
109
+
110
+ array_namespace
111
+ is_array_api_obj
112
+ is_cupy_array
113
+ is_torch_array
114
+ is_ndonnx_array
115
+ is_dask_array
116
+ is_jax_array
117
+ is_pydata_sparse_array
118
+ """
119
+ # TODO: Should we reject ndarray subclasses?
120
+ cls = cast(Hashable, type(x))
121
+ return (
122
+ _issubclass_fast(cls, "numpy", "ndarray")
123
+ or _issubclass_fast(cls, "numpy", "generic")
124
+ ) and not _is_jax_zero_gradient_array(x)
125
+
126
+
127
+ def is_cupy_array(x: object) -> bool:
128
+ """
129
+ Return True if `x` is a CuPy array.
130
+
131
+ This function does not import CuPy if it has not already been imported
132
+ and is therefore cheap to use.
133
+
134
+ This also returns True for `cupy.ndarray` subclasses and CuPy scalar objects.
135
+
136
+ See Also
137
+ --------
138
+
139
+ array_namespace
140
+ is_array_api_obj
141
+ is_numpy_array
142
+ is_torch_array
143
+ is_ndonnx_array
144
+ is_dask_array
145
+ is_jax_array
146
+ is_pydata_sparse_array
147
+ """
148
+ cls = cast(Hashable, type(x))
149
+ return _issubclass_fast(cls, "cupy", "ndarray")
150
+
151
+
152
+ def is_torch_array(x: object) -> TypeIs[torch.Tensor]:
153
+ """
154
+ Return True if `x` is a PyTorch tensor.
155
+
156
+ This function does not import PyTorch if it has not already been imported
157
+ and is therefore cheap to use.
158
+
159
+ See Also
160
+ --------
161
+
162
+ array_namespace
163
+ is_array_api_obj
164
+ is_numpy_array
165
+ is_cupy_array
166
+ is_dask_array
167
+ is_jax_array
168
+ is_pydata_sparse_array
169
+ """
170
+ cls = cast(Hashable, type(x))
171
+ return _issubclass_fast(cls, "torch", "Tensor")
172
+
173
+
174
+ def is_ndonnx_array(x: object) -> TypeIs[ndx.Array]:
175
+ """
176
+ Return True if `x` is a ndonnx Array.
177
+
178
+ This function does not import ndonnx if it has not already been imported
179
+ and is therefore cheap to use.
180
+
181
+ See Also
182
+ --------
183
+
184
+ array_namespace
185
+ is_array_api_obj
186
+ is_numpy_array
187
+ is_cupy_array
188
+ is_ndonnx_array
189
+ is_dask_array
190
+ is_jax_array
191
+ is_pydata_sparse_array
192
+ """
193
+ cls = cast(Hashable, type(x))
194
+ return _issubclass_fast(cls, "ndonnx", "Array")
195
+
196
+
197
+ def is_dask_array(x: object) -> TypeIs[da.Array]:
198
+ """
199
+ Return True if `x` is a dask.array Array.
200
+
201
+ This function does not import dask if it has not already been imported
202
+ and is therefore cheap to use.
203
+
204
+ See Also
205
+ --------
206
+
207
+ array_namespace
208
+ is_array_api_obj
209
+ is_numpy_array
210
+ is_cupy_array
211
+ is_torch_array
212
+ is_ndonnx_array
213
+ is_jax_array
214
+ is_pydata_sparse_array
215
+ """
216
+ cls = cast(Hashable, type(x))
217
+ return _issubclass_fast(cls, "dask.array", "Array")
218
+
219
+
220
+ def is_jax_array(x: object) -> TypeIs[jax.Array]:
221
+ """
222
+ Return True if `x` is a JAX array.
223
+
224
+ This function does not import JAX if it has not already been imported
225
+ and is therefore cheap to use.
226
+
227
+
228
+ See Also
229
+ --------
230
+
231
+ array_namespace
232
+ is_array_api_obj
233
+ is_numpy_array
234
+ is_cupy_array
235
+ is_torch_array
236
+ is_ndonnx_array
237
+ is_dask_array
238
+ is_pydata_sparse_array
239
+ """
240
+ cls = cast(Hashable, type(x))
241
+ return _issubclass_fast(cls, "jax", "Array") or _is_jax_zero_gradient_array(x)
242
+
243
+
244
+ def is_pydata_sparse_array(x: object) -> TypeIs[sparse.SparseArray]:
245
+ """
246
+ Return True if `x` is an array from the `sparse` package.
247
+
248
+ This function does not import `sparse` if it has not already been imported
249
+ and is therefore cheap to use.
250
+
251
+
252
+ See Also
253
+ --------
254
+
255
+ array_namespace
256
+ is_array_api_obj
257
+ is_numpy_array
258
+ is_cupy_array
259
+ is_torch_array
260
+ is_ndonnx_array
261
+ is_dask_array
262
+ is_jax_array
263
+ """
264
+ # TODO: Account for other backends.
265
+ cls = cast(Hashable, type(x))
266
+ return _issubclass_fast(cls, "sparse", "SparseArray")
267
+
268
+
269
+ def is_array_api_obj(x: object) -> TypeIs[_ArrayApiObj]: # pyright: ignore[reportUnknownParameterType]
270
+ """
271
+ Return True if `x` is an array API compatible array object.
272
+
273
+ See Also
274
+ --------
275
+
276
+ array_namespace
277
+ is_numpy_array
278
+ is_cupy_array
279
+ is_torch_array
280
+ is_ndonnx_array
281
+ is_dask_array
282
+ is_jax_array
283
+ """
284
+ return (
285
+ hasattr(x, '__array_namespace__')
286
+ or _is_array_api_cls(cast(Hashable, type(x)))
287
+ )
288
+
289
+
290
+ @lru_cache(100)
291
+ def _is_array_api_cls(cls: type) -> bool:
292
+ return (
293
+ # TODO: drop support for numpy<2 which didn't have __array_namespace__
294
+ _issubclass_fast(cls, "numpy", "ndarray")
295
+ or _issubclass_fast(cls, "numpy", "generic")
296
+ or _issubclass_fast(cls, "cupy", "ndarray")
297
+ or _issubclass_fast(cls, "torch", "Tensor")
298
+ or _issubclass_fast(cls, "dask.array", "Array")
299
+ or _issubclass_fast(cls, "sparse", "SparseArray")
300
+ # TODO: drop support for jax<0.4.32 which didn't have __array_namespace__
301
+ or _issubclass_fast(cls, "jax", "Array")
302
+ )
303
+
304
+
305
+ def _compat_module_name() -> str:
306
+ assert __name__.endswith(".common._helpers")
307
+ return __name__.removesuffix(".common._helpers")
308
+
309
+
310
+ @lru_cache(100)
311
+ def is_numpy_namespace(xp: Namespace) -> bool:
312
+ """
313
+ Returns True if `xp` is a NumPy namespace.
314
+
315
+ This includes both NumPy itself and the version wrapped by array-api-compat.
316
+
317
+ See Also
318
+ --------
319
+
320
+ array_namespace
321
+ is_cupy_namespace
322
+ is_torch_namespace
323
+ is_ndonnx_namespace
324
+ is_dask_namespace
325
+ is_jax_namespace
326
+ is_pydata_sparse_namespace
327
+ is_array_api_strict_namespace
328
+ """
329
+ return xp.__name__ in {"numpy", _compat_module_name() + ".numpy"}
330
+
331
+
332
+ @lru_cache(100)
333
+ def is_cupy_namespace(xp: Namespace) -> bool:
334
+ """
335
+ Returns True if `xp` is a CuPy namespace.
336
+
337
+ This includes both CuPy itself and the version wrapped by array-api-compat.
338
+
339
+ See Also
340
+ --------
341
+
342
+ array_namespace
343
+ is_numpy_namespace
344
+ is_torch_namespace
345
+ is_ndonnx_namespace
346
+ is_dask_namespace
347
+ is_jax_namespace
348
+ is_pydata_sparse_namespace
349
+ is_array_api_strict_namespace
350
+ """
351
+ return xp.__name__ in {"cupy", _compat_module_name() + ".cupy"}
352
+
353
+
354
+ @lru_cache(100)
355
+ def is_torch_namespace(xp: Namespace) -> bool:
356
+ """
357
+ Returns True if `xp` is a PyTorch namespace.
358
+
359
+ This includes both PyTorch itself and the version wrapped by array-api-compat.
360
+
361
+ See Also
362
+ --------
363
+
364
+ array_namespace
365
+ is_numpy_namespace
366
+ is_cupy_namespace
367
+ is_ndonnx_namespace
368
+ is_dask_namespace
369
+ is_jax_namespace
370
+ is_pydata_sparse_namespace
371
+ is_array_api_strict_namespace
372
+ """
373
+ return xp.__name__ in {"torch", _compat_module_name() + ".torch"}
374
+
375
+
376
+ def is_ndonnx_namespace(xp: Namespace) -> bool:
377
+ """
378
+ Returns True if `xp` is an NDONNX namespace.
379
+
380
+ See Also
381
+ --------
382
+
383
+ array_namespace
384
+ is_numpy_namespace
385
+ is_cupy_namespace
386
+ is_torch_namespace
387
+ is_dask_namespace
388
+ is_jax_namespace
389
+ is_pydata_sparse_namespace
390
+ is_array_api_strict_namespace
391
+ """
392
+ return xp.__name__ == "ndonnx"
393
+
394
+
395
+ @lru_cache(100)
396
+ def is_dask_namespace(xp: Namespace) -> bool:
397
+ """
398
+ Returns True if `xp` is a Dask namespace.
399
+
400
+ This includes both ``dask.array`` itself and the version wrapped by array-api-compat.
401
+
402
+ See Also
403
+ --------
404
+
405
+ array_namespace
406
+ is_numpy_namespace
407
+ is_cupy_namespace
408
+ is_torch_namespace
409
+ is_ndonnx_namespace
410
+ is_jax_namespace
411
+ is_pydata_sparse_namespace
412
+ is_array_api_strict_namespace
413
+ """
414
+ return xp.__name__ in {"dask.array", _compat_module_name() + ".dask.array"}
415
+
416
+
417
+ def is_jax_namespace(xp: Namespace) -> bool:
418
+ """
419
+ Returns True if `xp` is a JAX namespace.
420
+
421
+ This includes ``jax.numpy`` and ``jax.experimental.array_api`` which existed in
422
+ older versions of JAX.
423
+
424
+ See Also
425
+ --------
426
+
427
+ array_namespace
428
+ is_numpy_namespace
429
+ is_cupy_namespace
430
+ is_torch_namespace
431
+ is_ndonnx_namespace
432
+ is_dask_namespace
433
+ is_pydata_sparse_namespace
434
+ is_array_api_strict_namespace
435
+ """
436
+ return xp.__name__ in {"jax.numpy", "jax.experimental.array_api"}
437
+
438
+
439
+ def is_pydata_sparse_namespace(xp: Namespace) -> bool:
440
+ """
441
+ Returns True if `xp` is a pydata/sparse namespace.
442
+
443
+ See Also
444
+ --------
445
+
446
+ array_namespace
447
+ is_numpy_namespace
448
+ is_cupy_namespace
449
+ is_torch_namespace
450
+ is_ndonnx_namespace
451
+ is_dask_namespace
452
+ is_jax_namespace
453
+ is_array_api_strict_namespace
454
+ """
455
+ return xp.__name__ == "sparse"
456
+
457
+
458
+ def is_array_api_strict_namespace(xp: Namespace) -> bool:
459
+ """
460
+ Returns True if `xp` is an array-api-strict namespace.
461
+
462
+ See Also
463
+ --------
464
+
465
+ array_namespace
466
+ is_numpy_namespace
467
+ is_cupy_namespace
468
+ is_torch_namespace
469
+ is_ndonnx_namespace
470
+ is_dask_namespace
471
+ is_jax_namespace
472
+ is_pydata_sparse_namespace
473
+ """
474
+ return xp.__name__ == "array_api_strict"
475
+
476
+
477
+ def _check_api_version(api_version: str | None) -> None:
478
+ if api_version in _API_VERSIONS_OLD:
479
+ warnings.warn(
480
+ f"The {api_version} version of the array API specification was requested but the returned namespace is actually version 2024.12"
481
+ )
482
+ elif api_version is not None and api_version not in _API_VERSIONS:
483
+ raise ValueError(
484
+ "Only the 2024.12 version of the array API specification is currently supported"
485
+ )
486
+
487
+
488
+ def array_namespace(
489
+ *xs: Array | complex | None,
490
+ api_version: str | None = None,
491
+ use_compat: bool | None = None,
492
+ ) -> Namespace:
493
+ """
494
+ Get the array API compatible namespace for the arrays `xs`.
495
+
496
+ Parameters
497
+ ----------
498
+ xs: arrays
499
+ one or more arrays. xs can also be Python scalars (bool, int, float,
500
+ complex, or None), which are ignored.
501
+
502
+ api_version: str
503
+ The newest version of the spec that you need support for (currently
504
+ the compat library wrapped APIs support v2024.12).
505
+
506
+ use_compat: bool or None
507
+ If None (the default), the native namespace will be returned if it is
508
+ already array API compatible, otherwise a compat wrapper is used. If
509
+ True, the compat library wrapped library will be returned. If False,
510
+ the native library namespace is returned.
511
+
512
+ Returns
513
+ -------
514
+
515
+ out: namespace
516
+ The array API compatible namespace corresponding to the arrays in `xs`.
517
+
518
+ Raises
519
+ ------
520
+ TypeError
521
+ If `xs` contains arrays from different array libraries or contains a
522
+ non-array.
523
+
524
+
525
+ Typical usage is to pass the arguments of a function to
526
+ `array_namespace()` at the top of a function to get the corresponding
527
+ array API namespace:
528
+
529
+ .. code:: python
530
+
531
+ def your_function(x, y):
532
+ xp = array_api_compat.array_namespace(x, y)
533
+ # Now use xp as the array library namespace
534
+ return xp.mean(x, axis=0) + 2*xp.std(y, axis=0)
535
+
536
+
537
+ Wrapped array namespaces can also be imported directly. For example,
538
+ `array_namespace(np.array(...))` will return `array_api_compat.numpy`.
539
+ This function will also work for any array library not wrapped by
540
+ array-api-compat if it explicitly defines `__array_namespace__
541
+ <https://data-apis.org/array-api/latest/API_specification/generated/array_api.array.__array_namespace__.html>`__
542
+ (the wrapped namespace is always preferred if it exists).
543
+
544
+ See Also
545
+ --------
546
+
547
+ is_array_api_obj
548
+ is_numpy_array
549
+ is_cupy_array
550
+ is_torch_array
551
+ is_dask_array
552
+ is_jax_array
553
+ is_pydata_sparse_array
554
+
555
+ """
556
+ if use_compat not in [None, True, False]:
557
+ raise ValueError("use_compat must be None, True, or False")
558
+
559
+ _use_compat = use_compat in [None, True]
560
+
561
+ namespaces: set[Namespace] = set()
562
+ for x in xs:
563
+ if is_numpy_array(x):
564
+ import numpy as np
565
+
566
+ from .. import numpy as numpy_namespace
567
+
568
+ if use_compat is True:
569
+ _check_api_version(api_version)
570
+ namespaces.add(numpy_namespace)
571
+ elif use_compat is False:
572
+ namespaces.add(np)
573
+ else:
574
+ # numpy 2.0+ have __array_namespace__, however, they are not yet fully array API
575
+ # compatible.
576
+ namespaces.add(numpy_namespace)
577
+ elif is_cupy_array(x):
578
+ if _use_compat:
579
+ _check_api_version(api_version)
580
+ from .. import cupy as cupy_namespace
581
+
582
+ namespaces.add(cupy_namespace)
583
+ else:
584
+ import cupy as cp # pyright: ignore[reportMissingTypeStubs]
585
+
586
+ namespaces.add(cp)
587
+ elif is_torch_array(x):
588
+ if _use_compat:
589
+ _check_api_version(api_version)
590
+ from .. import torch as torch_namespace
591
+
592
+ namespaces.add(torch_namespace)
593
+ else:
594
+ import torch
595
+
596
+ namespaces.add(torch)
597
+ elif is_dask_array(x):
598
+ if _use_compat:
599
+ _check_api_version(api_version)
600
+ from ..dask import array as dask_namespace
601
+
602
+ namespaces.add(dask_namespace)
603
+ else:
604
+ import dask.array as da
605
+
606
+ namespaces.add(da)
607
+ elif is_jax_array(x):
608
+ if use_compat is True:
609
+ _check_api_version(api_version)
610
+ raise ValueError("JAX does not have an array-api-compat wrapper")
611
+ elif use_compat is False:
612
+ import jax.numpy as jnp
613
+ else:
614
+ # JAX v0.4.32 and newer implements the array API directly in jax.numpy.
615
+ # For older JAX versions, it is available via jax.experimental.array_api.
616
+ import jax.numpy
617
+
618
+ if hasattr(jax.numpy, "__array_api_version__"):
619
+ jnp = jax.numpy
620
+ else:
621
+ import jax.experimental.array_api as jnp # pyright: ignore[reportMissingImports]
622
+ namespaces.add(jnp)
623
+ elif is_pydata_sparse_array(x):
624
+ if use_compat is True:
625
+ _check_api_version(api_version)
626
+ raise ValueError("`sparse` does not have an array-api-compat wrapper")
627
+ else:
628
+ import sparse # pyright: ignore[reportMissingTypeStubs]
629
+ # `sparse` is already an array namespace. We do not have a wrapper
630
+ # submodule for it.
631
+ namespaces.add(sparse)
632
+ elif hasattr(x, "__array_namespace__"):
633
+ if use_compat is True:
634
+ raise ValueError(
635
+ "The given array does not have an array-api-compat wrapper"
636
+ )
637
+ x = cast("SupportsArrayNamespace[Any]", x)
638
+ namespaces.add(x.__array_namespace__(api_version=api_version))
639
+ elif isinstance(x, (bool, int, float, complex, type(None))):
640
+ continue
641
+ else:
642
+ # TODO: Support Python scalars?
643
+ raise TypeError(f"{type(x).__name__} is not a supported array type")
644
+
645
+ if not namespaces:
646
+ raise TypeError("Unrecognized array input")
647
+
648
+ if len(namespaces) != 1:
649
+ raise TypeError(f"Multiple namespaces for array inputs: {namespaces}")
650
+
651
+ (xp,) = namespaces
652
+
653
+ return xp
654
+
655
+
656
+ # backwards compatibility alias
657
+ get_namespace = array_namespace
658
+
659
+
660
+ def _check_device(bare_xp: Namespace, device: Device) -> None: # pyright: ignore[reportUnusedFunction]
661
+ """
662
+ Validate dummy device on device-less array backends.
663
+
664
+ Notes
665
+ -----
666
+ This function is also invoked by CuPy, which does have multiple devices
667
+ if there are multiple GPUs available.
668
+ However, CuPy multi-device support is currently impossible
669
+ without using the global device or a context manager:
670
+
671
+ https://github.com/data-apis/array-api-compat/pull/293
672
+ """
673
+ if bare_xp is sys.modules.get("numpy"):
674
+ if device not in ("cpu", None):
675
+ raise ValueError(f"Unsupported device for NumPy: {device!r}")
676
+
677
+ elif bare_xp is sys.modules.get("dask.array"):
678
+ if device not in ("cpu", _DASK_DEVICE, None):
679
+ raise ValueError(f"Unsupported device for Dask: {device!r}")
680
+
681
+
682
+ # Placeholder object to represent the dask device
683
+ # when the array backend is not the CPU.
684
+ # (since it is not easy to tell which device a dask array is on)
685
+ class _dask_device:
686
+ def __repr__(self) -> Literal["DASK_DEVICE"]:
687
+ return "DASK_DEVICE"
688
+
689
+
690
+ _DASK_DEVICE = _dask_device()
691
+
692
+
693
+ # device() is not on numpy.ndarray or dask.array and to_device() is not on numpy.ndarray
694
+ # or cupy.ndarray. They are not included in array objects of this library
695
+ # because this library just reuses the respective ndarray classes without
696
+ # wrapping or subclassing them. These helper functions can be used instead of
697
+ # the wrapper functions for libraries that need to support both NumPy/CuPy and
698
+ # other libraries that use devices.
699
+ def device(x: _ArrayApiObj, /) -> Device:
700
+ """
701
+ Hardware device the array data resides on.
702
+
703
+ This is equivalent to `x.device` according to the `standard
704
+ <https://data-apis.org/array-api/latest/API_specification/generated/array_api.array.device.html>`__.
705
+ This helper is included because some array libraries either do not have
706
+ the `device` attribute or include it with an incompatible API.
707
+
708
+ Parameters
709
+ ----------
710
+ x: array
711
+ array instance from an array API compatible library.
712
+
713
+ Returns
714
+ -------
715
+ out: device
716
+ a ``device`` object (see the `Device Support <https://data-apis.org/array-api/latest/design_topics/device_support.html>`__
717
+ section of the array API specification).
718
+
719
+ Notes
720
+ -----
721
+
722
+ For NumPy the device is always `"cpu"`. For Dask, the device is always a
723
+ special `DASK_DEVICE` object.
724
+
725
+ See Also
726
+ --------
727
+
728
+ to_device : Move array data to a different device.
729
+
730
+ """
731
+ if is_numpy_array(x):
732
+ return "cpu"
733
+ elif is_dask_array(x):
734
+ # Peek at the metadata of the Dask array to determine type
735
+ if is_numpy_array(x._meta): # pyright: ignore
736
+ # Must be on CPU since backed by numpy
737
+ return "cpu"
738
+ return _DASK_DEVICE
739
+ elif is_jax_array(x):
740
+ # FIXME Jitted JAX arrays do not have a device attribute
741
+ # https://github.com/jax-ml/jax/issues/26000
742
+ # Return None in this case. Note that this workaround breaks
743
+ # the standard and will result in new arrays being created on the
744
+ # default device instead of the same device as the input array(s).
745
+ x_device = getattr(x, "device", None)
746
+ # Older JAX releases had .device() as a method, which has been replaced
747
+ # with a property in accordance with the standard.
748
+ if inspect.ismethod(x_device):
749
+ return x_device()
750
+ else:
751
+ return x_device
752
+ elif is_pydata_sparse_array(x):
753
+ # `sparse` will gain `.device`, so check for this first.
754
+ x_device = getattr(x, "device", None)
755
+ if x_device is not None:
756
+ return x_device
757
+ # Everything but DOK has this attr.
758
+ try:
759
+ inner = x.data # pyright: ignore
760
+ except AttributeError:
761
+ return "cpu"
762
+ # Return the device of the constituent array
763
+ return device(inner) # pyright: ignore
764
+ return x.device # pyright: ignore
765
+
766
+
767
+ # Prevent shadowing, used below
768
+ _device = device
769
+
770
+
771
+ # Based on cupy.array_api.Array.to_device
772
+ def _cupy_to_device(
773
+ x: _CupyArray,
774
+ device: Device,
775
+ /,
776
+ stream: int | Any | None = None,
777
+ ) -> _CupyArray:
778
+ import cupy as cp
779
+
780
+ if device == "cpu":
781
+ # allowing us to use `to_device(x, "cpu")`
782
+ # is useful for portable test swapping between
783
+ # host and device backends
784
+ return x.get()
785
+ if not isinstance(device, cp.cuda.Device):
786
+ raise TypeError(f"Unsupported device type {device!r}")
787
+
788
+ if stream is None:
789
+ with device:
790
+ return cp.asarray(x)
791
+
792
+ # stream can be an int as specified in __dlpack__, or a CuPy stream
793
+ if isinstance(stream, int):
794
+ stream = cp.cuda.ExternalStream(stream)
795
+ elif not isinstance(stream, cp.cuda.Stream):
796
+ raise TypeError(f"Unsupported stream type {stream!r}")
797
+
798
+ with device, stream:
799
+ return cp.asarray(x)
800
+
801
+
802
+ def _torch_to_device(
803
+ x: torch.Tensor,
804
+ device: torch.device | str | int,
805
+ /,
806
+ stream: None = None,
807
+ ) -> torch.Tensor:
808
+ if stream is not None:
809
+ raise NotImplementedError
810
+ return x.to(device)
811
+
812
+
813
+ def to_device(x: Array, device: Device, /, *, stream: int | Any | None = None) -> Array:
814
+ """
815
+ Copy the array from the device on which it currently resides to the specified ``device``.
816
+
817
+ This is equivalent to `x.to_device(device, stream=stream)` according to
818
+ the `standard
819
+ <https://data-apis.org/array-api/latest/API_specification/generated/array_api.array.to_device.html>`__.
820
+ This helper is included because some array libraries do not have the
821
+ `to_device` method.
822
+
823
+ Parameters
824
+ ----------
825
+
826
+ x: array
827
+ array instance from an array API compatible library.
828
+
829
+ device: device
830
+ a ``device`` object (see the `Device Support <https://data-apis.org/array-api/latest/design_topics/device_support.html>`__
831
+ section of the array API specification).
832
+
833
+ stream: int | Any | None
834
+ stream object to use during copy. In addition to the types supported
835
+ in ``array.__dlpack__``, implementations may choose to support any
836
+ library-specific stream object with the caveat that any code using
837
+ such an object would not be portable.
838
+
839
+ Returns
840
+ -------
841
+
842
+ out: array
843
+ an array with the same data and data type as ``x`` and located on the
844
+ specified ``device``.
845
+
846
+ Notes
847
+ -----
848
+
849
+ For NumPy, this function effectively does nothing since the only supported
850
+ device is the CPU. For CuPy, this method supports CuPy CUDA
851
+ :external+cupy:class:`Device <cupy.cuda.Device>` and
852
+ :external+cupy:class:`Stream <cupy.cuda.Stream>` objects. For PyTorch,
853
+ this is the same as :external+torch:meth:`x.to(device) <torch.Tensor.to>`
854
+ (the ``stream`` argument is not supported in PyTorch).
855
+
856
+ See Also
857
+ --------
858
+
859
+ device : Hardware device the array data resides on.
860
+
861
+ """
862
+ if is_numpy_array(x):
863
+ if stream is not None:
864
+ raise ValueError("The stream argument to to_device() is not supported")
865
+ if device == "cpu":
866
+ return x
867
+ raise ValueError(f"Unsupported device {device!r}")
868
+ elif is_cupy_array(x):
869
+ # cupy does not yet have to_device
870
+ return _cupy_to_device(x, device, stream=stream)
871
+ elif is_torch_array(x):
872
+ return _torch_to_device(x, device, stream=stream) # pyright: ignore[reportArgumentType]
873
+ elif is_dask_array(x):
874
+ if stream is not None:
875
+ raise ValueError("The stream argument to to_device() is not supported")
876
+ # TODO: What if our array is on the GPU already?
877
+ if device == "cpu":
878
+ return x
879
+ raise ValueError(f"Unsupported device {device!r}")
880
+ elif is_jax_array(x):
881
+ if not hasattr(x, "__array_namespace__"):
882
+ # In JAX v0.4.31 and older, this import adds to_device method to x...
883
+ import jax.experimental.array_api # noqa: F401 # pyright: ignore
884
+
885
+ # ... but only on eager JAX. It won't work inside jax.jit.
886
+ if not hasattr(x, "to_device"):
887
+ return x
888
+ return x.to_device(device, stream=stream)
889
+ elif is_pydata_sparse_array(x) and device == _device(x):
890
+ # Perform trivial check to return the same array if
891
+ # device is same instead of err-ing.
892
+ return x
893
+ return x.to_device(device, stream=stream) # pyright: ignore
894
+
895
+
896
+ @overload
897
+ def size(x: HasShape[Collection[SupportsIndex]]) -> int: ...
898
+ @overload
899
+ def size(x: HasShape[Collection[None]]) -> None: ...
900
+ @overload
901
+ def size(x: HasShape[Collection[SupportsIndex | None]]) -> int | None: ...
902
+ def size(x: HasShape[Collection[SupportsIndex | None]]) -> int | None:
903
+ """
904
+ Return the total number of elements of x.
905
+
906
+ This is equivalent to `x.size` according to the `standard
907
+ <https://data-apis.org/array-api/latest/API_specification/generated/array_api.array.size.html>`__.
908
+
909
+ This helper is included because PyTorch defines `size` in an
910
+ :external+torch:meth:`incompatible way <torch.Tensor.size>`.
911
+ It also fixes dask.array's behaviour which returns nan for unknown sizes, whereas
912
+ the standard requires None.
913
+ """
914
+ # Lazy API compliant arrays, such as ndonnx, can contain None in their shape
915
+ if None in x.shape:
916
+ return None
917
+ out = math.prod(cast("Collection[SupportsIndex]", x.shape))
918
+ # dask.array.Array.shape can contain NaN
919
+ return None if math.isnan(out) else out
920
+
921
+
922
+ @lru_cache(100)
923
+ def _is_writeable_cls(cls: type) -> bool | None:
924
+ if (
925
+ _issubclass_fast(cls, "numpy", "generic")
926
+ or _issubclass_fast(cls, "jax", "Array")
927
+ or _issubclass_fast(cls, "sparse", "SparseArray")
928
+ ):
929
+ return False
930
+ if _is_array_api_cls(cls):
931
+ return True
932
+ return None
933
+
934
+
935
+ def is_writeable_array(x: object) -> bool:
936
+ """
937
+ Return False if ``x.__setitem__`` is expected to raise; True otherwise.
938
+ Return False if `x` is not an array API compatible object.
939
+
940
+ Warning
941
+ -------
942
+ As there is no standard way to check if an array is writeable without actually
943
+ writing to it, this function blindly returns True for all unknown array types.
944
+ """
945
+ cls = cast(Hashable, type(x))
946
+ if _issubclass_fast(cls, "numpy", "ndarray"):
947
+ return cast("npt.NDArray", x).flags.writeable
948
+ res = _is_writeable_cls(cls)
949
+ if res is not None:
950
+ return res
951
+ return hasattr(x, '__array_namespace__')
952
+
953
+
954
+ @lru_cache(100)
955
+ def _is_lazy_cls(cls: type) -> bool | None:
956
+ if (
957
+ _issubclass_fast(cls, "numpy", "ndarray")
958
+ or _issubclass_fast(cls, "numpy", "generic")
959
+ or _issubclass_fast(cls, "cupy", "ndarray")
960
+ or _issubclass_fast(cls, "torch", "Tensor")
961
+ or _issubclass_fast(cls, "sparse", "SparseArray")
962
+ ):
963
+ return False
964
+ if (
965
+ _issubclass_fast(cls, "jax", "Array")
966
+ or _issubclass_fast(cls, "dask.array", "Array")
967
+ or _issubclass_fast(cls, "ndonnx", "Array")
968
+ ):
969
+ return True
970
+ return None
971
+
972
+
973
+ def is_lazy_array(x: object) -> bool:
974
+ """Return True if x is potentially a future or it may be otherwise impossible or
975
+ expensive to eagerly read its contents, regardless of their size, e.g. by
976
+ calling ``bool(x)`` or ``float(x)``.
977
+
978
+ Return False otherwise; e.g. ``bool(x)`` etc. is guaranteed to succeed and to be
979
+ cheap as long as the array has the right dtype and size.
980
+
981
+ Note
982
+ ----
983
+ This function errs on the side of caution for array types that may or may not be
984
+ lazy, e.g. JAX arrays, by always returning True for them.
985
+ """
986
+ # **JAX note:** while it is possible to determine if you're inside or outside
987
+ # jax.jit by testing the subclass of a jax.Array object, as well as testing bool()
988
+ # as we do below for unknown arrays, this is not recommended by JAX best practices.
989
+
990
+ # **Dask note:** Dask eagerly computes the graph on __bool__, __float__, and so on.
991
+ # This behaviour, while impossible to change without breaking backwards
992
+ # compatibility, is highly detrimental to performance as the whole graph will end
993
+ # up being computed multiple times.
994
+
995
+ # Note: skipping reclassification of JAX zero gradient arrays, as one will
996
+ # exclusively get them once they leave a jax.grad JIT context.
997
+ cls = cast(Hashable, type(x))
998
+ res = _is_lazy_cls(cls)
999
+ if res is not None:
1000
+ return res
1001
+
1002
+ if not hasattr(x, "__array_namespace__"):
1003
+ return False
1004
+
1005
+ # Unknown Array API compatible object. Note that this test may have dire consequences
1006
+ # in terms of performance, e.g. for a lazy object that eagerly computes the graph
1007
+ # on __bool__ (dask is one such example, which however is special-cased above).
1008
+
1009
+ # Select a single point of the array
1010
+ s = size(cast("HasShape[Collection[SupportsIndex | None]]", x))
1011
+ if s is None:
1012
+ return True
1013
+ xp = array_namespace(x)
1014
+ if s > 1:
1015
+ x = xp.reshape(x, (-1,))[0]
1016
+ # Cast to dtype=bool and deal with size 0 arrays
1017
+ x = xp.any(x)
1018
+
1019
+ try:
1020
+ bool(x)
1021
+ return False
1022
+ # The Array API standard dictactes that __bool__ should raise TypeError if the
1023
+ # output cannot be defined.
1024
+ # Here we allow for it to raise arbitrary exceptions, e.g. like Dask does.
1025
+ except Exception:
1026
+ return True
1027
+
1028
+
1029
+ __all__ = [
1030
+ "array_namespace",
1031
+ "device",
1032
+ "get_namespace",
1033
+ "is_array_api_obj",
1034
+ "is_array_api_strict_namespace",
1035
+ "is_cupy_array",
1036
+ "is_cupy_namespace",
1037
+ "is_dask_array",
1038
+ "is_dask_namespace",
1039
+ "is_jax_array",
1040
+ "is_jax_namespace",
1041
+ "is_numpy_array",
1042
+ "is_numpy_namespace",
1043
+ "is_torch_array",
1044
+ "is_torch_namespace",
1045
+ "is_ndonnx_array",
1046
+ "is_ndonnx_namespace",
1047
+ "is_pydata_sparse_array",
1048
+ "is_pydata_sparse_namespace",
1049
+ "is_writeable_array",
1050
+ "is_lazy_array",
1051
+ "size",
1052
+ "to_device",
1053
+ ]
1054
+
1055
+ _all_ignore = ['lru_cache', 'sys', 'math', 'inspect', 'warnings']
1056
+
1057
+ def __dir__() -> list[str]:
1058
+ return __all__
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/common/_linalg.py ADDED
@@ -0,0 +1,232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import math
4
+ from typing import Literal, NamedTuple, cast
5
+
6
+ import numpy as np
7
+
8
+ if np.__version__[0] == "2":
9
+ from numpy.lib.array_utils import normalize_axis_tuple
10
+ else:
11
+ from numpy.core.numeric import normalize_axis_tuple
12
+
13
+ from .._internal import get_xp
14
+ from ._aliases import isdtype, matmul, matrix_transpose, tensordot, vecdot
15
+ from ._typing import Array, DType, JustFloat, JustInt, Namespace
16
+
17
+
18
+ # These are in the main NumPy namespace but not in numpy.linalg
19
+ def cross(
20
+ x1: Array,
21
+ x2: Array,
22
+ /,
23
+ xp: Namespace,
24
+ *,
25
+ axis: int = -1,
26
+ **kwargs: object,
27
+ ) -> Array:
28
+ return xp.cross(x1, x2, axis=axis, **kwargs)
29
+
30
+ def outer(x1: Array, x2: Array, /, xp: Namespace, **kwargs: object) -> Array:
31
+ return xp.outer(x1, x2, **kwargs)
32
+
33
+ class EighResult(NamedTuple):
34
+ eigenvalues: Array
35
+ eigenvectors: Array
36
+
37
+ class QRResult(NamedTuple):
38
+ Q: Array
39
+ R: Array
40
+
41
+ class SlogdetResult(NamedTuple):
42
+ sign: Array
43
+ logabsdet: Array
44
+
45
+ class SVDResult(NamedTuple):
46
+ U: Array
47
+ S: Array
48
+ Vh: Array
49
+
50
+ # These functions are the same as their NumPy counterparts except they return
51
+ # a namedtuple.
52
+ def eigh(x: Array, /, xp: Namespace, **kwargs: object) -> EighResult:
53
+ return EighResult(*xp.linalg.eigh(x, **kwargs))
54
+
55
+ def qr(
56
+ x: Array,
57
+ /,
58
+ xp: Namespace,
59
+ *,
60
+ mode: Literal["reduced", "complete"] = "reduced",
61
+ **kwargs: object,
62
+ ) -> QRResult:
63
+ return QRResult(*xp.linalg.qr(x, mode=mode, **kwargs))
64
+
65
+ def slogdet(x: Array, /, xp: Namespace, **kwargs: object) -> SlogdetResult:
66
+ return SlogdetResult(*xp.linalg.slogdet(x, **kwargs))
67
+
68
+ def svd(
69
+ x: Array,
70
+ /,
71
+ xp: Namespace,
72
+ *,
73
+ full_matrices: bool = True,
74
+ **kwargs: object,
75
+ ) -> SVDResult:
76
+ return SVDResult(*xp.linalg.svd(x, full_matrices=full_matrices, **kwargs))
77
+
78
+ # These functions have additional keyword arguments
79
+
80
+ # The upper keyword argument is new from NumPy
81
+ def cholesky(
82
+ x: Array,
83
+ /,
84
+ xp: Namespace,
85
+ *,
86
+ upper: bool = False,
87
+ **kwargs: object,
88
+ ) -> Array:
89
+ L = xp.linalg.cholesky(x, **kwargs)
90
+ if upper:
91
+ U = get_xp(xp)(matrix_transpose)(L)
92
+ if get_xp(xp)(isdtype)(U.dtype, 'complex floating'):
93
+ U = xp.conj(U) # pyright: ignore[reportConstantRedefinition]
94
+ return U
95
+ return L
96
+
97
+ # The rtol keyword argument of matrix_rank() and pinv() is new from NumPy.
98
+ # Note that it has a different semantic meaning from tol and rcond.
99
+ def matrix_rank(
100
+ x: Array,
101
+ /,
102
+ xp: Namespace,
103
+ *,
104
+ rtol: float | Array | None = None,
105
+ **kwargs: object,
106
+ ) -> Array:
107
+ # this is different from xp.linalg.matrix_rank, which supports 1
108
+ # dimensional arrays.
109
+ if x.ndim < 2:
110
+ raise xp.linalg.LinAlgError("1-dimensional array given. Array must be at least two-dimensional")
111
+ S: Array = get_xp(xp)(svdvals)(x, **kwargs)
112
+ if rtol is None:
113
+ tol = S.max(axis=-1, keepdims=True) * max(x.shape[-2:]) * xp.finfo(S.dtype).eps
114
+ else:
115
+ # this is different from xp.linalg.matrix_rank, which does not
116
+ # multiply the tolerance by the largest singular value.
117
+ tol = S.max(axis=-1, keepdims=True)*xp.asarray(rtol)[..., xp.newaxis]
118
+ return xp.count_nonzero(S > tol, axis=-1)
119
+
120
+ def pinv(
121
+ x: Array,
122
+ /,
123
+ xp: Namespace,
124
+ *,
125
+ rtol: float | Array | None = None,
126
+ **kwargs: object,
127
+ ) -> Array:
128
+ # this is different from xp.linalg.pinv, which does not multiply the
129
+ # default tolerance by max(M, N).
130
+ if rtol is None:
131
+ rtol = max(x.shape[-2:]) * xp.finfo(x.dtype).eps
132
+ return xp.linalg.pinv(x, rcond=rtol, **kwargs)
133
+
134
+ # These functions are new in the array API spec
135
+
136
+ def matrix_norm(
137
+ x: Array,
138
+ /,
139
+ xp: Namespace,
140
+ *,
141
+ keepdims: bool = False,
142
+ ord: Literal[1, 2, -1, -2] | JustFloat | Literal["fro", "nuc"] | None = "fro",
143
+ ) -> Array:
144
+ return xp.linalg.norm(x, axis=(-2, -1), keepdims=keepdims, ord=ord)
145
+
146
+ # svdvals is not in NumPy (but it is in SciPy). It is equivalent to
147
+ # xp.linalg.svd(compute_uv=False).
148
+ def svdvals(x: Array, /, xp: Namespace) -> Array | tuple[Array, ...]:
149
+ return xp.linalg.svd(x, compute_uv=False)
150
+
151
+ def vector_norm(
152
+ x: Array,
153
+ /,
154
+ xp: Namespace,
155
+ *,
156
+ axis: int | tuple[int, ...] | None = None,
157
+ keepdims: bool = False,
158
+ ord: JustInt | JustFloat = 2,
159
+ ) -> Array:
160
+ # xp.linalg.norm tries to do a matrix norm whenever axis is a 2-tuple or
161
+ # when axis=None and the input is 2-D, so to force a vector norm, we make
162
+ # it so the input is 1-D (for axis=None), or reshape so that norm is done
163
+ # on a single dimension.
164
+ if axis is None:
165
+ # Note: xp.linalg.norm() doesn't handle 0-D arrays
166
+ _x = x.ravel()
167
+ _axis = 0
168
+ elif isinstance(axis, tuple):
169
+ # Note: The axis argument supports any number of axes, whereas
170
+ # xp.linalg.norm() only supports a single axis for vector norm.
171
+ normalized_axis = cast(
172
+ "tuple[int, ...]",
173
+ normalize_axis_tuple(axis, x.ndim), # pyright: ignore[reportCallIssue]
174
+ )
175
+ rest = tuple(i for i in range(x.ndim) if i not in normalized_axis)
176
+ newshape = axis + rest
177
+ _x = xp.transpose(x, newshape).reshape(
178
+ (math.prod([x.shape[i] for i in axis]), *[x.shape[i] for i in rest]))
179
+ _axis = 0
180
+ else:
181
+ _x = x
182
+ _axis = axis
183
+
184
+ res = xp.linalg.norm(_x, axis=_axis, ord=ord)
185
+
186
+ if keepdims:
187
+ # We can't reuse xp.linalg.norm(keepdims) because of the reshape hacks
188
+ # above to avoid matrix norm logic.
189
+ shape = list(x.shape)
190
+ _axis = cast(
191
+ "tuple[int, ...]",
192
+ normalize_axis_tuple( # pyright: ignore[reportCallIssue]
193
+ range(x.ndim) if axis is None else axis,
194
+ x.ndim,
195
+ ),
196
+ )
197
+ for i in _axis:
198
+ shape[i] = 1
199
+ res = xp.reshape(res, tuple(shape))
200
+
201
+ return res
202
+
203
+ # xp.diagonal and xp.trace operate on the first two axes whereas these
204
+ # operates on the last two
205
+
206
+ def diagonal(x: Array, /, xp: Namespace, *, offset: int = 0, **kwargs: object) -> Array:
207
+ return xp.diagonal(x, offset=offset, axis1=-2, axis2=-1, **kwargs)
208
+
209
+ def trace(
210
+ x: Array,
211
+ /,
212
+ xp: Namespace,
213
+ *,
214
+ offset: int = 0,
215
+ dtype: DType | None = None,
216
+ **kwargs: object,
217
+ ) -> Array:
218
+ return xp.asarray(
219
+ xp.trace(x, offset=offset, dtype=dtype, axis1=-2, axis2=-1, **kwargs)
220
+ )
221
+
222
+ __all__ = ['cross', 'matmul', 'outer', 'tensordot', 'EighResult',
223
+ 'QRResult', 'SlogdetResult', 'SVDResult', 'eigh', 'qr', 'slogdet',
224
+ 'svd', 'cholesky', 'matrix_rank', 'pinv', 'matrix_norm',
225
+ 'matrix_transpose', 'svdvals', 'vecdot', 'vector_norm', 'diagonal',
226
+ 'trace']
227
+
228
+ _all_ignore = ['math', 'normalize_axis_tuple', 'get_xp', 'np', 'isdtype']
229
+
230
+
231
+ def __dir__() -> list[str]:
232
+ return __all__
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/common/_typing.py ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ from collections.abc import Mapping
4
+ from types import ModuleType as Namespace
5
+ from typing import (
6
+ TYPE_CHECKING,
7
+ Literal,
8
+ Protocol,
9
+ TypeAlias,
10
+ TypedDict,
11
+ TypeVar,
12
+ final,
13
+ )
14
+
15
+ if TYPE_CHECKING:
16
+ from _typeshed import Incomplete
17
+
18
+ SupportsBufferProtocol: TypeAlias = Incomplete
19
+ Array: TypeAlias = Incomplete
20
+ Device: TypeAlias = Incomplete
21
+ DType: TypeAlias = Incomplete
22
+ else:
23
+ SupportsBufferProtocol = object
24
+ Array = object
25
+ Device = object
26
+ DType = object
27
+
28
+
29
+ _T_co = TypeVar("_T_co", covariant=True)
30
+
31
+
32
+ # These "Just" types are equivalent to the `Just` type from the `optype` library,
33
+ # apart from them not being `@runtime_checkable`.
34
+ # - docs: https://github.com/jorenham/optype/blob/master/README.md#just
35
+ # - code: https://github.com/jorenham/optype/blob/master/optype/_core/_just.py
36
+ @final
37
+ class JustInt(Protocol):
38
+ @property
39
+ def __class__(self, /) -> type[int]: ...
40
+ @__class__.setter
41
+ def __class__(self, value: type[int], /) -> None: ... # pyright: ignore[reportIncompatibleMethodOverride]
42
+
43
+
44
+ @final
45
+ class JustFloat(Protocol):
46
+ @property
47
+ def __class__(self, /) -> type[float]: ...
48
+ @__class__.setter
49
+ def __class__(self, value: type[float], /) -> None: ... # pyright: ignore[reportIncompatibleMethodOverride]
50
+
51
+
52
+ @final
53
+ class JustComplex(Protocol):
54
+ @property
55
+ def __class__(self, /) -> type[complex]: ...
56
+ @__class__.setter
57
+ def __class__(self, value: type[complex], /) -> None: ... # pyright: ignore[reportIncompatibleMethodOverride]
58
+
59
+
60
+ #
61
+
62
+
63
+ class NestedSequence(Protocol[_T_co]):
64
+ def __getitem__(self, key: int, /) -> _T_co | NestedSequence[_T_co]: ...
65
+ def __len__(self, /) -> int: ...
66
+
67
+
68
+ class SupportsArrayNamespace(Protocol[_T_co]):
69
+ def __array_namespace__(self, /, *, api_version: str | None) -> _T_co: ...
70
+
71
+
72
+ class HasShape(Protocol[_T_co]):
73
+ @property
74
+ def shape(self, /) -> _T_co: ...
75
+
76
+
77
+ # Return type of `__array_namespace_info__.default_dtypes`
78
+ Capabilities = TypedDict(
79
+ "Capabilities",
80
+ {
81
+ "boolean indexing": bool,
82
+ "data-dependent shapes": bool,
83
+ "max dimensions": int,
84
+ },
85
+ )
86
+
87
+ # Return type of `__array_namespace_info__.default_dtypes`
88
+ DefaultDTypes = TypedDict(
89
+ "DefaultDTypes",
90
+ {
91
+ "real floating": DType,
92
+ "complex floating": DType,
93
+ "integral": DType,
94
+ "indexing": DType,
95
+ },
96
+ )
97
+
98
+
99
+ _DTypeKind: TypeAlias = Literal[
100
+ "bool",
101
+ "signed integer",
102
+ "unsigned integer",
103
+ "integral",
104
+ "real floating",
105
+ "complex floating",
106
+ "numeric",
107
+ ]
108
+ # Type of the `kind` parameter in `__array_namespace_info__.dtypes`
109
+ DTypeKind: TypeAlias = _DTypeKind | tuple[_DTypeKind, ...]
110
+
111
+
112
+ # `__array_namespace_info__.dtypes(kind="bool")`
113
+ class DTypesBool(TypedDict):
114
+ bool: DType
115
+
116
+
117
+ # `__array_namespace_info__.dtypes(kind="signed integer")`
118
+ class DTypesSigned(TypedDict):
119
+ int8: DType
120
+ int16: DType
121
+ int32: DType
122
+ int64: DType
123
+
124
+
125
+ # `__array_namespace_info__.dtypes(kind="unsigned integer")`
126
+ class DTypesUnsigned(TypedDict):
127
+ uint8: DType
128
+ uint16: DType
129
+ uint32: DType
130
+ uint64: DType
131
+
132
+
133
+ # `__array_namespace_info__.dtypes(kind="integral")`
134
+ class DTypesIntegral(DTypesSigned, DTypesUnsigned):
135
+ pass
136
+
137
+
138
+ # `__array_namespace_info__.dtypes(kind="real floating")`
139
+ class DTypesReal(TypedDict):
140
+ float32: DType
141
+ float64: DType
142
+
143
+
144
+ # `__array_namespace_info__.dtypes(kind="complex floating")`
145
+ class DTypesComplex(TypedDict):
146
+ complex64: DType
147
+ complex128: DType
148
+
149
+
150
+ # `__array_namespace_info__.dtypes(kind="numeric")`
151
+ class DTypesNumeric(DTypesIntegral, DTypesReal, DTypesComplex):
152
+ pass
153
+
154
+
155
+ # `__array_namespace_info__.dtypes(kind=None)` (default)
156
+ class DTypesAll(DTypesBool, DTypesNumeric):
157
+ pass
158
+
159
+
160
+ # `__array_namespace_info__.dtypes(kind=?)` (fallback)
161
+ DTypesAny: TypeAlias = Mapping[str, DType]
162
+
163
+
164
+ __all__ = [
165
+ "Array",
166
+ "Capabilities",
167
+ "DType",
168
+ "DTypeKind",
169
+ "DTypesAny",
170
+ "DTypesAll",
171
+ "DTypesBool",
172
+ "DTypesNumeric",
173
+ "DTypesIntegral",
174
+ "DTypesSigned",
175
+ "DTypesUnsigned",
176
+ "DTypesReal",
177
+ "DTypesComplex",
178
+ "DefaultDTypes",
179
+ "Device",
180
+ "HasShape",
181
+ "Namespace",
182
+ "JustInt",
183
+ "JustFloat",
184
+ "JustComplex",
185
+ "NestedSequence",
186
+ "SupportsArrayNamespace",
187
+ "SupportsBufferProtocol",
188
+ ]
189
+
190
+
191
+ def __dir__() -> list[str]:
192
+ return __all__
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/cupy/__init__.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from cupy import * # noqa: F403
2
+
3
+ # from cupy import * doesn't overwrite these builtin names
4
+ from cupy import abs, max, min, round # noqa: F401
5
+
6
+ # These imports may overwrite names from the import * above.
7
+ from ._aliases import * # noqa: F403
8
+
9
+ # See the comment in the numpy __init__.py
10
+ __import__(__package__ + '.linalg')
11
+ __import__(__package__ + '.fft')
12
+
13
+ __array_api_version__ = '2024.12'
tool_server/.venv/lib/python3.12/site-packages/scipy/_lib/array_api_compat/cupy/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (488 Bytes). View file