Skip to main content

Typed NumPy with static shape typing and runtime shape validation.

Project description

typed-numpy

Ruff

Typed NumPy with static shape typing and runtime shape validation.

[!WARNING] Experimental & WIP. See USAGE.md for more details.

Installation

Install uv (optional, recommended)

Install uv, if not already. Check here for installation instructions.

It is recommended to use uv, as it will automatically install the dependencies in a virtual environment. If you don't want to use uv, skip to the next step.

TL;DR: Just run

curl -LsSf https://astral.sh/uv/install.sh | sh
Install the package

The dependencies are listed in the pyproject.toml file. At present, the only required dependency is numpy.

Install the package from the PyPI release:

# Using uv
uv add typed-numpy

# Or with pip
pip3 install typed-numpy

To install from the latest commit:

uv add git+https://github.com/AshrithSagar/typed-numpy.git@main

Usage

from typing import TypeVar

from typed_numpy._typed.ndarray import TypedNDArray

# Shape variables are just regular TypeVar's
N = TypeVar("N", bound=int, default=int)
M = TypeVar("M", bound=int, default=int)

# Create aliases such as these, or use TypedNDArray directly
Vector = TypedNDArray[tuple[N]]
Matrix = TypedNDArray[tuple[M, N]]

v1 = Vector([1, 2, 3])  # Passes
v2 = Vector([4, 5, 6, 7])  # Also passes

v3 = TypedNDArray[tuple[int]]([[8, 9]])
# Fails, since expected 1D array but passed in a 2D array

See USAGE.md for more details.

License

This project falls under the MIT License.

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

typed_numpy-0.2.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

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

typed_numpy-0.2.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file typed_numpy-0.2.0.tar.gz.

File metadata

  • Download URL: typed_numpy-0.2.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for typed_numpy-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d52d74016ebeceff410b8822ed9fd5872b7dbd33e0cd25df2400c3ce76aba8f5
MD5 d44888b1d739d92567c06607e0563de8
BLAKE2b-256 6d1b5738d5a92831fa9c3b5862b5e5450d9883cbf18f0fd776e94119fb594704

See more details on using hashes here.

File details

Details for the file typed_numpy-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: typed_numpy-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for typed_numpy-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eb4d7616d0c70544021bebbeb9492439171cc4d4573af1e982cd7dc9d6a2ceb2
MD5 e99c81b68de25b1ffe4dafadec877c66
BLAKE2b-256 1b23e882e3fda5cfc11a942ca6bb45c6f0d472557660e685a3e7f4a3e9922868

See more details on using hashes here.

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