Skip to main content

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 for torch.Tensor backends.
  • 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 space
  • HermitianSpace - space of Hermitian (symmetric) matrices
  • ProductSpace - Cartesian product of spaces

LinOp

A LinOp represents a linear operator between spaces, for example:

  • DenseLinOp - linear operator represented by dense matrix
  • SparseLinOp - linear operator represented by sparse matrix
  • BlockDiagonalLinOp - 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

spacecore-0.1.4.tar.gz (59.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spacecore-0.1.4-py3-none-any.whl (70.5 kB view details)

Uploaded Python 3

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

Hashes for spacecore-0.1.4.tar.gz
Algorithm Hash digest
SHA256 5a32cda96e2732930ee2d893f5fb8a27d14eb09f346bacfa9ad38597f7e97198
MD5 286ee15a441a575357fb1c498cf2eef4
BLAKE2b-256 72168a00be8e318afc384e49f8a99f48cc66d61d906c4f37d80052a901c9a254

See more details on using hashes here.

Provenance

The following attestation bundles were made for spacecore-0.1.4.tar.gz:

Publisher: ci.yml on Pavlo3P/SpaceCore

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for spacecore-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4292776949a5ce60b50c4e2490bb64f635f4295917971b86d18c39a287eb5765
MD5 4edc192c69423c21fb7618896253713f
BLAKE2b-256 5e3ee38b2007015fcea790cee645e023fee1e52fbec4256f94a8b0faca8d4f1e

See more details on using hashes here.

Provenance

The following attestation bundles were made for spacecore-0.1.4-py3-none-any.whl:

Publisher: ci.yml on Pavlo3P/SpaceCore

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page