Skip to main content

Unit-aware tensors for physics and scientific machine learning

Project description

dimtensor

Unit-aware tensors for physics and scientific machine learning.

dimtensor wraps NumPy arrays with physical unit tracking, catching dimensional errors at operation time rather than after hours of computation.

Installation

pip install dimtensor

Quick Start

from dimtensor import DimArray, units

# Create dimension-aware arrays
velocity = DimArray([10, 20, 30], units.m / units.s)
time = DimArray([1, 2, 3], units.s)

# Operations preserve/check dimensions
distance = velocity * time
print(distance)  # [10 40 90] m

# Catch errors early
acceleration = DimArray([9.8], units.m / units.s**2)
velocity + acceleration  # DimensionError: cannot add m/s to m/s^2

Features

  • Dimensional Safety: Operations between incompatible dimensions raise DimensionError immediately
  • Unit Conversion: Convert between compatible units with .to()
  • SI Units: Full support for SI base and derived units
  • NumPy Integration: Works with NumPy arrays and supports common operations
  • Lightweight: Minimal overhead, just metadata tracking

Examples

Kinematics

from dimtensor import DimArray, units

v = DimArray([10], units.m / units.s)  # velocity
t = DimArray([5], units.s)              # time
d = v * t                               # distance = 50 m

Force and Energy

m = DimArray([2], units.kg)              # mass
g = DimArray([9.8], units.m / units.s**2)  # gravity
h = DimArray([10], units.m)              # height

# Potential energy
PE = m * g * h  # 196 J

# Force
F = m * g  # 19.6 N

Unit Conversion

distance = DimArray([1], units.km)
in_meters = distance.to(units.m)  # 1000 m
in_miles = distance.to(units.mile)  # ~0.621 mi

Why dimtensor?

  1. Catch errors early: Don't waste compute on dimensionally invalid calculations
  2. Self-documenting code: Units make physics code clearer
  3. Designed for ML: Built with PyTorch/JAX integration in mind (coming soon)
  4. Lightweight: Just metadata tracking, minimal overhead

License

MIT

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

dimtensor-0.8.0.tar.gz (31.6 kB view details)

Uploaded Source

Built Distribution

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

dimtensor-0.8.0-py3-none-any.whl (40.6 kB view details)

Uploaded Python 3

File details

Details for the file dimtensor-0.8.0.tar.gz.

File metadata

  • Download URL: dimtensor-0.8.0.tar.gz
  • Upload date:
  • Size: 31.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for dimtensor-0.8.0.tar.gz
Algorithm Hash digest
SHA256 b4ba4b9582ddc61e6c5c0cb5768066f7c39f3b86950f1bb0c61c2fa98b82fb2e
MD5 afa7b23dc08602e84e2fa53e589746a8
BLAKE2b-256 b27fd5c761b0fe6767c0dce4a22cc5de19ccc622aff1182021677407ef2f9b5c

See more details on using hashes here.

File details

Details for the file dimtensor-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: dimtensor-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 40.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for dimtensor-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b5bd55685fc19e74e9d93d4e81a3e6eb128b695fdf0ef07310a8469bf06c62c2
MD5 7a33ffd5877d1162780483c1d477ee4d
BLAKE2b-256 3762aa3a00a9a2d9f17c1eeca7de953e6f653f968c7cf67934f9ca760758aad3

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