typelevel-tensor-0.2.1: Tensors whose ranks and dimensions type-inferred and type-checked.

Safe HaskellNone



A tensor algebra library. Main ingredients are :

Vec and :~ are data constructors for rank-1 tensor. This is essentially a touple of objects of the same type.

Vector is a class for rank-1 tensor.

Axis is an object for accessing the tensor components.



data n :~ a Source

data constructor for constructing n+1-dimensional tensor from n-dimensional tensor.


(n a) :~ a 


Traversable n => Functor (:~ n) 
(Applicative n, Traversable n) => Applicative (:~ n) 
Traversable n => Foldable (:~ n) 
Traversable n => Traversable (:~ n) 
Vector v => Vector (:~ v) 
(C a, VectorRing v a, C (v a)) => VectorRing (:~ v) a 
(Eq a, Eq (n a)) => Eq (:~ n a) 
(Vector v, Num a) => Num (:~ v a) 
(Ord (n a), Ord a) => Ord (:~ n a)

the last component contributes the most to the ordering

(Read a, Vector (:~ n)) => Read (:~ n a) 
(Show a, Traversable (:~ n)) => Show (:~ n a) 
(Arbitrary a, Arbitrary (n a), Traversable n) => Arbitrary (:~ n a) 
(Vector v, C a) => C (:~ v a) 

data Vec a Source

data constructor for 0-dimensional tensor.




Functor Vec 
Applicative Vec 
Foldable Vec 
Traversable Vec 
Vector Vec 
C a => VectorRing Vec a 
Eq (Vec a) 
Ord (Vec a) 
Read (Vec a) 
Show (Vec a) 
Arbitrary (Vec a) 
C a => C (Vec a)

Vector whose components are additive is also additive.

newtype Axis v Source

An coordinate Axis , labeled by an integer. Axis also carries v, the container type for its corresponding vector. Therefore, An axis of one type can access only vectors of a fixed dimension, but of arbitrary type.




axisIndex :: Int


Eq (Axis v) 
Ord (Axis v) 
Read (Axis v) 
Show (Axis v) 

(!) :: Vector v => v a -> Axis v -> aSource

a component operator.

class Traversable v => Vector v whereSource

An object that allows component-wise access.




:: Alternative f 
=> Axis v

the axis of the component you want

-> v a

the target vector

-> f a

the component, obtained within a failure

Get a component within f, a context which allows failure.

component :: Axis v -> v a -> aSource

Get a component. This computation may result in a runtime error, though, as long as the Axis is generated from library functions such as compose, there will be no error.

dimension :: v a -> IntSource

The dimension of the vector.

compose :: (Axis v -> a) -> v aSource

Create a Vector from a function that maps axis to components.


Vector Vec 
Vector v => Vector (:~ v) 

class (Vector v, C a) => VectorRing v a whereSource

VectorRing is a Vector whose components belongs to C, thus providing unit vectors.


unitVectorF :: Alternative f => Axis v -> f (v a)Source

A vector where Axisth component is unity but others are zero.

unitVector :: Axis v -> v aSource

pure but unsafe version means of obtaining a unitVector


C a => VectorRing Vec a 
(C a, VectorRing v a, C (v a)) => VectorRing (:~ v) a 

contract :: (Vector v, C a) => (Axis v -> a) -> aSource

Tensor contraction. Create a Vector from a function that maps axis to component, then sums over the axis and returns a.

type Vec0 = VecSource

Type synonyms

vec0 :: Vec0 aSource

Utility functions

vec1 :: a -> Vec1 aSource

vec2 :: a -> a -> Vec2 aSource

vec3 :: a -> a -> a -> Vec3 aSource

vec4 :: a -> a -> a -> a -> Vec4 aSource

vec5 :: a -> a -> a -> a -> a -> Vec5 aSource

vec6 :: a -> a -> a -> a -> a -> a -> Vec6 aSource

vec7 :: a -> a -> a -> a -> a -> a -> a -> Vec7 aSource

vec8 :: a -> a -> a -> a -> a -> a -> a -> a -> Vec8 aSource

vec9 :: a -> a -> a -> a -> a -> a -> a -> a -> a -> Vec9 aSource

vec10 :: a -> a -> a -> a -> a -> a -> a -> a -> a -> a -> Vec10 aSource