-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/

-- | Simple and incomplete pure haskell implementation of linear algebra
--   
--   This library is simply collection of linear-algebra related modules
--   split from statistics library.
@package dense-linear-algebra
@version 0.1.0.0

module Statistics.Matrix.Function

-- | Multiply a number by itself.
square :: Double -> Double

-- | Simple for loop. Counts from start to end-1.
for :: Monad m => Int -> Int -> (Int -> m ()) -> m ()

-- | Basic matrix operations.
--   
--   There isn't a widely used matrix package for Haskell yet, so we
--   implement the necessary minimum here.
module Statistics.Matrix.Types
type Vector = Vector Double
type MVector s = MVector s Double

-- | Two-dimensional matrix, stored in row-major order.
data Matrix
Matrix :: {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> !Vector -> Matrix

-- | Rows of matrix.
[rows] :: Matrix -> {-# UNPACK #-} !Int

-- | Columns of matrix.
[cols] :: Matrix -> {-# UNPACK #-} !Int

-- | Matrix data.
[_vector] :: Matrix -> !Vector

-- | Two-dimensional mutable matrix, stored in row-major order.
data MMatrix s
MMatrix :: {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> !MVector s -> MMatrix s
debug :: Matrix -> String
instance GHC.Classes.Eq Statistics.Matrix.Types.Matrix
instance GHC.Internal.Show.Show Statistics.Matrix.Types.Matrix

-- | Basic mutable matrix operations.
module Statistics.Matrix.Mutable

-- | Two-dimensional mutable matrix, stored in row-major order.
data MMatrix s
MMatrix :: {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> !MVector s -> MMatrix s
type MVector s = MVector s Double
replicate :: Int -> Int -> Double -> ST s (MMatrix s)
thaw :: Matrix -> ST s (MMatrix s)

-- | Given row and column numbers, calculate the offset into the flat
--   row-major vector.
bounds :: MMatrix s -> Int -> Int -> (MVector s -> Int -> r) -> r

-- | Allocate new matrix. Matrix content is not initialized hence unsafe.
unsafeNew :: Int -> Int -> ST s (MMatrix s)
unsafeFreeze :: MMatrix s -> ST s Matrix
unsafeRead :: MMatrix s -> Int -> Int -> ST s Double
unsafeWrite :: MMatrix s -> Int -> Int -> Double -> ST s ()
unsafeModify :: MMatrix s -> Int -> Int -> (Double -> Double) -> ST s ()
immutably :: NFData a => MMatrix s -> (Matrix -> a) -> ST s a

-- | Given row and column numbers, calculate the offset into the flat
--   row-major vector, without checking.
unsafeBounds :: MMatrix s -> Int -> Int -> (MVector s -> Int -> r) -> r

-- | Basic matrix operations.
--   
--   There isn't a widely used matrix package for Haskell yet, so we
--   implement the necessary minimum here.
module Statistics.Matrix

-- | Two-dimensional matrix, stored in row-major order.
data Matrix
Matrix :: {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> !Vector -> Matrix

-- | Rows of matrix.
[rows] :: Matrix -> {-# UNPACK #-} !Int

-- | Columns of matrix.
[cols] :: Matrix -> {-# UNPACK #-} !Int

-- | Matrix data.
[_vector] :: Matrix -> !Vector
type Vector = Vector Double

-- | Convert from a row-major vector.
fromVector :: Int -> Int -> Vector Double -> Matrix

-- | Convert from a row-major list.
fromList :: Int -> Int -> [Double] -> Matrix

-- | create a matrix from a list of lists, as rows
fromRowLists :: [[Double]] -> Matrix

-- | create a matrix from a list of vectors, as rows
fromRows :: [Vector] -> Matrix

-- | create a matrix from a list of vectors, as columns
fromColumns :: [Vector] -> Matrix

-- | Convert to a row-major flat vector.
toVector :: Matrix -> Vector Double

-- | Convert to a row-major flat list.
toList :: Matrix -> [Double]

-- | Convert to a list of vectors, as rows
toRows :: Matrix -> [Vector]

-- | Convert to a list of vectors, as columns
toColumns :: Matrix -> [Vector]

-- | Convert to a list of lists, as rows
toRowLists :: Matrix -> [[Double]]

-- | Generate matrix using function
generate :: Int -> Int -> (Int -> Int -> Double) -> Matrix

-- | Generate symmetric square matrix using function
generateSym :: Int -> (Int -> Int -> Double) -> Matrix

-- | Create the square identity matrix with given dimensions.
ident :: Int -> Matrix

-- | Create a square matrix with given diagonal, other entries default to 0
diag :: Vector -> Matrix

-- | Return the dimensions of this matrix, as a (row,column) pair.
dimension :: Matrix -> (Int, Int)

-- | Element in the center of matrix (not corrected for exponent).
center :: Matrix -> Double

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

-- | Matrix-vector multiplication.
multiplyV :: Matrix -> Vector -> Vector
transpose :: Matrix -> Matrix

-- | Raise matrix to nth power. Power must be positive (/note: not
--   checked).
power :: Matrix -> Int -> Matrix

-- | Calculate the Euclidean norm of a vector.
norm :: Vector -> Double

-- | Return the given column.
column :: Matrix -> Int -> Vector

-- | Return the given row.
row :: Matrix -> Int -> Vector

-- | Apply function to every element of matrix
map :: (Double -> Double) -> Matrix -> Matrix

-- | Simple for loop. Counts from start to end-1.
for :: Monad m => Int -> Int -> (Int -> m ()) -> m ()
unsafeIndex :: Matrix -> Int -> Int -> Double

-- | Indicate whether any element of the matrix is NaN.
hasNaN :: Matrix -> Bool

-- | Given row and column numbers, calculate the offset into the flat
--   row-major vector.
bounds :: (Vector -> Int -> r) -> Matrix -> Int -> Int -> r

-- | Given row and column numbers, calculate the offset into the flat
--   row-major vector, without checking.
unsafeBounds :: (Vector -> Int -> r) -> Matrix -> Int -> Int -> r

-- | Useful matrix functions.
module Statistics.Matrix.Algorithms

-- | O(r*c) Compute the QR decomposition of a matrix. The result
--   returned is the matrices (q,r).
qr :: Matrix -> (Matrix, Matrix)
