Batched tensorsolve() for NumPy / PyTorch / JAX
Project description
Batch Tensorsolve
Documentation: https://batch-tensorsolve.readthedocs.io
Source Code: https://github.com/34j/batch-tensorsolve
Batched tensorsolve() for NumPy / PyTorch / JAX. (numpy/numpy#28099)
Installation
Install this via pip (or your favourite package manager):
pip install batch-tensorsolve
Usage
import numpy as np
from numpy.testing import assert_allclose
from batch_tensorsolve import btensorsolve
a = np.random.randn(2, 2, 3, 6)
b = np.random.randn(2, 2, 3)
assert_allclose(np.einsum("...ijk,...k->...ij", a, btensorsolve(a, b)), b)
Advanced Usage
It is recommended to explicitly specify the batch axes, as the desired shape will be ambiguous if axes of size 1 are present.
import numpy as np
from batch_tensorsolve import btensorsolve
a = np.random.randn(2, 1, 2, 2)
b = np.random.randn(2, 1, 2)
# 2 possibilities:
assert btensorsolve(a, b, num_batch_axes=1).shape == (2, 2) # 1st axis is batch
assert btensorsolve(a, b, num_batch_axes=2).shape == (2, 1, 2) # 1st and 2nd axes are batch
Broadcasting-like behavior is also supported:
import numpy as np
from numpy.testing import assert_allclose
from batch_tensorsolve import btensorsolve
a = np.random.randn(1, 2, 3, 6) # -> (2, 2, 3, 6)
b = np.random.randn(2, 1, 1) # -> (2, 2, 3)
left = np.einsum("...ijk,...k->...ij", a, btensorsolve(a, b))
assert_allclose(left, np.broadcast_to(b, left.shape))
Note that broadcasting (repeating) a for non-batch axes will result in numpy.linalg.LinAlgError: Singular matrix because the matrix representation of a has duplicate rows.
Contributors ✨
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
Credits
This package was created with Copier and the browniebroke/pypackage-template project template.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file batch_tensorsolve-0.1.0.tar.gz.
File metadata
- Download URL: batch_tensorsolve-0.1.0.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63c94a4685fcd5f089cf872025e1f23a6d319c402a15b2a078f0838216b3be32
|
|
| MD5 |
326d8efa3dc4acbc6f7d0a713ba75d4e
|
|
| BLAKE2b-256 |
c20ad5fd41ad4d511b4e4e15ade69c053e4b5275ed327d1e45f80895cc1cf6e6
|
Provenance
The following attestation bundles were made for batch_tensorsolve-0.1.0.tar.gz:
Publisher:
ci.yml on 34j/batch-tensorsolve
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
batch_tensorsolve-0.1.0.tar.gz -
Subject digest:
63c94a4685fcd5f089cf872025e1f23a6d319c402a15b2a078f0838216b3be32 - Sigstore transparency entry: 209528157
- Sigstore integration time:
-
Permalink:
34j/batch-tensorsolve@924a8b99a99e50e01018a4848bf05e95acbcf1f6 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/34j
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@924a8b99a99e50e01018a4848bf05e95acbcf1f6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file batch_tensorsolve-0.1.0-py3-none-any.whl.
File metadata
- Download URL: batch_tensorsolve-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d85e3e58206909407e461e563594f4a1dc00376035d860880dc4e5c96f928d9a
|
|
| MD5 |
7ff3d717d63f4c4bdfc5c7aba1b0d5ab
|
|
| BLAKE2b-256 |
11ed1bd65cc6c0ab656aa899c160c01f6081a3bb3c434cf00537072d77433228
|
Provenance
The following attestation bundles were made for batch_tensorsolve-0.1.0-py3-none-any.whl:
Publisher:
ci.yml on 34j/batch-tensorsolve
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
batch_tensorsolve-0.1.0-py3-none-any.whl -
Subject digest:
d85e3e58206909407e461e563594f4a1dc00376035d860880dc4e5c96f928d9a - Sigstore transparency entry: 209528159
- Sigstore integration time:
-
Permalink:
34j/batch-tensorsolve@924a8b99a99e50e01018a4848bf05e95acbcf1f6 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/34j
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@924a8b99a99e50e01018a4848bf05e95acbcf1f6 -
Trigger Event:
push
-
Statement type: