cupy.linalg.inv insists on 2D array
See original GitHub issueThe function cupy.linalg.inv
can compute the inverse of a 2D array (matrix), but raises an error for a >2D array. In numpy, the inverse is computed over the last two axes for a >2D array in numpy.linalg.inv
.
- Can the numpy behavior be implemented in cupy?
- Is there an efficient manual method?
Concerning 2, I tried
cp.array([cp.linalg.inv(a) for a in arr], dtype=arr.dtype)
but this seems slow. I also looked at cupy.linalg.tensorinv
but I’m not able to use it for this purpose.
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
cupy.linalg.inv — CuPy 11.4.0 documentation
This function computes matrix a_inv from n-dimensional regular matrix a such that dot(a, a_inv) == eye(n) . Parameters. a (cupy.ndarray) – The regular...
Read more >cupy.linalg.tensorinv — CuPy 11.3.0 documentation
Computes the inverse of a tensor. This function computes tensor a_inv from tensor a such that tensordot(a_inv, a, ind) == I , where...
Read more >Linear algebra (cupy.linalg) — CuPy 11.4.0 documentation
Return the least-squares solution to a linear matrix equation. linalg.inv (a). Computes the inverse of a matrix.
Read more >cupy.linalg.pinv — CuPy 11.3.0 documentation
It computes a pseudoinverse of a matrix a , which is a generalization of the inverse matrix with Singular Value Decomposition (SVD). Note...
Read more >cupy.linalg.norm — CuPy 11.4.0 documentation
ndarray) – Array to take norm. If axis is None, x must be 1-D or 2-D. ord (non ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@clemisch I think @okuta said that you can do parallelized inv in the same way as Chainer do. Chainer is not needed. Just call cublas APIs (sgetrfBatched and sgetriBatched) as in the code okuta linked.
Thanks, (Note that I’m not a member of PFN, I just concerned the same problem as you.)
Nevermind, I only was too lazy and just did it myself. You only need to adapt the
matmul
functions from chainer. But somehow, I get invalid values in the return array. Does the input arrayb
has to have a certain shape?