feldspar-language-0.6.0.2: A functional embedded language for DSP and parallelism

Safe Haskell | None

Feldspar.Matrix

Contents

- Wrapping for matrices

Description

Operations on matrices (doubly-nested parallel vectors). All operations in this module assume rectangular matrices.

Synopsis

- type Matrix a = Vector2 a
- tMat :: Patch a a -> Patch (Matrix a) (Matrix a)
- freezeMatrix :: Type a => Matrix a -> Data [[a]]
- thawMatrix :: Type a => Data [[a]] -> Matrix a
- thawMatrix' :: Type a => Length -> Length -> Data [[a]] -> Matrix a
- matrix :: Type a => [[a]] -> Matrix a
- indexedMat :: Data Length -> Data Length -> (Data Index -> Data Index -> Data a) -> Matrix a
- transpose :: Type a => Matrix a -> Matrix a
- flatten :: Type a => Matrix a -> Vector (Data a)
- diagonal :: Type a => Matrix a -> Vector (Data a)
- distributeL :: (a -> b -> c) -> a -> Vector b -> Vector c
- distributeR :: (a -> b -> c) -> Vector a -> b -> Vector c
- class Mul a b where
  - type Prod a b
  - (***) :: a -> b -> Prod a b
- mulMat :: Numeric a => Matrix a -> Matrix a -> Matrix a
- class Syntax a => ElemWise a where
  - type Scalar a
  - elemWise :: (Scalar a -> Scalar a -> Scalar a) -> a -> a -> a
- (.+) :: (ElemWise a, Num (Scalar a)) => a -> a -> a
- (.-) :: (ElemWise a, Num (Scalar a)) => a -> a -> a
- (.*) :: (ElemWise a, Num (Scalar a)) => a -> a -> a

# Documentation

type Matrix a = Vector2 a

tMat :: Patch a a -> Patch (Matrix a) (Matrix a)

freezeMatrix :: Type a => Matrix a -> Data [[a]]

Converts a matrix to a core array.

thawMatrix :: Type a => Data [[a]] -> Matrix a

Converts a core array to a matrix.

thawMatrix' :: Type a => Length -> Length -> Data [[a]] -> Matrix a

Converts a core array to a matrix. The first length argument is the number of rows (outer vector), and the second argument is the number of columns (inner vector).

matrix :: Type a => [[a]] -> Matrix a

Constructs a matrix. The elements are stored in a core array.

indexedMat :: Data Length -> Data Length -> (Data Index -> Data Index -> Data a) -> Matrix a

Constructing a matrix from an index function.

`indexedMat m n ixf`:

- `m` is the number of rows.
- `n` is the number of columns.
- `ifx` is a function mapping indexes to elements (first argument is row index; second argument is column index).

transpose :: Type a => Matrix a -> Matrix a

Transpose of a matrix. Assumes that the number of rows is > 0.

flatten :: Type a => Matrix a -> Vector (Data a)

Concatenates the rows of a matrix.

diagonal :: Type a => Matrix a -> Vector (Data a)

The diagonal vector of a square matrix. It happens to work if the number of rows is less than the number of columns, but not the other way around (this would require some overhead).

distributeL :: (a -> b -> c) -> a -> Vector b -> Vector c

distributeR :: (a -> b -> c) -> Vector a -> b -> Vector c

class Mul a b where

Associated Types

type Prod a b

Methods

(***) :: a -> b -> Prod a b

General multiplication operator

Instances

Numeric a => Mul (Data a) (Matrix a) |
Numeric a => Mul (Data a) (Vector1 a) |
Numeric a => Mul (Data a) (Data a) |
Numeric a => Mul (Vector1 a) (Matrix a) |
Numeric a => Mul (Vector1 a) (Vector1 a) |
Numeric a => Mul (Vector1 a) (Data a) |
Numeric a => Mul (Matrix a) (Matrix a) |
Numeric a => Mul (Matrix a) (Vector1 a) |
Numeric a => Mul (Matrix a) (Data a) |

mulMat :: Numeric a => Matrix a -> Matrix a -> Matrix a

Matrix multiplication

class Syntax a => ElemWise a where

Associated Types

type Scalar a

Methods

elemWise :: (Scalar a -> Scalar a -> Scalar a) -> a -> a -> a

Operator for general element-wise multiplication

Instances

Type a => ElemWise (Data a) |
(ElemWise a, Syntax (Vector a)) => ElemWise (Vector a) |

(.+) :: (ElemWise a, Num (Scalar a)) => a -> a -> a

(.-) :: (ElemWise a, Num (Scalar a)) => a -> a -> a

(.*) :: (ElemWise a, Num (Scalar a)) => a -> a -> a

# Wrapping for matrices