Module

# Data.Matrix

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

### #MatrixSource

``newtype Matrix h w a``

Matrix with height `h`, width `w` and contained value `a`

#### Constructors

• `Matrix (Vec h (Vec w a))`

#### Instances

• `(Nat h, Nat w, Semiring a) => Semigroup (Matrix h w a)`
• `(Nat h, Nat w, Semiring a) => Commutative (Matrix h w a)`
• `(Nat h, Nat w, Semiring a) => Monoid (Matrix h w a)`
• `(Nat h, Nat w, Ring a) => Group (Matrix h w a)`
• `(Field k, Nat s) => VectorField (Matrix s s) k`
• `(Nat h, Nat w, Show a) => Show (Matrix h w a)`
• `(Nat h, Nat w) => Functor (Matrix h w)`
• `(Nat h, Nat w) => Foldable (Matrix h w)`
• `(Eq a, Nat h, Nat w) => Eq (Matrix h w a)`
• `(Nat s, CommutativeRing a) => Semiring (Matrix s s a)`
• `(Nat s, CommutativeRing a) => Ring (Matrix s s a)`

### #fillSource

``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]
``````

### #fromVecSource

``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 _



``````

### #toArraySource

``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'Source

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

create Matrix with one value

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

### #heightSource

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

## Basic Accesors

height of the matrix (aka number of rows)

### #widthSource

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

width of the matrix (aka number of columns)

### #sizeSource

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

size of square matrix

### #indexSource

``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'Source

``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
``````

### #unsafeIndexSource

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

### #columnSource

``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]
``````

### #columnUnsafeSource

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

### #rowSource

``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]
``````

### #rowUnsafeSource

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

### #concatHSource

``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]
``````

### #concatVSource

``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]
``````

### #zipWithESource

``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)]
``````

### #zipESource

``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)]
``````

### #negateMatrixSource

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

### #mulMatrixSource

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

### #matrixOneSource

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

### #matrixZeroSource

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

### #scalarMulSource

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