Module

Data.Matrix

Package
purescript-sized-matrices
Repository
csicar/purescript-sized-matrices

#Matrix Source

newtype Matrix h w a

Matrix with height h, width w and contained value a

Constructors

Instances

#fill Source

fill :: forall a w h. 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 Source

fromVec :: forall a w h s. 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 Source

toArray :: forall a w h. 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' Source

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

create Matrix with one value

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

#height Source

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

Basic Accesors

height of the matrix (aka number of rows)

#width Source

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

width of the matrix (aka number of columns)

#size Source

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

size of square matrix

#index Source

index :: forall a w h y x. 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' Source

index' :: forall a w h. 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 Source

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

#column Source

column :: forall x a w h. 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 Source

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

#row Source

row :: forall y a w h. 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 Source

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

#concatH Source

concatH :: forall a w w2 w1 h. 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 Source

concatV :: forall a w h h2 h1. 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 Source

zipWithE :: forall c b a h w. 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 Source

zipE :: forall b a h w. 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 Source

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

#mulMatrix Source

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

#matrixOne Source

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

#matrixZero Source

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

#scalarMul Source

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

#(\\) Source

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