linear-accelerate-0.7.0.0: Lifting linear vector spaces into Accelerate

Copyright2014 Edward Kmett Charles Durham
[2015..2020] Trevor L. McDonell
LicenseBSD-style (see the file LICENSE)
MaintainerTrevor L. McDonell <trevor.mcdonell@gmail.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Data.Array.Accelerate.Linear.Matrix

Description

Simple matrix operations for low-dimensional primitives

Synopsis

Documentation

(!*!) :: (Functor m, Foldable t, Additive t, Additive n, Num a, Box2 m t a, Box2 t n a, Box2 m n a) => Exp (m (t a)) -> Exp (t (n a)) -> Exp (m (n a)) infixl 7 Source #

Matrix product. This can compute any combination of sparse and dense multiplication.

>>> test $ (V2_ (V3_ 1 2 3) (V3_ 4 5 6) :: Exp (M23 Int)) !*! (V3_ (V2_ 1 2) (V2_ 3 4) (V2_ 4 5) :: Exp (M32 Int))
V2 (V2 19 25) (V2 43 58)

(!+!) :: (Additive m, Additive n, Num a, Box2 m n a) => Exp (m (n a)) -> Exp (m (n a)) -> Exp (m (n a)) infixl 6 Source #

Entry-wise matrix addition.

>>> test $ (V2_ (V3_ 1 2 3) (V3_ 4 5 6) :: Exp (M23 Int)) !+! (V2_ (V3_ 7 8 9) (V3_ 1 2 3) :: Exp (M23 Int))
V2 (V3 8 10 12) (V3 5 7 9)

(!-!) :: (Additive m, Additive n, Num a, Box2 m n a) => Exp (m (n a)) -> Exp (m (n a)) -> Exp (m (n a)) infixl 6 Source #

Entry-wise matrix subtraction.

>>> test $ (V2_ (V3_ 1 2 3) (V3_ 4 5 6) :: Exp (M23 Int)) !-! (V2_ (V3_ 7 8 9) (V3_ 1 2 3) :: Exp (M23 Int))
V2 (V3 (-6) (-6) (-6)) (V3 3 3 3)

(!*) :: (Functor m, Foldable r, Additive r, Num a, Box2 m r a, Box m a) => Exp (m (r a)) -> Exp (r a) -> Exp (m a) infixl 7 Source #

Matrix * column vector

>>> test $ (V2_ (V3_ 1 2 3) (V3_ 4 5 6) :: Exp (M23 Int)) !* (V3_ 7 8 9 :: Exp (V3 Int))
V2 50 122

(*!) :: (Foldable t, Additive f, Additive t, Num a, Box t a, Box f a, Box2 t f a) => Exp (t a) -> Exp (t (f a)) -> Exp (f a) infixl 7 Source #

Row vector * matrix

>>> test $ (V2_ 1 2 :: Exp (V2 Int)) *! (V2_ (V3_ 3 4 5) (V3_ 6 7 8) :: Exp (M23 Int))
V3 15 18 21

(!!*) :: (Functor m, Functor r, Num a, Box2 m r a) => Exp (m (r a)) -> Exp a -> Exp (m (r a)) infixl 7 Source #

Matrix-scalar product

>>> test $ (V2_ (V2_ 1 2) (V2_ 3 4) :: Exp (M22 Int)) !!* 5
V2 (V2 5 10) (V2 15 20)

(*!!) :: (Functor m, Functor r, Num a, Box2 m r a) => Exp a -> Exp (m (r a)) -> Exp (m (r a)) infixl 7 Source #

Scalar-matrix product

>>> test $ 5 *!! (V2_ (V2_ 1 2) (V2_ 3 4) :: Exp (M22 Int))
V2 (V2 5 10) (V2 15 20)

(!!/) :: (Functor m, Functor r, Floating a, Box2 m r a) => Exp (m (r a)) -> Exp a -> Exp (m (r a)) infixl 7 Source #

Matrix-scalar division

type M22 a = V2 (V2 a) #

A 2x2 matrix with row-major representation

type M23 a = V2 (V3 a) #

A 2x3 matrix with row-major representation

type M24 a = V2 (V4 a) #

A 2x4 matrix with row-major representation

type M32 a = V3 (V2 a) #

A 3x2 matrix with row-major representation

type M33 a = V3 (V3 a) #

A 3x3 matrix with row-major representation

type M34 a = V3 (V4 a) #

A 3x4 matrix with row-major representation

type M42 a = V4 (V2 a) #

A 4x2 matrix with row-major representation

type M43 a = V4 (V3 a) #

A 4x3 matrix with row-major representation

type M44 a = V4 (V4 a) #

A 4x4 matrix with row-major representation

m33_to_m44 :: Num a => Exp (M33 a) -> Exp (M44 a) Source #

