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
DimensionErrorimmediately - 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?
- Catch errors early: Don't waste compute on dimensionally invalid calculations
- Self-documenting code: Units make physics code clearer
- Designed for ML: Built with PyTorch/JAX integration in mind (coming soon)
- Lightweight: Just metadata tracking, minimal overhead
License
MIT
Project details
Release history Release notifications | RSS feed
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.2.0.tar.gz
(12.2 kB
view details)
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
dimtensor-0.2.0-py3-none-any.whl
(14.1 kB
view details)
File details
Details for the file dimtensor-0.2.0.tar.gz.
File metadata
- Download URL: dimtensor-0.2.0.tar.gz
- Upload date:
- Size: 12.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0177754ef555ba6f5454b754b29f1e05dbd2e7c0fd4ae1d840341430463667ca
|
|
| MD5 |
762bcc1b6cc496faddc74e0c73ebad3b
|
|
| BLAKE2b-256 |
f48c2d82fedc843da0d501efcb20f00a40a97d428a762a0680de447dee0a6377
|
File details
Details for the file dimtensor-0.2.0-py3-none-any.whl.
File metadata
- Download URL: dimtensor-0.2.0-py3-none-any.whl
- Upload date:
- Size: 14.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a18adec2d92ad0a4701bd010894bc7ca752c9a28eb0f5d972947c5f3274c780c
|
|
| MD5 |
f3650f9800bd73485ba5bc34f34a2149
|
|
| BLAKE2b-256 |
be10a1b47c886c901ce3cf1edef9534d8a4ed33d8e3b5bd063fd0e2426a5470a
|