Backend-agnostic vector spaces and linear operators.
Project description
SpaceCore
SpaceCore is a lightweight backend-agnostic library for working with vector spaces and linear operators.
It provides a small set of abstractions for:
- backend-aware numerical operations
- contexts carrying backend and dtype information
- structured vector spaces
- structured linear operators
- conversion between compatible contexts
Installation
Base install:
pip install spacecore
With JAX support:
pip install "spacecore[jax]"
With PyTorch support:
pip install "spacecore[torch]"
spacecore[jax]: installs optional JAX support.- GPU users should install the appropriate CUDA-enabled JAX build first, following the official JAX installation guide.
spacecore[torch]: installs optional PyTorch support fortorch.Tensorbackends.- GPU users should install the appropriate CUDA-enabled PyTorch build first, following the official PyTorch installation guide.
Main concepts
Context
A Context specifies how objects are represented, in particular:
- backend (
NumPy,JAX,PyTorch, etc.) - dtype
- validation/conversion behavior
Constructors resolve contexts in priority order: explicit ctx=..., then
contexts inferred from inputs, then the global default context. Advanced code
that needs this resolution step directly can call
spacecore.resolve_context_priority(...).
Space
A Space describes the structure of objects space, for example:
VectorSpace- Euclidean spaceHermitianSpace- space of Hermitian (symmetric) matricesProductSpace- Cartesian product of spaces
LinOp
A LinOp represents a linear operator between spaces, for example:
DenseLinOp- linear operator represented by dense matrixSparseLinOp- linear operator represented by sparse matrixBlockDiagonalLinOp- linear operator from $X_1 \times \dots \times X_k$ to $Y_1 \times \dots \times Y_k$StackedLinOp- linear operator from $X$ to $Y_1 \times \dots \times Y_k$SumToSingleLinOp- linear operator from $X_1 \times \dots \times X_k$ to $Y$
Minimal example
import numpy as np
import spacecore as sc
sc.set_context('numpy', dtype='float64')
X = sc.VectorSpace((3,))
Y = sc.VectorSpace((2,))
A = np.array(
[[1.0, 2.0, 3.0],
[0.0, 1.0, 0.0]]
)
linop = sc.DenseLinOp(
A,
dom=X,
cod=Y,
)
x = X.ctx.asarray([1.0, 0.0, -1.0])
y = linop.apply(x)
print(y)
PyTorch tensors can be used by selecting the torch backend:
import torch
import spacecore as sc
ctx = sc.Context(sc.TorchOps(), dtype=torch.float64)
X = sc.VectorSpace((3,), ctx)
x = ctx.asarray([1.0, 2.0, 3.0])
print(X.inner(x, x))
Status
SpaceCore is currently experimental and under active development. The public API may still evolve.
Tutorials
See the Sphinx documentation under docs/source/ for tutorials, design notes,
API reference, and release notes.
Documentation
The documentation website is built with Sphinx from docs/source.
Install the documentation dependencies:
pip install -e ".[docs]"
Build the local HTML documentation:
sphinx-build -b html docs/source docs/build/html
License
Apache License 2.0
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 spacecore-0.1.4.tar.gz.
File metadata
- Download URL: spacecore-0.1.4.tar.gz
- Upload date:
- Size: 59.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a32cda96e2732930ee2d893f5fb8a27d14eb09f346bacfa9ad38597f7e97198
|
|
| MD5 |
286ee15a441a575357fb1c498cf2eef4
|
|
| BLAKE2b-256 |
72168a00be8e318afc384e49f8a99f48cc66d61d906c4f37d80052a901c9a254
|
Provenance
The following attestation bundles were made for spacecore-0.1.4.tar.gz:
Publisher:
ci.yml on Pavlo3P/SpaceCore
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spacecore-0.1.4.tar.gz -
Subject digest:
5a32cda96e2732930ee2d893f5fb8a27d14eb09f346bacfa9ad38597f7e97198 - Sigstore transparency entry: 1524630342
- Sigstore integration time:
-
Permalink:
Pavlo3P/SpaceCore@ebf53a7ec84d70ccc0811020007674f244c83abd -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/Pavlo3P
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@ebf53a7ec84d70ccc0811020007674f244c83abd -
Trigger Event:
push
-
Statement type:
File details
Details for the file spacecore-0.1.4-py3-none-any.whl.
File metadata
- Download URL: spacecore-0.1.4-py3-none-any.whl
- Upload date:
- Size: 70.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4292776949a5ce60b50c4e2490bb64f635f4295917971b86d18c39a287eb5765
|
|
| MD5 |
4edc192c69423c21fb7618896253713f
|
|
| BLAKE2b-256 |
5e3ee38b2007015fcea790cee645e023fee1e52fbec4256f94a8b0faca8d4f1e
|
Provenance
The following attestation bundles were made for spacecore-0.1.4-py3-none-any.whl:
Publisher:
ci.yml on Pavlo3P/SpaceCore
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spacecore-0.1.4-py3-none-any.whl -
Subject digest:
4292776949a5ce60b50c4e2490bb64f635f4295917971b86d18c39a287eb5765 - Sigstore transparency entry: 1524630353
- Sigstore integration time:
-
Permalink:
Pavlo3P/SpaceCore@ebf53a7ec84d70ccc0811020007674f244c83abd -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/Pavlo3P
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@ebf53a7ec84d70ccc0811020007674f244c83abd -
Trigger Event:
push
-
Statement type: