Module

Data.Matrix

#Matrix

newtype Matrix h w a

Matrix with height h, width w and contained value a

Constructors

Instances

#fill

fill :: forall h w a. Nat h => Nat w => (Int -> Int -> a) -> Matrix h w a

Creation

create Matrix of size hxw with a generator-function

> fill (\x y -> x) :: Matrix D2 D3 Int
  [0,1,2]
  [0,1,2]

#fromVec

fromVec :: forall s h w a. Nat s => Nat h => Nat w => Mul h w s => Vec s a -> Matrix h w a
> fromVec (Vec.vec3 1 2 3) :: Matrix D1 D3 _
  [1,2,3]

> fromVec (Vec.vec3 1 2 3) :: Matrix D3 D1 _
  [1]
  [2]
  [3]

#toArray

toArray :: forall h w a. Nat h => Nat w => Matrix h w a -> Array (Array a)

Convert Matrix to Array

> toArray (matrix22 1 2 3 4)
[[1,2],[3,4]]

#replicate'

replicate' :: forall w h a. Nat w => Nat h => a -> Matrix h w a

create Matrix with one value

> replicate' "-" :: Matrix D3 D5 _
 ["-","-","-","-","-"]
 ["-","-","-","-","-"]
 ["-","-","-","-","-"]

#height

height :: forall h w a. Nat h => Nat w => Matrix h w a -> Int

Basic Accesors

height of the matrix (aka number of rows)

#width

width :: forall h w a. Nat h => Nat w => Matrix h w a -> Int

width of the matrix (aka number of columns)

#size

size :: forall s a. Nat s => Matrix s s a -> Int

size of square matrix

#index

index :: forall x y h w a. Nat x => Nat y => Lt x w => Lt y h => x -> y -> Matrix h w a -> a

value a position in matrix:

> m
 [1,2,-3]
 [4,9,0]
 [11,2,8]
> index d0 d2 m -- d0, d2 are value-representations of D0 D2
11

#index'

index' :: forall h w a. Nat h => Nat w => Int -> Int -> Matrix h w a -> Maybe a

value a position in matrix:

> m
 [1,2,-3]
 [4,9,0]
 [11,2,8]
> index 0 2 m
Just 11
> index 10 2 m
Nothing

#unsafeIndex

unsafeIndex :: forall h w a. Partial => Nat h => Nat w => Matrix h w a -> Int -> Int -> a

#column

column :: forall h w a x. Nat x => Lt x w => Nat h => Matrix h w a -> x -> Vec h a

get vector for column

> m
  [1,2]
  [0,5]
> column m d1
[2,5]

#columnUnsafe

columnUnsafe :: forall h w a. Partial => Nat h => Nat w => Matrix h w a -> Int -> Vec h a

#row

row :: forall h w a y. Nat y => Lt y h => Nat w => Matrix h w a -> y -> Vec w a

get vector for row

> m
  [1,2]
  [0,5]
> row m d1
[0,5]

#rowUnsafe

rowUnsafe :: forall h w a. Partial => Nat h => Nat w => Matrix h w a -> Int -> Vec w a

#concatH

concatH :: forall h w1 w2 w a. Add w1 w2 w => Nat h => Matrix h w1 a -> Matrix h w2 a -> Matrix h w a
> matrix22 1 2 3 4 `concatH` matrix22 0 1 2 0
 [1,2,0,1]
 [3,4,2,0]

#concatV

concatV :: forall h1 h2 h w a. Add h1 h2 h => Nat w => Matrix h1 w a -> Matrix h2 w a -> Matrix h w a

Basic Operations

> matrix22 1 2 3 4 `concatV` matrix22 0 1 2 0
 [1,2]
 [3,4]
 [0,1]
 [2,0]

#zipWithE

zipWithE :: forall w h a b c. Nat w => Nat h => (a -> b -> c) -> Matrix h w a -> Matrix h w b -> Matrix h w c

Zip Matrices with function with Exactly the same size

> zipWithE Tuple (matrix22 1 2 0 0) (matrix22 1 3 4 5)
 [(Tuple 1 1),(Tuple 2 3)]
 [(Tuple 0 4),(Tuple 0 5)]

#zipE

zipE :: forall w h a b. Nat w => Nat h => Matrix h w a -> Matrix h w b -> Matrix h w (Tuple a b)

Zip Matrices with Exactly the same size

> zipE (matrix22 1 2 0 0) (matrix22 1 3 4 5)
 [(Tuple 1 1),(Tuple 2 3)]
 [(Tuple 0 4),(Tuple 0 5)]

#negateMatrix

negateMatrix :: forall h w a. Nat h => Nat w => Ring a => Matrix h w a -> Matrix h w a

#mulMatrix

mulMatrix :: forall h w a. Nat h => Nat w => CommutativeRing a => Matrix h w a -> Matrix w h a -> Matrix h h a

#matrixOne

matrixOne :: forall h w a. Semiring a => Nat h => Nat w => Matrix h w a

#matrixZero

matrixZero :: forall h w a. Semiring a => Nat h => Nat w => Matrix h w a

#scalarMul

scalarMul :: forall h w a. Nat h => Nat w => Semiring a => a -> Matrix h w a -> Matrix h w a

#(\\)

Operator alias for Data.Matrix.concatV (right-associative / precedence 3)

Modules