Portability | portable |
---|---|
Stability | experimental |
Maintainer | felipe.lessa@gmail.com |
Safe Haskell | Safe-Infered |
Implement matrices using plain Vector
s with data stored in
row-major order (i.e. the first elements correspond to the
first row).
- data Matrix = M {}
- size :: Matrix -> (Int, Int)
- (!) :: Matrix -> (Int, Int) -> Double
- replicate :: (Int, Int) -> Double -> Matrix
- replicateRows :: Int -> Vector Double -> Matrix
- fromVector :: (Vector v (w Double), Vector w Double) => v (w Double) -> Matrix
- fromVectorT :: (Vector v (w Double), Vector w Double) => v (w Double) -> Matrix
- rows :: Matrix -> Vector (Vector Double)
- (!!!) :: Matrix -> Int -> Vector Double
- cols :: Matrix -> Vector (Vector Double)
- col :: Matrix -> Int -> Vector Double
- umap :: (Vector Double -> Vector Double) -> Matrix -> Matrix
- map :: (Double -> Double) -> Matrix -> Matrix
- imap :: ((Int, Int) -> Double -> Double) -> Matrix -> Matrix
- rowmap :: (Vector Double -> Double) -> Matrix -> Vector Double
- irowmap :: (Int -> Vector Double -> Double) -> Matrix -> Vector Double
- uzipWith :: (Vector Double -> Vector Double -> Vector Double) -> Matrix -> Matrix -> Matrix
- zipWith :: (Double -> Double -> Double) -> Matrix -> Matrix -> Matrix
- izipWith :: ((Int, Int) -> Double -> Double -> Double) -> Matrix -> Matrix -> Matrix
- rzipWith :: (Int -> Vector Double -> Vector Double -> Vector Double) -> Matrix -> Matrix -> Matrix
- transpose :: Matrix -> Matrix
Basic
A matrix.
Constructing
fromVector :: (Vector v (w Double), Vector w Double) => v (w Double) -> MatrixSource
Creates a matrix from a vector of vectors. It *is not* verified that the vectors have the right length.
fromVectorT :: (Vector v (w Double), Vector w Double) => v (w Double) -> MatrixSource
Creates a matrix from a vector of vectors. The vectors are
transposed, so fromVectorT
is the same as transpose
. fromVector
. It *is* verified that the vectors have the
right length.
Rows
rows :: Matrix -> Vector (Vector Double)Source
O(rows) Rows of the matrix. Each element takes O(1) time and storage.
Columns
cols :: Matrix -> Vector (Vector Double)Source
O(rows*cols) Columns of the matrix. Each element takes O(rows) time and storage.
Maps and zips
rzipWith :: (Int -> Vector Double -> Vector Double -> Vector Double) -> Matrix -> Matrix -> MatrixSource
rzipWith f m n
is a matrix with the same number of rows as
m
. The i
-th row is obtained by applying f
to the i
-th
rows of m
and n
.