Copyright | (C) Frank Staals |
---|---|
License | see the LICENSE file |
Maintainer | Frank Staals |
Safe Haskell | None |
Language | GHC2021 |
A class of types representing matrices
Synopsis
- class (r ~ NumType matrix, Ixed matrix, IxValue matrix ~ r, Index matrix ~ (Int, Int), HasElements matrix matrix) => Matrix_ matrix (n :: Nat) (m :: Nat) r | matrix -> n, matrix -> m, matrix -> r where
- identityMatrix :: matrix
- generateMatrix :: ((Int, Int) -> r) -> matrix
- matrixFromList :: [r] -> Maybe matrix
- matrixFromRows :: Vector_ rowVector n (Vector m r) => rowVector -> matrix
- (!*!) :: forall matrix' (m' :: Nat) matrix''. (Matrix_ matrix' m m' r, Matrix_ matrix'' n m' r, Num r, Has_ Additive_ m r) => matrix -> matrix' -> matrix''
- (!*) :: matrix -> Vector m r -> Vector n r
- (*!!) :: r -> matrix -> matrix
- (!!*) :: matrix -> r -> matrix
- rows :: Lens' matrix (Vector n (Vector m r))
- row :: Int -> matrix -> Maybe (Vector m r)
- column :: Int -> matrix -> Maybe (Vector n r)
- class HasElements matrix matrix' where
- elements :: IndexedTraversal1 (Int, Int) matrix matrix' (NumType matrix) (NumType matrix')
- class HasDeterminant (d :: Nat) where
- class Invertible (n :: Nat) where
- inverseMatrix :: (Fractional r, Matrix_ matrix n n r, Has_ Vector_ n r) => matrix -> matrix
Documentation
class (r ~ NumType matrix, Ixed matrix, IxValue matrix ~ r, Index matrix ~ (Int, Int), HasElements matrix matrix) => Matrix_ matrix (n :: Nat) (m :: Nat) r | matrix -> n, matrix -> m, matrix -> r where Source #
A matrix of n rows, each of m columns, storing values of type r.
identityMatrix :: matrix Source #
Produces the Identity Matrix.
>>>
printMatrix $ identityMatrix @(Matrix 3 3 Int)
Vector3 1 0 0 Vector3 0 1 0 Vector3 0 0 1
generateMatrix :: ((Int, Int) -> r) -> matrix Source #
Given a function that specifies the values, generate the matrix
matrixFromList :: [r] -> Maybe matrix Source #
Given a list of the elements in the matrix, in row by row order, constructs the matrix. requires that there are exactly n*m elements.
>>>
matrixFromList @(Matrix 2 3 Int) [1,2,3,4,5,6]
Just (Matrix (Vector2 (Vector3 1 2 3) (Vector3 4 5 6)))>>>
matrixFromList @(Matrix 2 3 Int) [1,2,3,4,5,6,7]
Nothing
matrixFromRows :: Vector_ rowVector n (Vector m r) => rowVector -> matrix Source #
Given a list of the elements in the matrix, in row by row order, constructs the matrix. requires that there are exactly n*m elements.
>>>
matrixFromRows @(Matrix 2 3 Int) (Vector2 (Vector3 1 2 3) (Vector3 4 5 6))
Matrix (Vector2 (Vector3 1 2 3) (Vector3 4 5 6))
(!*!) :: forall matrix' (m' :: Nat) matrix''. (Matrix_ matrix' m m' r, Matrix_ matrix'' n m' r, Num r, Has_ Additive_ m r) => matrix -> matrix' -> matrix'' infixl 7 Source #
Matrix multiplication
>>>
let m1 = matrixFromRows @(Matrix 2 3 Int) (Vector2 (Vector3 1 2 3) (Vector3 4 5 6))
>>>
let r i = Vector4 i (i*10) (i*100) (i*1000)
>>>
let m2 = matrixFromRows @(Matrix 3 4 Int) (Vector3 (r 1) (r 2) (r 3))
>>>
printMatrix $ (m1 !*! m2 :: Matrix 2 4 Int)
Vector4 14 140 1400 14000 Vector4 32 320 3200 32000
(!*) :: matrix -> Vector m r -> Vector n r infixl 7 Source #
Multiply a matrix and a vector.
>>>
let m = matrixFromRows @(Matrix 2 3 Int) (Vector2 (Vector3 1 2 3) (Vector3 4 5 6))
>>>
m !* Vector3 2 3 1
Vector2 11 29
(*!!) :: r -> matrix -> matrix infixl 7 Source #
Multiply a scalar and a matrix
(!!*) :: matrix -> r -> matrix infixl 7 Source #
Multiply a matrix and a scalar
rows :: Lens' matrix (Vector n (Vector m r)) Source #
Lens to access all rows
row :: Int -> matrix -> Maybe (Vector m r) Source #
Access the i^th row in the matrix.
column :: Int -> matrix -> Maybe (Vector n r) Source #
Access the j^th column in the matrix.
Instances
(Has_ Vector_ n (Vector m r), Has_ Additive_ m r, Ixed (Vector n (Vector m r)), Ixed (Vector m r)) => Matrix_ (Matrix n m r) n m r Source # | |
Defined in HGeometry.Matrix.ByRows identityMatrix :: Matrix n m r Source # generateMatrix :: ((Int, Int) -> r) -> Matrix n m r Source # matrixFromList :: [r] -> Maybe (Matrix n m r) Source # matrixFromRows :: Vector_ rowVector n (Vector m r) => rowVector -> Matrix n m r Source # (!*!) :: forall matrix' (m' :: Nat) matrix''. (Matrix_ matrix' m m' r, Matrix_ matrix'' n m' r, Num r, Has_ Additive_ m r) => Matrix n m r -> matrix' -> matrix'' Source # (!*) :: Matrix n m r -> Vector m r -> Vector n r Source # (*!!) :: r -> Matrix n m r -> Matrix n m r Source # (!!*) :: Matrix n m r -> r -> Matrix n m r Source # rows :: Lens' (Matrix n m r) (Vector n (Vector m r)) Source # row :: Int -> Matrix n m r -> Maybe (Vector m r) Source # column :: Int -> Matrix n m r -> Maybe (Vector n r) Source # |
class HasElements matrix matrix' where Source #
Types that have an elements
field lens.
elements :: IndexedTraversal1 (Int, Int) matrix matrix' (NumType matrix) (NumType matrix') Source #
IndexedTraversal over the elements of the matrix, each index is a (row,column) index pair.
class HasDeterminant (d :: Nat) where Source #
Dimensions for which we can compute the determinant of a matrix
Instances
class Invertible (n :: Nat) where Source #
Class of matrices that are invertible.
inverseMatrix :: (Fractional r, Matrix_ matrix n n r, Has_ Vector_ n r) => matrix -> matrix Source #
given an invertable square \(n \times n\) matrix A, computes the \(n \times n\) matrix B such that A !*! B = identityMatrix
Instances
Invertible 1 Source # | |
Defined in HGeometry.Matrix.Class inverseMatrix :: (Fractional r, Matrix_ matrix 1 1 r, Has_ Vector_ 1 r) => matrix -> matrix Source # | |
Invertible 2 Source # | |
Defined in HGeometry.Matrix.Class inverseMatrix :: (Fractional r, Matrix_ matrix 2 2 r, Has_ Vector_ 2 r) => matrix -> matrix Source # | |
Invertible 3 Source # | |
Defined in HGeometry.Matrix.Class inverseMatrix :: (Fractional r, Matrix_ matrix 3 3 r, Has_ Vector_ 3 r) => matrix -> matrix Source # |