fpnla-0.1.1: A library for NLA operations
Safe HaskellSafe-Inferred
LanguageHaskell98

FPNLA.Matrix

Description

This module defines classes used to handle Matrices and Vectors in a generic way.

Synopsis

Vector

class Vector (v :: Type -> Type) e where Source #

This class represents a vector structure For any vector data structure used in this framework it must have an instance of this class. A minimal instance of this class must provide an implementation for generate_v, elem_v and length_v. The index of the first element stored in the vector must be 0. This is a multi-param type class because usually libraries of Matrix and Vector imposes restrictions over the type of the elements (for example, to have a Storable instance).

Minimal complete definition

generate_v, elem_v, length_v

Methods

generate_v Source #

Arguments

:: Int

The length of the vector

-> (Int -> e)

A function that returns the value for each index

-> v e 

Creates a new vector from the length of the vector and a function that returns the value for each index.

fromList_v Source #

Arguments

:: [e]

A list that contains the elements of the vector. The first element of the list will be the first element of the vector and so on.

-> v e 

Creates a new vector from a list, th vector will contain all (and only) the elements of the list, and in the same order.

concat_v Source #

Arguments

:: [v e]

A list containing the vectors to be joined. If the list is [1, 2,3, 4,5,6] then the vector will be 1,2,3,4,5,6.

-> v e 

Join multiple vectors in one single vector.

elem_v :: Int -> v e -> e Source #

Returns the element from a given index. The index must be between 0 and the length of the vector.

length_v :: v e -> Int Source #

Returns the length of the vector.

foldr_v :: (e -> b -> b) -> b -> v e -> b Source #

The common foldr function but specific for this instance.

map_v :: (e -> e) -> v e -> v e Source #

The common map function but specific for this instance.

zipWith_v :: (e -> e -> e) -> v e -> v e -> v e Source #

The common zipWith function but specific for this instance.

Matrix

class Matrix (m :: Type -> Type) e where Source #

This class represents any Matrix structure For any matrix data structure used in this framework it must have an instance of this class. A minimal instance of this class must provide an implementation for generate_m, dim_m and elem_m. The index of the first element stored in the vector must be (0,0). This is a multi-param type class because usually libraries of Matrix and Vector imposes restrictions over the type of the elements (for example, to have an Storable instance).

Minimal complete definition

generate_m, dim_m, elem_m

Methods

generate_m Source #

Arguments

:: Int

The length of the rows

-> Int

A function that returns the value for each index

-> (Int -> Int -> e) 
-> m e 

Creates a new matrix from the dimension (length of rows and columns) of the matrix and a function that returns the value for each index.

fromList_m :: Int -> Int -> [e] -> m e Source #

Creates a new matrix from the dimension (length of rows and columns) of and a list.

transpose_m :: m e -> m e Source #

Given a matrix, creates a new matrix that will be the transpose of the original.

dim_m :: m e -> (Int, Int) Source #

Returns the dimension of a given matrix. The first element in the pair is the number of rows and the second the number of columns.

elem_m Source #

Arguments

:: Int

The row component of the position (i).

-> Int

The column component of the position (j).

-> m e

The matrix.

-> e 

Returns the element that is in the position (i,j).

map_m :: (e -> e) -> m e -> m e Source #

The common map function but specific for this instance.

zipWith_m :: (e -> e -> e) -> m e -> m e -> m e Source #

The common zipWith function but specific for this instance.

subMatrix_m Source #

Arguments

:: Int
i
-> Int
j
-> Int
r
-> Int
c
-> m e
m
-> m e 

Given an initial position (i,j), a dimension (r,c) and a matrix m, creates a new matrix that is a sub matrix of m containing the elements in positions [(p1, p2) | p1 <- [i..i+r], p2 <- [j..j+c]] For example, if m is: 1 2 3 4 5 6 7 8 9 and (i,j) and (r,c) are (0,1) and (2,3) respectively, then the result will be a new matrix containing: 2 3 5 6 8 9

fromBlocks_m :: [[m e]] -> m e Source #

Constructs a new matrix from a list of list where the elements are sub-matrices. This operations is the analogue of concat_v operation from the Vector class. The 'borders' of the sub-matrices will be joined. The dimensions of the sum-matrices must be compatibles.

toBlocks_m Source #

Arguments

:: Int
r
-> Int
c
-> m e
m
-> [[m e]] 

Split a matrix m in blocks of size (r,c) (the dimension of the blocks in the right and the bottom may be smaller).

MatrixVectror

class (Vector v e, Matrix m e) => MatrixVector (m :: Type -> Type) (v :: Type -> Type) e where Source #

This class allows us to leave separated the two concepts of Vector and Matrix. This class establishes a link between a vector and a matrix structure. We provide a default instance for any Vector and Matrix instances so any vector could be used with any matrix whenever the type of the elements are the same.

Minimal complete definition

Nothing

Methods

row_vm :: Int -> m e -> v e Source #

Extracts the i-th row of the matrix m and converts it in the vector structure.

col_vm :: Int -> m e -> v e Source #

Extracts the j-th column of the matrix m and converts it in the vector structure.

fromCols_vm :: [v e] -> m e Source #

Joins a list of column vectors in a matrix structure. The length of every vector in the list must be the same.

toCols_vm :: m e -> [v e] Source #

Returns a list containing every column of the matrix converted in the vector structure.

Instances

Instances details
(Vector v e, Matrix m e) => MatrixVector m v e Source # 
Instance details

Defined in FPNLA.Matrix

Methods

row_vm :: Int -> m e -> v e Source #

col_vm :: Int -> m e -> v e Source #

fromCols_vm :: [v e] -> m e Source #

toCols_vm :: m e -> [v e] Source #

Miscellaneous

cantRows_m :: Matrix m e => m e -> Int Source #

Returns the number of rows of the matrix.

cantCols_m :: Matrix m e => m e -> Int Source #

Returns the number of columns of the matrix.

size_m :: Matrix m e => m e -> Int Source #

Returns the size of the matrix (number of rows x number of columns).

asColumn_vm :: MatrixVector m v e => v e -> m e Source #

Converts a vector in a matrix of one column.

diagonalBlock Source #

Arguments

:: Matrix m e 
=> (Int, Int)
(r,c)
-> Int
i
-> m e
m
-> m e 

Splits a matrix m into blocks of size (r,c) and returns the block on the position (i,i).

verticalBlock Source #

Arguments

:: Matrix m e 
=> Int
s
-> Int
i
-> m e
m
-> m e 

Splits a matrix m into blocks of size (s, cantCols_m m) and returns the block on the position i.