xarray-einstats
xarray-einstats copied to clipboard
1 test fails: TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'
========================================================================================= FAILURES ==========================================================================================
__________________________________________________________________________________ TestWrappers.test_pinv ___________________________________________________________________________________
self = <tests.test_linalg.TestWrappers object at 0x1711c8c9ddd0>
matrices = <xarray.DataArray (batch: 10, experiment: 3, dim: 4, dim2: 4)> Size: 4kB
0.11 0.3897 1.4 2.2 0.3435 0.2578 0.4345 ... 0.3557 1.105 2.256 2.58 1.683 1.311
Dimensions without coordinates: batch, experiment, dim, dim2
def test_pinv(self, matrices):
> out = pinv(matrices, dims=("experiment", "dim"))
test_linalg.py:145:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../stage/usr/local/lib/python3.11/site-packages/xarray_einstats/linalg.py:807: in pinv
return xr.apply_ufunc(
/usr/local/lib/python3.11/site-packages/xarray/core/computation.py:1268: in apply_ufunc
return apply_dataarray_vfunc(
/usr/local/lib/python3.11/site-packages/xarray/core/computation.py:312: in apply_dataarray_vfunc
result_var = func(*data_vars)
/usr/local/lib/python3.11/site-packages/xarray/core/computation.py:821: in apply_variable_ufunc
result_data = func(*input_data)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
a = array([[[[1.10014813e-01, 3.43493819e-01, 1.00096157e+00,
2.66531379e-01],
[9.07669713e-01, 1.79952...-01,
3.49558767e-03],
[1.81801768e+00, 2.39405153e+00, 1.10546137e+00,
1.31130995e+00]]]])
rcond = array(None, dtype=object), hermitian = False
@array_function_dispatch(_pinv_dispatcher)
def pinv(a, rcond=1e-15, hermitian=False):
"""
Compute the (Moore-Penrose) pseudo-inverse of a matrix.
Calculate the generalized inverse of a matrix using its
singular-value decomposition (SVD) and including all
*large* singular values.
.. versionchanged:: 1.14
Can now operate on stacks of matrices
Parameters
----------
a : (..., M, N) array_like
Matrix or stack of matrices to be pseudo-inverted.
rcond : (...) array_like of float
Cutoff for small singular values.
Singular values less than or equal to
``rcond * largest_singular_value`` are set to zero.
Broadcasts against the stack of matrices.
hermitian : bool, optional
If True, `a` is assumed to be Hermitian (symmetric if real-valued),
enabling a more efficient method for finding singular values.
Defaults to False.
.. versionadded:: 1.17.0
Returns
-------
B : (..., N, M) ndarray
The pseudo-inverse of `a`. If `a` is a `matrix` instance, then so
is `B`.
Raises
------
LinAlgError
If the SVD computation does not converge.
See Also
--------
scipy.linalg.pinv : Similar function in SciPy.
scipy.linalg.pinvh : Compute the (Moore-Penrose) pseudo-inverse of a
Hermitian matrix.
Notes
-----
The pseudo-inverse of a matrix A, denoted :math:`A^+`, is
defined as: "the matrix that 'solves' [the least-squares problem]
:math:`Ax = b`," i.e., if :math:`\\bar{x}` is said solution, then
:math:`A^+` is that matrix such that :math:`\\bar{x} = A^+b`.
It can be shown that if :math:`Q_1 \\Sigma Q_2^T = A` is the singular
value decomposition of A, then
:math:`A^+ = Q_2 \\Sigma^+ Q_1^T`, where :math:`Q_{1,2}` are
orthogonal matrices, :math:`\\Sigma` is a diagonal matrix consisting
of A's so-called singular values, (followed, typically, by
zeros), and then :math:`\\Sigma^+` is simply the diagonal matrix
consisting of the reciprocals of A's singular values
(again, followed by zeros). [1]_
References
----------
.. [1] G. Strang, *Linear Algebra and Its Applications*, 2nd Ed., Orlando,
FL, Academic Press, Inc., 1980, pp. 139-142.
Examples
--------
The following example checks that ``a * a+ * a == a`` and
``a+ * a * a+ == a+``:
>>> a = np.random.randn(9, 6)
>>> B = np.linalg.pinv(a)
>>> np.allclose(a, np.dot(a, np.dot(B, a)))
True
>>> np.allclose(B, np.dot(B, np.dot(a, B)))
True
"""
a, wrap = _makearray(a)
rcond = asarray(rcond)
if _is_empty_2d(a):
m, n = a.shape[-2:]
res = empty(a.shape[:-2] + (n, m), dtype=a.dtype)
return wrap(res)
a = a.conjugate()
u, s, vt = svd(a, full_matrices=False, hermitian=hermitian)
# discard small singular values
> cutoff = rcond[..., newaxis] * amax(s, axis=-1, keepdims=True)
E TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'
/usr/local/lib/python3.11/site-packages/numpy/linalg/linalg.py:2025: TypeError
===================================================================================== warnings summary ======================================================================================
tests/test_stats.py::TestMvNormal::test_rvs_method[vals0]
tests/test_stats.py::TestMvNormal::test_rvs_method[vals1]
/usr/ports/devel/py-xarray-einstats/work-py311/stage/usr/local/lib/python3.11/site-packages/xarray_einstats/stats.py:384: PendingDeprecationWarning: The `dims` argument has been renamed to `dim`, and will be removed in the future. This renaming is taking place throughout xarray over the next few releases.
return mean + xr.dot(cov_chol, samples, dims=dim2)
tests/test_stats.py::TestMvNormal::test_pdf_method[vals0]
tests/test_stats.py::TestMvNormal::test_pdf_method[vals1]
/usr/ports/devel/py-xarray-einstats/work-py311/stage/usr/local/lib/python3.11/site-packages/xarray_einstats/stats.py:397: PendingDeprecationWarning: The `dims` argument has been renamed to `dim`, and will be removed in the future. This renaming is taking place throughout xarray over the next few releases.
maha = np.square(xr.dot(x_mu.rename({dim1: dim2}), u_mat, dims=dim2)).sum(dim=dim1)
tests/test_stats.py: 20 warnings
/usr/local/lib/python3.11/site-packages/scipy/stats/_stats_py.py:1069: DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)
else dtype(mean))
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================================================================== short test summary info ==================================================================================
SKIPPED [1] test_stats.py:193: rankdata doesn't support Dataset input and dims=None
============================================================= 1 failed, 263 passed, 1 skipped, 24 warnings in 192.08s (0:03:12) =============================================================
*** Error code 1
Version: 0.8.0 Python 3.11 FreeBSD 14.1
Hi, sorry. I can't reproduce this (nor can the project's CI). Can you add the versions you are using for the dependencies of the project? numpy, scipy and xarray