Static Linear Unitfull Tensors
This is a small lib I made for my thermodynamics simulation project. I was fed up with implementing vectors in uom. It's very bug prone, experimental but does the job quite well. Inspired by Terry Tao's post and yuouom.
It's very useful for a lot of things like physics simulation, linear algebra, and could even be used as a theorem prover for dimensional analysis. Don't forget to include the experimental headers and use cargo nightly.
Usage
You can cargo add the library from this repository. You can find all the structures in dlt::tensor units in dlt::units and all the dimensions in dlt::dimension. You can create tensors of any dimension and any unit. You can also perform operations on tensors like addition, subtraction, scaling, dot product, cross product, matrix multiplication, etc.
use *;
use *;
use *;
let t = ;
let v = ;
let m = ;
Example
use *;
use *;
use *;
// Tensor of lengths
let mass = ;
let force = ;
//let error = mass + force; // error (expected)
let mass = mass + ; // works
println!;
/*
Tensor [1x1]: M^1
( 10.005 )
*/
// Operator overloading for scalar division
let acc = force / mass; // works
println!;
/*
Tensor [2x1]: L^1 * T^-2
( 0.9995002 )
( 1.9990004 )
*/
let time = ;
let vel1 = ;
let vel2 = vel1 + acc.scale; // works
println!;
/*
[10.9995, 21.999]
*/
Linear algebra
// try to transpose a tensor
let tensor = ;
let tensor_transposed = tensor.transpose;
println!;
println!;
/*
Tensor [1x6]: Dimensionless
( 1 2 3 4 5 6 )
Tensor [6x1]: Dimensionless
( 1 )
( 2 )
( 3 )
( 4 )
( 5 )
( 6 )
*/
let length = ;
// now try and dot product length and force
// dot product add the dimensions
let dot_product = dot!;
println!;
/*
Tensor [1x1]: L^2 * M^1 * T^-2
( 50 )
*/
assert_dimension!; // works
//assert_dimension!(dot_product, Force); // error (expected)
let m1 = ;
let m2 = ;
let m3 = m1.matmul;
println!;
/*
Tensor [2x2]: L^2
( 22 28 )
( 49 64 )
*/