Convert a 3x3 matrix to a 4x4 matrix extending it with zeros in the new row and column.

m43_to_m44 :: Num a => Exp (M43 a) -> Exp (M44 a) Source #

Convert a 4x3 matrix to a 4x4 matrix, extending it with [ 0 0 0 1 ] column vector

det22 :: Num a => Exp (M22 a) -> Exp a Source #

2x2 matrix determinant

det33 :: Num a => Exp (M33 a) -> Exp a Source #

3x3 matrix determinant

det44 :: Num a => Exp (M44 a) -> Exp a Source #

4x4 matrix determinant

inv22 :: Fractional a => Exp (M22 a) -> Exp (M22 a) Source #

2x2 matrix inverse

inv33 :: Fractional a => Exp (M33 a) -> Exp (M33 a) Source #

3x3 matrix inverse

inv44 :: Fractional a => Exp (M44 a) -> Exp (M44 a) Source #

4x4 matrix inverse

identity :: forall t a. (Traversable t, Applicative t, Num a, Box2 t t a) => Exp (t (t a)) Source #

The identity matrix for any dimension vector.

>>> test $ (identity :: Exp (M44 Int))
V4 (V4 1 0 0 0) (V4 0 1 0 0) (V4 0 0 1 0) (V4 0 0 0 1)
>>> test $ (identity :: Exp (V3 (V3 Int)))
V3 (V3 1 0 0) (V3 0 1 0) (V3 0 0 1)

transpose :: (Distributive g, Functor f, Box2 f g a, Box2 g f a) => Exp (f (g a)) -> Exp (g (f a)) Source #

transpose is just an alias for distribute

>>> test $ transpose $ (V3_ (V2_ 1 2) (V2_ 3 4) (V2_ 5 6) :: Exp (M32 Int))
V2 (V3 1 3 5) (V3 2 4 6)

class Trace m => Trace m where Source #

Minimal complete definition

Nothing

Methods

trace :: (Num a, Box2 m m a) => Exp (m (m a)) -> Exp a Source #

Compute the trace of a matrix

diagonal :: Box2 m m a => Exp (m (m a)) -> Exp (m a) Source #

Compute the diagonal of a matrix

Instances
Trace Complex Source # 
Instance details

Defined in Data.Array.Accelerate.Linear.Trace

Trace Plucker Source # 
Instance details

Defined in Data.Array.Accelerate.Linear.Trace

Trace Quaternion Source # 
Instance details

Defined in Data.Array.Accelerate.Linear.Trace

Trace V0 Source # 
Instance details

Defined in Data.Array.Accelerate.Linear.Trace

Methods

trace :: (Num a, Box2 V0 V0 a) => Exp (V0 (V0 a)) -> Exp a Source #

diagonal :: Box2 V0 V0 a => Exp (V0 (V0 a)) -> Exp (V0 a) Source #

Trace V4 Source # 
Instance details

Defined in Data.Array.Accelerate.Linear.Trace

Methods

trace :: (Num a, Box2 V4 V4 a) => Exp (V4 (V4 a)) -> Exp a Source #

diagonal :: Box2 V4 V4 a => Exp (V4 (V4 a)) -> Exp (V4 a) Source #

Trace V3 Source # 
Instance details

Defined in Data.Array.Accelerate.Linear.Trace

Methods

trace :: (Num a, Box2 V3 V3 a) => Exp (V3 (V3 a)) -> Exp a Source #

diagonal :: Box2 V3 V3 a => Exp (V3 (V3 a)) -> Exp (V3 a) Source #

Trace V2 Source # 
Instance details

Defined in Data.Array.Accelerate.Linear.Trace

Methods

trace :: (Num a, Box2 V2 V2 a) => Exp (V2 (V2 a)) -> Exp a Source #

diagonal :: Box2 V2 V2 a => Exp (V2 (V2 a)) -> Exp (V2 a) Source #

Trace V1 Source # 
Instance details

Defined in Data.Array.Accelerate.Linear.Trace

Methods

trace :: (Num a, Box2 V1 V1 a) => Exp (V1 (V1 a)) -> Exp a Source #

diagonal :: Box2 V1 V1 a => Exp (V1 (V1 a)) -> Exp (V1 a) Source #

fromQuaternion :: forall a. Num a => Exp (Quaternion a) -> Exp (M33 a) Source #

Build a rotation matrix from a unit Quaternion

mkTransformation :: forall a. Num a => Exp (Quaternion a) -> Exp (V3 a) -> Exp (M44 a) Source #

Build a transformation matrix from a rotation expressed as a Quaternion and a translation vector.

mkTransformationMat :: Num a => Exp (M33 a) -> Exp (V3 a) -> Exp (M44 a) Source #

Build a transformation matrix from a rotation matrix and a translation vector.