HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduledense-linear-algebra-0.1.0.0Haskell2010

Statistics.Matrix

Basic matrix operations.

There isn't a widely used matrix package for Haskell yet, so we implement the necessary minimum here.

  • 2 types
  • 29 values

Data types

2 declarations
datadata Matrix
#

Two-dimensional matrix, stored in row-major order.

Constructors

Instances2Eq, Show
  • Eq MatrixDefined in dense-linear-algebra-0.1.0.0 · Statistics.Matrix.Types
  • Show MatrixDefined in dense-linear-algebra-0.1.0.0 · Statistics.Matrix.Types

Conversion fromto listsvectors

10 declarations
valuefromList
  1. :: Int

    Number of rows.

  2. -> Int

    Number of columns.

  3. -> [Double]

    Flat list of values, in row-major order.

  4. -> Matrix
#

Convert from a row-major list.

Other

19 declarations
valuegenerate
  1. :: Int

    Number of rows

  2. -> Int

    Number of columns

  3. -> (Int -> Int -> Double)

    Function which takes row and column as argument.

  4. -> Matrix
#

Generate matrix using function

valuegenerateSym
  1. :: Int

    Number of rows and columns

  2. -> (Int -> Int -> Double)

    Function which takes row and column as argument. It must be symmetric in arguments: f i j == f j i

  3. -> Matrix
#

Generate symmetric square matrix using function

valueident :: Int -> Matrix
#

Create the square identity matrix with given dimensions.

valuediag :: Vector -> Matrix
#

Create a square matrix with given diagonal, other entries default to 0

valuecenter :: Matrix -> Double
#

Element in the center of matrix (not corrected for exponent).

valuemultiply :: Matrix -> Matrix -> Matrix
#

Matrix-matrix multiplication. Matrices must be of compatible sizes (note: not checked).

valuepower :: Matrix -> Int -> Matrix
#

Raise matrix to nth power. Power must be positive (/note: not checked).

valuefor :: Monad m => Int -> Int -> (Int -> m ()) -> m ()
#

Simple for loop. Counts from start to end-1.

valuehasNaN :: Matrix -> Bool
#

Indicate whether any element of the matrix is NaN.

valuebounds :: (Vector -> Int -> r) -> Matrix -> Int -> Int -> r
#

Given row and column numbers, calculate the offset into the flat row-major vector.

valueunsafeBounds :: (Vector -> Int -> r) -> Matrix -> Int -> Int -> r
#

Given row and column numbers, calculate the offset into the flat row-major vector, without checking.