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.
Metadata
Release files for batch-tensorsolve 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| batch_tensorsolve-1.0.2.tar.gz | 9.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| batch_tensorsolve-1.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.2 kB
Release files / batch_tensorsolve-1.0.2.tar.gz
| Download URL | batch_tensorsolve-1.0.2.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c726f89c1372fe3c840707498344fb7101ea4144cec9e91d95b694dc47f36dd5
|
|
BLAKE2b-256 checksum How to use checksums |
2cf874cc2cbad732b5ac5a76ddf615d9e15d4e103149557a704edba45f99f838
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 28, 2025.
Transparency logRelease files / batch_tensorsolve-1.0.2-py3-none-any.whl
| Download URL | batch_tensorsolve-1.0.2-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
09f023e8dbf2b136d74feb8ad3237f93a2204723d71c6b38ed2ab211180dd013
|
|
BLAKE2b-256 checksum How to use checksums |
16c5d382e374531320f84a4f2856d25af6b11e18d2b8443cb4ea3caf275c64f6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 28, 2025.
Transparency log