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


-- | Numerical computing in native Haskell
--   
--   <i>Overview</i>
--   
--   The <tt>sparse-linear-algebra</tt> library provides iterative linear
--   solvers, matrix decompositions, eigenvalue algorithms and related
--   utilities. The user interface is provided by the top-level module
--   <a>Numeric.LinearAlgebra.Sparse</a>:
--   
--   <pre>
--   import           Numeric.LinearAlgebra.Sparse
--   </pre>
--   
--   Please refer to the README file for usage examples.
@package sparse-linear-algebra
@version 0.2.9.9

module Control.Exception.Common

-- | Errors associated with partial functions
data PartialFunctionError
EmptyList :: String -> PartialFunctionError

-- | Input errors
data InputError
NonNegError :: String -> Int -> InputError

-- | Out of bounds index errors
data OutOfBoundsIndexError i
OOBIxError :: String -> i -> OutOfBoundsIndexError i
OOBIxsError :: String -> [i] -> OutOfBoundsIndexError i
OOBNoCompatRows :: String -> (i, i) -> OutOfBoundsIndexError i
checkIxBound :: MonadThrow m => String -> Int -> UB -> m a -> m a

-- | Operand size mismatch errors
data OperandSizeMismatch
DotSizeMismatch :: Int -> Int -> OperandSizeMismatch
NonTriangularException :: String -> OperandSizeMismatch
MatVecSizeMismatchException :: String -> (Int, Int) -> Int -> OperandSizeMismatch

-- | Matrix exceptions
data MatrixException i
HugeConditionNumber :: String -> i -> MatrixException i
NeedsPivoting :: String -> String -> MatrixException i

-- | Numerical iteration errors
data IterationException a
NotConvergedE :: String -> Int -> a -> IterationException a
DivergingE :: String -> Int -> a -> a -> IterationException a
instance GHC.Classes.Eq a => GHC.Classes.Eq (Control.Exception.Common.IterationException a)
instance GHC.Classes.Eq i => GHC.Classes.Eq (Control.Exception.Common.MatrixException i)
instance GHC.Classes.Eq Control.Exception.Common.OperandSizeMismatch
instance GHC.Classes.Eq i => GHC.Classes.Eq (Control.Exception.Common.OutOfBoundsIndexError i)
instance GHC.Classes.Eq Control.Exception.Common.InputError
instance GHC.Classes.Eq Control.Exception.Common.PartialFunctionError
instance GHC.Show.Show a => GHC.Show.Show (Control.Exception.Common.IterationException a)
instance (GHC.Show.Show a, Data.Typeable.Internal.Typeable a) => GHC.Exception.Exception (Control.Exception.Common.IterationException a)
instance GHC.Show.Show i => GHC.Show.Show (Control.Exception.Common.MatrixException i)
instance (GHC.Show.Show i, Data.Typeable.Internal.Typeable i) => GHC.Exception.Exception (Control.Exception.Common.MatrixException i)
instance GHC.Show.Show Control.Exception.Common.OperandSizeMismatch
instance GHC.Exception.Exception Control.Exception.Common.OperandSizeMismatch
instance GHC.Show.Show i => GHC.Show.Show (Control.Exception.Common.OutOfBoundsIndexError i)
instance (GHC.Show.Show i, Data.Typeable.Internal.Typeable i) => GHC.Exception.Exception (Control.Exception.Common.OutOfBoundsIndexError i)
instance GHC.Show.Show Control.Exception.Common.InputError
instance GHC.Exception.Exception Control.Exception.Common.InputError
instance GHC.Show.Show Control.Exception.Common.PartialFunctionError
instance GHC.Exception.Exception Control.Exception.Common.PartialFunctionError


-- | Testing for values "near" zero
module Numeric.Eps

-- | Provides a test to see if a quantity is near zero.
--   
--   <pre>
--   &gt;&gt;&gt; nearZero (1e-11 :: Double)
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; nearZero (1e-17 :: Double)
--   True
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; nearZero (1e-5 :: Float)
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; nearZero (1e-7 :: Float)
--   True
--   </pre>
class (Floating a, Num a) => Epsilon a

-- | Determine if a quantity is near zero.
nearZero :: Epsilon a => a -> Bool

-- | Is this quantity distinguishable from 0 ?
isNz :: Epsilon a => a -> Bool
roundZero :: Epsilon a => a -> a
roundOne :: Epsilon a => a -> a

-- | Round to respectively 0 or 1
roundZeroOne :: Epsilon a => a -> a

-- | Is this quantity close to 1 ?
nearOne :: Epsilon a => a -> Bool
instance Numeric.Eps.Epsilon GHC.Types.Float
instance Numeric.Eps.Epsilon GHC.Types.Double
instance Numeric.Eps.Epsilon Foreign.C.Types.CFloat
instance Numeric.Eps.Epsilon Foreign.C.Types.CDouble
instance Numeric.Eps.Epsilon (Data.Complex.Complex GHC.Types.Float)
instance Numeric.Eps.Epsilon (Data.Complex.Complex GHC.Types.Double)
instance Numeric.Eps.Epsilon (Data.Complex.Complex Foreign.C.Types.CFloat)
instance Numeric.Eps.Epsilon (Data.Complex.Complex Foreign.C.Types.CDouble)


-- | Typeclasses for linear algebra and related concepts
module Numeric.LinearAlgebra.Class
class (Eq e, Fractional e, Floating e, Num (EltMag e), Ord (EltMag e)) => Elt e where {
    type family EltMag e :: *;
}

-- | Complex conjugate, or identity function if its input is real-valued
conj :: Elt e => e -> e

-- | Magnitude
mag :: Elt e => e -> EltMag e
class AdditiveGroup v

-- | The zero element: identity for '(^+^)'
zeroV :: AdditiveGroup v => v

-- | Add vectors
(^+^) :: AdditiveGroup v => v -> v -> v

-- | Additive inverse
negateV :: AdditiveGroup v => v -> v

-- | Group subtraction
(^-^) :: AdditiveGroup v => v -> v -> v
class (AdditiveGroup v, Num (Scalar v)) => VectorSpace v where {
    type family Scalar v :: *;
}

-- | Scale a vector
(.*) :: VectorSpace v => Scalar v -> v -> v

-- | Adds inner (dot) products.
class (VectorSpace v, AdditiveGroup (Scalar v)) => InnerSpace v

-- | Inner/dot product
(<.>) :: InnerSpace v => v -> v -> Scalar v

-- | Inner product
dot :: InnerSpace v => v -> v -> Scalar v

-- | Scale a vector by the reciprocal of a number (e.g. for normalization)
(./) :: (VectorSpace v, s ~ Scalar v, Fractional s) => v -> s -> v
infixr 7 ./

-- | Vector multiplied by scalar
(*.) :: (VectorSpace v, s ~ Scalar v) => v -> s -> v
infixl 7 *.

-- | Convex combination of two vectors (NB: 0 &lt;= <tt>a</tt> &lt;= 1).
cvx :: VectorSpace v => Scalar v -> v -> v -> v

-- | `hilbertDistSq x y = || x - y ||^2` computes the squared L2 distance
--   between two vectors
hilbertDistSq :: InnerSpace v => v -> v -> Scalar v
class (InnerSpace v, Num (RealScalar v), Eq (RealScalar v), Epsilon (Magnitude v), Show (Magnitude v), Ord (Magnitude v)) => Normed v where {
    type family Magnitude v :: *;
    type family RealScalar v :: *;
}

-- | L1 norm
norm1 :: Normed v => v -> Magnitude v

-- | Euclidean (L2) norm squared
norm2Sq :: Normed v => v -> Magnitude v

-- | Lp norm (p &gt; 0)
normP :: Normed v => RealScalar v -> v -> Magnitude v

-- | Normalize w.r.t. Lp norm
normalize :: Normed v => RealScalar v -> v -> v

-- | Normalize w.r.t. L2 norm
normalize2 :: Normed v => v -> v

-- | Normalize w.r.t. norm2' instead of norm2
normalize2' :: (Normed v, Floating (Scalar v)) => v -> v

-- | Euclidean (L2) norm
norm2 :: (Normed v, Floating (Magnitude v)) => v -> Magnitude v

-- | Euclidean (L2) norm; returns a Complex (norm :+ 0) for Complex-valued
--   vectors
norm2' :: (Normed v, Floating (Scalar v)) => v -> Scalar v

-- | Lp norm (p &gt; 0)
norm :: (Normed v, Floating (Magnitude v)) => RealScalar v -> v -> Magnitude v

-- | Infinity-norm (Real)
normInftyR :: (Foldable t, Ord a) => t a -> a

-- | Infinity-norm (Complex)
normInftyC :: (Foldable t, RealFloat a, Functor t) => t (Complex a) -> a

-- | Lp inner product (p &gt; 0)
dotLp :: (Set t, Foldable t, Floating a) => a -> t a -> t a -> a

-- | Reciprocal
reciprocal :: (Functor f, Fractional b) => f b -> f b

-- | Scale
scale :: (Num b, Functor f) => b -> f b -> f b

-- | A matrix ring is any collection of matrices over some ring R that form
--   a ring under matrix addition and matrix multiplication
class (AdditiveGroup m, Epsilon (MatrixNorm m)) => MatrixRing m where {
    type family MatrixNorm m :: *;
}

-- | Matrix-matrix product
(##) :: MatrixRing m => m -> m -> m

-- | Matrix times matrix transpose (A B^T)
(##^) :: MatrixRing m => m -> m -> m

-- | Matrix transpose times matrix (A^T B)
(#^#) :: MatrixRing m => m -> m -> m

-- | Matrix transpose (Hermitian conjugate in the Complex case)
transpose :: MatrixRing m => m -> m

-- | Frobenius norm
normFrobenius :: MatrixRing m => m -> MatrixNorm m
class (VectorSpace v, MatrixRing (MatrixType v)) => LinearVectorSpace v where {
    type family MatrixType v :: *;
}

-- | Matrix-vector action
(#>) :: LinearVectorSpace v => MatrixType v -> v -> v

-- | Dual matrix-vector action
(<#) :: LinearVectorSpace v => v -> MatrixType v -> v
type V v = (LinearVectorSpace v, Normed v)
class LinearVectorSpace v => LinearSystem v

-- | Solve a linear system; uses GMRES internally as default method
(<\>) :: (LinearSystem v, MonadIO m, MonadThrow m) => MatrixType v -> v -> m v
class FiniteDim f where {
    type family FDSize f;
}

-- | Dimension (i.e. Int for SpVector, (Int, Int) for SpMatrix)
dim :: FiniteDim f => f -> FDSize f
class HasData f where {
    type family HDData f;
}

-- | Number of nonzeros
nnz :: HasData f => f -> Int
dat :: HasData f => f -> HDData f
class (FiniteDim f, HasData f) => Sparse f

-- | Sparsity (fraction of nonzero elements)
spy :: (Sparse f, Fractional b) => f -> b
class Functor f => Set f

-- | Union binary lift : apply function on _union_ of two "sets"
liftU2 :: Set f => (a -> a -> a) -> f a -> f a -> f a

-- | Intersection binary lift : apply function on _intersection_ of two
--   "sets"
liftI2 :: Set f => (a -> a -> b) -> f a -> f a -> f b
class Sparse c => SpContainer c where {
    type family ScIx c :: *;
    type family ScElem c;
}
scInsert :: SpContainer c => ScIx c -> ScElem c -> c -> c
scLookup :: SpContainer c => c -> ScIx c -> Maybe (ScElem c)
scToList :: SpContainer c => c -> [(ScIx c, ScElem c)]
(@@) :: SpContainer c => c -> ScIx c -> ScElem c
class SpContainer v => SparseVector v where {
    type family SpvIx v :: *;
}
svFromList :: SparseVector v => Int -> [(SpvIx v, ScElem v)] -> v
svFromListDense :: SparseVector v => Int -> [ScElem v] -> v
svConcat :: (SparseVector v, Foldable t) => t v -> v
class SpContainer m => SparseMatrix m
smFromVector :: SparseMatrix m => LexOrd -> (Int, Int) -> Vector (IxRow, IxCol, ScElem m) -> m
smTranspose :: SparseMatrix m => m -> m
encodeIx :: SparseMatrix m => m -> LexOrd -> (IxRow, IxCol) -> LexIx
decodeIx :: SparseMatrix m => m -> LexOrd -> LexIx -> (IxRow, IxCol)

-- | Lift a real number onto the complex plane
toC :: Num a => a -> Complex a
instance Numeric.LinearAlgebra.Class.Elt GHC.Types.Double
instance Numeric.LinearAlgebra.Class.Elt GHC.Types.Float
instance GHC.Float.RealFloat e => Numeric.LinearAlgebra.Class.Elt (Data.Complex.Complex e)


module Data.Sparse.SpVector
data SpVector a
SV :: {-# UNPACK #-} !Int -> !(IntM a) -> SpVector a
[svDim] :: SpVector a -> {-# UNPACK #-} !Int
[svData] :: SpVector a -> !(IntM a)

-- | SpVector density
spySV :: Fractional b => SpVector a -> b

-- | Number of nonzeros
nzSV :: SpVector a -> Int
sizeStrSV :: SpVector a -> String
foldlWithKeySV :: (a -> Key -> b -> a) -> a -> SpVector b -> a
foldlWithKeySV' :: (a -> Key -> b -> a) -> a -> SpVector b -> a

-- | <a>SpVector</a>s form a vector space because they can be multiplied by
--   a scalar
--   
--   <a>SpVector</a>s are finite-dimensional vectors

-- | <a>SpVector</a>s are sparse containers too, i.e. any specific
--   component may be missing (so it is assumed to be 0)
dotS :: InnerSpace (IntM t) => SpVector t -> SpVector t -> Scalar (IntM t)
dotSSafe :: (InnerSpace (IntM t), MonadThrow m) => SpVector t -> SpVector t -> m (Scalar (IntM t))

-- | Empty sparse vector (length n, no entries)
zeroSV :: Int -> SpVector a

-- | Singleton sparse vector (length 1)
singletonSV :: a -> SpVector a

-- | Canonical basis vector in R^n
ei :: Num a => Int -> Key -> SpVector a

-- | Sparse vector from an association list while discarding all zero
--   entries
mkSpVector :: Epsilon a => Int -> IntMap a -> SpVector a
mkSpVector1 :: Int -> IntMap a -> SpVector a

-- | Dense real SpVector (monomorphic Double)
mkSpVR :: Int -> [Double] -> SpVector Double

-- | Dense complex SpVector (monomorphic Double)
mkSpVC :: Int -> [Complex Double] -> SpVector (Complex Double)

-- | Create new sparse vector, assumin 0-based, contiguous indexing
fromListDenseSV :: Int -> [a] -> SpVector a

-- | Map a function over a range of indices and filter the result (indices
--   and values) to fit in a <tt>n</tt>-long SpVector
spVectorDenseIx :: Epsilon a => (Int -> a) -> UB -> [Int] -> SpVector a

-- | ", using just the integer bounds of the interval
spVectorDenseLoHi :: Epsilon a => (Int -> a) -> UB -> Int -> Int -> SpVector a

-- | one-hot encoding : `oneHotSV n k` produces a SpVector of length n
--   having 1 at the k-th position
oneHotSVU :: Num a => Int -> IxRow -> SpVector a
oneHotSV :: Num a => Int -> IxRow -> SpVector a

-- | DENSE vector of `1`s
onesSV :: Num a => Int -> SpVector a

-- | DENSE vector of `0`s
zerosSV :: Num a => Int -> SpVector a

-- | DENSE vector with constant elements
constv :: Int -> a -> SpVector a

-- | Populate a SpVector with the contents of a Vector.
fromVector :: Vector a -> SpVector a

-- | Populate a Vector with the entries of a SpVector, discarding the
--   indices (NB: loses sparsity information).
toVector :: SpVector a -> Vector a

-- | Populate a Vector with the entries of a SpVector, replacing the
--   missing entries with 0
toVectorDense :: Num a => SpVector a -> Vector a

-- | insert element <tt>x</tt> at index <tt>i</tt> in a preexisting
--   SpVector; discards out-of-bounds entries
insertSpVector :: Key -> a -> SpVector a -> SpVector a
insertSpVectorSafe :: MonadThrow m => Int -> a -> SpVector a -> m (SpVector a)

-- | Create new SpVector using data from a Foldable (e.g. a list) in
--   (index, value) form
fromListSV :: Foldable t => Int -> t (Int, a) -> SpVector a
createv :: [a] -> SpVector a

-- | Create a <i>dense</i> SpVector from a list of Double's
vr :: [Double] -> SpVector Double

-- | Create a <i>dense</i> SpVector from a list of Complex Double's
vc :: [Complex Double] -> SpVector (Complex Double)

-- | Populate a list with SpVector contents
toListSV :: SpVector a -> [(Int, a)]

-- | To dense list (default = 0)
toDenseListSV :: Num b => SpVector b -> [b]

-- | Indexed fold over SpVector
ifoldSV :: (Key -> a -> b -> b) -> b -> SpVector a -> b

-- | Lookup an index in a SpVector
lookupSV :: Key -> SpVector a -> Maybe a

-- | Lookup an index, return a default value if lookup fails
lookupDefaultSV :: a -> Key -> SpVector a -> a

-- | Lookup an index in a SpVector, returns 0 if lookup fails
lookupDenseSV :: Num a => Key -> SpVector a -> a

-- | Tail elements
tailSV :: SpVector a -> SpVector a

-- | Head element
headSV :: Num a => SpVector a -> a

-- | Keep the first n components of the SpVector (like <a>take</a> for
--   lists)
takeSV :: Int -> SpVector a -> SpVector a

-- | Discard the first n components of the SpVector and rebalance the keys
--   (like <a>drop</a> for lists)
--   
--   Keep the first n components of the SpVector (like <a>take</a> for
--   lists)
dropSV :: Int -> SpVector a -> SpVector a

-- | Keep a range of entries
rangeSV :: (Key, Key) -> SpVector a -> SpVector a

-- | Concatenate two sparse vectors
concatSV :: SpVector a -> SpVector a -> SpVector a

-- | Filter
filterSV :: (a -> Bool) -> SpVector a -> SpVector a

-- | Indexed filter
ifilterSV :: (Int -> a -> Bool) -> SpVector a -> SpVector a

-- | Sparsify an SpVector
sparsifySV :: Epsilon a => SpVector a -> SpVector a

-- | Generate an arbitrary (not random) vector <tt>u</tt> such that `v dot
--   u = 0`
orthogonalSV :: (Scalar (SpVector t) ~ t, InnerSpace (SpVector t), Fractional t) => SpVector t -> SpVector t
instance GHC.Classes.Eq a => GHC.Classes.Eq (Data.Sparse.SpVector.SpVector a)
instance GHC.Show.Show a => GHC.Show.Show (Data.Sparse.SpVector.SpVector a)
instance GHC.Base.Functor Data.Sparse.SpVector.SpVector
instance Numeric.LinearAlgebra.Class.Set Data.Sparse.SpVector.SpVector
instance Data.Foldable.Foldable Data.Sparse.SpVector.SpVector
instance Numeric.LinearAlgebra.Class.FiniteDim (Data.Sparse.SpVector.SpVector a)
instance Numeric.LinearAlgebra.Class.HasData (Data.Sparse.SpVector.SpVector a)
instance Numeric.LinearAlgebra.Class.Sparse (Data.Sparse.SpVector.SpVector a)
instance Numeric.LinearAlgebra.Class.Elt a => Numeric.LinearAlgebra.Class.SpContainer (Data.Sparse.SpVector.SpVector a)


module Data.Sparse.SpMatrix
data SpMatrix a
SM :: {-# UNPACK #-} !(Rows, Cols) -> !(IntM (IntM a)) -> SpMatrix a
[smDim] :: SpMatrix a -> {-# UNPACK #-} !(Rows, Cols)
[smData] :: SpMatrix a -> !(IntM (IntM a))
sizeStrSM :: SpMatrix a -> String

-- | <a>SpMatrix</a>es form an additive group, in that they can have an
--   invertible associtative operation (matrix sum)

-- | <a>SpMatrix</a>es are maps between finite-dimensional spaces

-- | <a>SpMatrix</a>es are sparse containers too, i.e. any specific
--   component may be missing (so it is assumed to be 0)

-- | `zeroSM m n` : Empty SpMatrix of size (m, n)
zeroSM :: Rows -> Cols -> SpMatrix a

-- | `mkDiagonal n ll` : create a diagonal matrix of size <tt>n</tt> from a
--   list <tt>ll</tt> of elements
mkDiagonal :: Int -> [a] -> SpMatrix a

-- | `eye n` : identity matrix of rank <tt>n</tt>
eye :: Num a => Int -> SpMatrix a

-- | Permutation matrix from a (possibly incomplete) list of row swaps
--   starting from row 0 e.g. `permutationSM 5 [1,3]` first swaps rows (0,
--   1) and then rows (1, 3) :
--   
--   <pre>
--   &gt;&gt;&gt; prd (permutationSM 5 [1,3] :: SpMatrix Double)
--   </pre>
--   
--   <pre>
--   ( 5 rows, 5 columns ) , 5 NZ ( density 20.000 % )
--   
--   _      , 1.00   , _      , _      , _      
--   _      , _      , _      , 1.00   , _      
--   _      , _      , 1.00   , _      , _      
--   1.00   , _      , _      , _      , _      
--   _      , _      , _      , _      , 1.00
--   </pre>
permutationSM :: Num a => Int -> [IxRow] -> SpMatrix a

-- | Permutation matrix from a (possibly incomplete) list of row pair swaps
--   e.g. `permutPairs 5 [(2,4)]` swaps rows 2 and 4 :
--   
--   <pre>
--   &gt;&gt;&gt; prd (permutPairsSM 5 [(2,4)] :: SpMatrix Double)
--   </pre>
--   
--   <pre>
--   ( 5 rows, 5 columns ) , 5 NZ ( density 20.000 % )
--   
--   1.00   , _      , _      , _      , _      
--   _      , 1.00   , _      , _      , _      
--   _      , _      , _      , _      , 1.00   
--   _      , _      , _      , 1.00   , _      
--   _      , _      , 1.00   , _      , _
--   </pre>
permutPairsSM :: Num a => Int -> [(IxRow, IxRow)] -> SpMatrix a

-- | `mkSubDiagonal n o xx` creates a square SpMatrix of size <tt>n</tt>
--   with <tt>xx</tt> on the <tt>o</tt>th subdiagonal
mkSubDiagonal :: Int -> Int -> [a] -> SpMatrix a

-- | Insert an element in a preexisting Spmatrix at the specified indices
insertSpMatrix :: IxRow -> IxCol -> a -> SpMatrix a -> SpMatrix a

-- | Add to existing SpMatrix using data from list (row, col, value)
fromListSM' :: Foldable t => t (IxRow, IxCol, a) -> SpMatrix a -> SpMatrix a

-- | Create new SpMatrix using data from a Foldable (e.g. a list) in (row,
--   col, value) form
fromListSM :: Foldable t => (Int, Int) -> t (IxRow, IxCol, a) -> SpMatrix a
mkSpMR :: Foldable t => (Int, Int) -> t (IxRow, IxCol, Double) -> SpMatrix Double
mkSpMC :: Foldable t => (Int, Int) -> t (IxRow, IxCol, Complex Double) -> SpMatrix (Complex Double)

-- | Create new SpMatrix assuming contiguous, 0-based indexing of elements
fromListDenseSM :: Int -> [a] -> SpMatrix a

-- | Populate list with SpMatrix contents
toListSM :: SpMatrix t -> [(IxRow, IxCol, t)]

-- | Populate list with SpMatrix contents and populate missing entries with
--   0
toDenseListSM :: Num t => SpMatrix t -> [(IxRow, IxCol, t)]
lookupSM :: SpMatrix a -> IxRow -> IxCol -> Maybe a

-- | Looks up an element in the matrix with a default (if the element is
--   not found, zero is returned)
lookupWD_SM :: Num a => SpMatrix a -> (IxRow, IxCol) -> a

-- | Zero-default lookup, infix form (no bound checking)
--   
--   Looks up an element in the matrix with a default (if the element is
--   not found, zero is returned)
(@@!) :: Num a => SpMatrix a -> (IxRow, IxCol) -> a

-- | Indexed filtering function
filterSM :: (Key -> Key -> a -> Bool) -> SpMatrix a -> SpMatrix a

-- | Diagonal, subdiagonal, superdiagonal partitions of a SpMatrix (useful
--   for writing preconditioners)
extractDiag :: SpMatrix a -> SpMatrix a

-- | Diagonal, subdiagonal, superdiagonal partitions of a SpMatrix (useful
--   for writing preconditioners)
extractSuperDiag :: SpMatrix a -> SpMatrix a

-- | Diagonal, subdiagonal, superdiagonal partitions of a SpMatrix (useful
--   for writing preconditioners)
extractSubDiag :: SpMatrix a -> SpMatrix a

-- | Extract a submatrix given the specified index bounds, rebalancing keys
--   with the two supplied functions
extractSubmatrixSM :: (Key -> Key) -> (Key -> Key) -> SpMatrix a -> (IxRow, IxRow) -> (IxCol, IxCol) -> SpMatrix a

-- | Extract a submatrix given the specified index bounds NB : subtracts
--   (i1, j1) from the indices
extractSubmatrixRebalanceKeys :: SpMatrix a -> (IxRow, IxRow) -> (IxCol, IxCol) -> SpMatrix a

-- | Extract a submatrix given the specified index bounds NB : submatrix
--   indices are _preserved_
extractSubmatrix :: SpMatrix a -> (IxRow, IxRow) -> (IxCol, IxCol) -> SpMatrix a
takeRows :: IxRow -> SpMatrix a -> SpMatrix a
takeCols :: IxCol -> SpMatrix a -> SpMatrix a

-- | Extract whole column
extractColSM :: SpMatrix a -> IxCol -> SpMatrix a

-- | Extract column within a row range
extractSubColSM :: SpMatrix a -> IxCol -> (IxRow, IxRow) -> SpMatrix a

-- | Extract column within a row range, rebalance keys
extractSubColSM_RK :: SpMatrix a -> IxCol -> (IxRow, IxRow) -> SpMatrix a

-- | Are the supplied indices within matrix bounds?
isValidIxSM :: SpMatrix a -> (Int, Int) -> Bool

-- | Is the matrix square?
isSquareSM :: SpMatrix a -> Bool

-- | Is the matrix diagonal?
isDiagonalSM :: SpMatrix a -> Bool

-- | Is the matrix lower/upper triangular?
isLowerTriSM :: Eq a => SpMatrix a -> Bool

-- | Is the matrix lower/upper triangular?
isUpperTriSM :: Eq a => SpMatrix a -> Bool

-- | Is the matrix orthogonal? i.e. Q^t ## Q == I
isOrthogonalSM :: (Eq a, Epsilon a, MatrixRing (SpMatrix a)) => SpMatrix a -> Bool

-- | Data in internal representation (do not export) immSM :: SpMatrix t
--   -&gt; IM.IntMap (IM.IntMap t)
immSM :: () => SpMatrix a -> IntM IntM a

-- | (Number of rows, Number of columns)
dimSM :: SpMatrix t -> (Rows, Cols)

-- | Number of rows times number of columns
nelSM :: SpMatrix t -> Int

-- | Number of rows
nrows :: SpMatrix a -> Rows

-- | Number of columns
ncols :: SpMatrix a -> Cols
data SMInfo
SMInfo :: Int -> Double -> SMInfo
[smNz] :: SMInfo -> Int
[smSpy] :: SMInfo -> Double
infoSM :: SpMatrix a -> SMInfo
nzSM :: SpMatrix a -> Int
spySM :: Fractional b => SpMatrix a -> b
nzRow :: SpMatrix a -> Key -> Int
bwMinSM :: SpMatrix a -> Int
bwMaxSM :: SpMatrix a -> Int
bwBoundsSM :: SpMatrix a -> (Int, Int)

-- | Vertical stacking of matrix blocks
vertStackSM :: SpMatrix a -> SpMatrix a -> SpMatrix a

-- | Vertical stacking of matrix blocks
(-=-) :: SpMatrix a -> SpMatrix a -> SpMatrix a

-- | Horizontal stacking of matrix blocks
horizStackSM :: SpMatrix a -> SpMatrix a -> SpMatrix a

-- | Horizontal stacking of matrix blocks
(-||-) :: SpMatrix a -> SpMatrix a -> SpMatrix a

-- | Assemble a block-diagonal square matrix from a list of square
--   matrices, arranging these along the main diagonal
fromBlocksDiag :: [SpMatrix a] -> SpMatrix a

-- | Indexed filter over SpMatrix
ifilterSM :: (Key -> Key -> a -> Bool) -> SpMatrix a -> SpMatrix a

-- | Left fold over SpMatrix
foldlSM :: (a -> b -> b) -> b -> SpMatrix a -> b

-- | Indexed left fold over SpMatrix
ifoldlSM :: (Key -> Key -> a -> b -> b) -> b -> SpMatrix a -> b

-- | Count sub-diagonal nonzeros
countSubdiagonalNZSM :: SpMatrix a -> Int

-- | Filter the index subset that lies below the diagonal (used in the QR
--   decomposition, for example)
subdiagIndicesSM :: SpMatrix a -> [(IxRow, IxCol)]
sparsifyIM2 :: Epsilon a => IntM (IntM a) -> IntM (IntM a)

-- | Sparsify an SpMatrix
sparsifySM :: Epsilon a => SpMatrix a -> SpMatrix a

-- | Round almost-0 and almost-1 to 0 and 1 respectively
roundZeroOneSM :: Epsilon a => SpMatrix a -> SpMatrix a

-- | Modify (row, column) keys, leaving data intact. Be careful when using
--   this! modifyKeysSM' :: (IxRow -&gt; IxRow) -&gt; (IxCol -&gt; IxCol)
--   -&gt; SpMatrix a -&gt; SpMatrix a
modifyKeysSM' :: (IxRow -> a) -> (IxCol -> b) -> SpMatrix c -> [(a, b, c)]
modifyKeysSM :: (IxRow -> IxRow) -> (IxCol -> IxCol) -> SpMatrix a -> SpMatrix a

-- | Swap two rows of a SpMatrix (bounds not checked)
swapRows :: IxRow -> IxRow -> SpMatrix a -> SpMatrix a

-- | Swap two rows of a SpMatrix (bounds checked)
swapRowsSafe :: IxRow -> IxRow -> SpMatrix a -> SpMatrix a

-- | transposeSM : Matrix transpose
transposeSM :: SpMatrix a -> SpMatrix a

-- | Hermitian conjugate
hermitianConj :: Num a => SpMatrix (Complex a) -> SpMatrix (Complex a)
matScale :: Num a => a -> SpMatrix a -> SpMatrix a

-- | Matrix trace
trace :: Num b => SpMatrix b -> b
normFrobeniusSM :: (MatrixRing (SpMatrix a), Floating a) => SpMatrix a -> a
normFrobeniusSMC :: (MatrixRing (SpMatrix (Complex a)), RealFloat a) => SpMatrix (Complex a) -> a

-- | Internal implementation
data MatProd_
AB :: MatProd_
ABt :: MatProd_
matMat_ :: Num a => MatProd_ -> SpMatrix a -> SpMatrix a -> SpMatrix a

-- | Matrix product without dimension checks
matMatUnsafeWith :: Num a1 => (IntM IntM a2 -> IntM IntM a1) -> SpMatrix a1 -> SpMatrix a2 -> SpMatrix a1

-- | After multiplying the two matrices, all elements <tt>x</tt> for which
--   `| x | &lt;= eps` are removed.
matMatSparsified :: (MatrixRing (SpMatrix a), Epsilon a) => SpMatrix a -> SpMatrix a -> SpMatrix a

-- | After multiplying the two matrices, all elements <tt>x</tt> for which
--   `| x | &lt;= eps` are removed.
(#~#) :: (MatrixRing (SpMatrix a), Epsilon a) => SpMatrix a -> SpMatrix a -> SpMatrix a

-- | Sparsifying A^T B
(#~#^) :: (MatrixRing (SpMatrix a), Epsilon a) => SpMatrix a -> SpMatrix a -> SpMatrix a

-- | Sparsifying A B^T
(#~^#) :: (MatrixRing (SpMatrix a), Epsilon a) => SpMatrix a -> SpMatrix a -> SpMatrix a

-- | Contract row <tt>i</tt> of A with column <tt>j</tt> of B up to an
--   index <tt>n</tt>, i.e. summing over repeated indices: Aij Bjk , for j
--   in [0 .. n]
contractSub :: Elt a => SpMatrix a -> SpMatrix a -> IxRow -> IxCol -> Int -> a
instance GHC.Show.Show Data.Sparse.SpMatrix.MatProd_
instance GHC.Classes.Eq Data.Sparse.SpMatrix.MatProd_
instance GHC.Show.Show Data.Sparse.SpMatrix.SMInfo
instance GHC.Classes.Eq Data.Sparse.SpMatrix.SMInfo
instance Data.Foldable.Foldable Data.Sparse.SpMatrix.SpMatrix
instance GHC.Base.Functor Data.Sparse.SpMatrix.SpMatrix
instance GHC.Classes.Eq a => GHC.Classes.Eq (Data.Sparse.SpMatrix.SpMatrix a)
instance Numeric.LinearAlgebra.Class.MatrixRing (Data.Sparse.SpMatrix.SpMatrix GHC.Types.Double)
instance Numeric.LinearAlgebra.Class.MatrixRing (Data.Sparse.SpMatrix.SpMatrix (Data.Complex.Complex GHC.Types.Double))
instance GHC.Show.Show a => GHC.Show.Show (Data.Sparse.SpMatrix.SpMatrix a)
instance Numeric.LinearAlgebra.Class.Set Data.Sparse.SpMatrix.SpMatrix
instance GHC.Num.Num a => Numeric.LinearAlgebra.Class.AdditiveGroup (Data.Sparse.SpMatrix.SpMatrix a)
instance Numeric.LinearAlgebra.Class.FiniteDim (Data.Sparse.SpMatrix.SpMatrix a)
instance Numeric.LinearAlgebra.Class.HasData (Data.Sparse.SpMatrix.SpMatrix a)
instance Numeric.LinearAlgebra.Class.Sparse (Data.Sparse.SpMatrix.SpMatrix a)
instance GHC.Num.Num a => Numeric.LinearAlgebra.Class.SpContainer (Data.Sparse.SpMatrix.SpMatrix a)


module Data.Sparse.Common

-- | Insert row , using the provided row index transformation function
insertRowWith :: (IxCol -> IxCol) -> SpMatrix a -> SpVector a -> Key -> SpMatrix a

-- | Insert row
insertRow :: SpMatrix a -> SpVector a -> Key -> SpMatrix a

-- | Insert column, using the provided row index transformation function
insertColWith :: (IxRow -> IxRow) -> SpMatrix a -> SpVector a -> IxCol -> SpMatrix a

-- | Insert column
insertCol :: SpMatrix a -> SpVector a -> IxCol -> SpMatrix a

-- | Fill the diagonal of a SpMatrix with the components of a SpVector
diagonalSM :: SpVector a -> SpMatrix a

-- | Outer product
outerProdSV :: Num a => SpVector a -> SpVector a -> SpMatrix a

-- | Outer product
(><) :: Num a => SpVector a -> SpVector a -> SpMatrix a

-- | Demote (n x 1) or (1 x n) SpMatrix to SpVector
toSV :: SpMatrix a -> SpVector a

-- | promote a SV to SM
svToSM :: SpVector a -> SpMatrix a

-- | Lookup a row in a SpMatrix; returns an SpVector with the row, if this
--   is non-empty
lookupRowSM :: SpMatrix a -> IxRow -> Maybe (SpVector a)

-- | Extract jth column
extractCol :: SpMatrix a -> IxCol -> SpVector a

-- | Extract ith row
extractRow :: SpMatrix a -> IxRow -> SpVector a

-- | Generic extraction function
extractVectorDenseWith :: Num a => (Int -> (IxRow, IxCol)) -> SpMatrix a -> SpVector a

-- | Extract ith row (dense)
extractRowDense :: Num a => SpMatrix a -> IxRow -> SpVector a

-- | Extract jth column
extractColDense :: Num a => SpMatrix a -> IxCol -> SpVector a

-- | Extract the diagonal
extractDiagDense :: Num a => SpMatrix a -> SpVector a

-- | extract row interval (all entries between columns j1 and j2, INCLUDED,
--   are returned) extractSubRow :: SpMatrix a -&gt; IxRow -&gt; (IxCol,
--   IxCol) -&gt; SpVector a extractSubRow m i (j1, j2) = case lookupRowSM
--   m i of Nothing -&gt; zeroSV (ncols m) Just rv -&gt; ifilterSV (j _
--   -&gt; j &gt;= j1 &amp;&amp; j &lt;= j2) rv
--   
--   ", returning in Maybe extractSubRow :: SpMatrix a -&gt; IxRow -&gt;
--   (Int, Int) -&gt; Maybe (SpVector a) extractSubRow m i (j1, j2) =
--   resizeSV (j2 - j1) . ifilterSV (j _ -&gt; j &gt;= j1 &amp;&amp; j
--   <a>j2) &lt;$</a> lookupRowSM m i
--   
--   Extract an interval of SpVector components, changing accordingly the
--   resulting SpVector size. Keys are _not_ rebalanced, i.e. components
--   are still labeled according with respect to the source matrix.
extractSubRow :: SpMatrix a -> IxRow -> (Int, Int) -> SpVector a

-- | extract column interval
extractSubCol :: SpMatrix a -> IxCol -> (IxRow, IxRow) -> SpVector a

-- | extract row interval, rebalance keys by subtracting lowest one
extractSubRow_RK :: SpMatrix a -> IxRow -> (IxCol, IxCol) -> SpVector a

-- | extract column interval, rebalance keys by subtracting lowest one
extractSubCol_RK :: SpMatrix a -> IxCol -> (IxRow, IxRow) -> SpVector a

-- | Pack a list of SpVectors as rows of an SpMatrix
fromRowsL :: [SpVector a] -> SpMatrix a

-- | Pack a V.Vector of SpVectors as rows of an SpMatrix
fromRowsV :: Vector (SpVector a) -> SpMatrix a

-- | Pack a V.Vector of SpVectors as columns of an SpMatrix
fromColsV :: Vector (SpVector a) -> SpMatrix a

-- | Pack a list of SpVectors as columns an SpMatrix
fromColsL :: [SpVector a] -> SpMatrix a

-- | Unpack the rows of an SpMatrix into a list of SpVectors
toRowsL :: SpMatrix a -> [SpVector a]

-- | Unpack the columns of an SpMatrix into a list of SpVectors
toColsL :: SpMatrix a -> [SpVector a]
instance Data.Sparse.PPrint.PrintDense (Data.Sparse.SpVector.SpVector GHC.Types.Double)
instance Data.Sparse.PPrint.PrintDense (Data.Sparse.SpVector.SpVector (Data.Complex.Complex GHC.Types.Double))
instance Data.Sparse.PPrint.PrintDense (Data.Sparse.SpMatrix.SpMatrix GHC.Types.Double)
instance Data.Sparse.PPrint.PrintDense (Data.Sparse.SpMatrix.SpMatrix (Data.Complex.Complex GHC.Types.Double))


-- | This module exposes the user interface to the library.
module Numeric.LinearAlgebra.Sparse

-- | Solve a linear system; uses GMRES internally as default method
(<\>) :: (LinearSystem v, MonadIO m, MonadThrow m) => MatrixType v -> v -> m v

-- | Least-squares approximation of a rectangular system of equations.
pinv :: (LinearSystem v, MonadThrow m, MonadIO m) => MatrixType v -> v -> m v

-- | Direct solver based on a triangular factorization of the system
--   matrix.
luSolve :: (Scalar (SpVector t) ~ t, MonadThrow m, Elt t, InnerSpace (SpVector t), Epsilon t, PrintDense (SpVector t), MonadIO m) => SpMatrix t -> SpMatrix t -> SpVector t -> m (SpVector t)

-- | Forward substitution solver
triLowerSolve :: (Scalar (SpVector t) ~ t, Elt t, InnerSpace (SpVector t), PrintDense (SpVector t), Epsilon t, MonadThrow m, MonadIO m) => SpMatrix t -> SpVector t -> m (SpVector t)

-- | Backward substitution solver
triUpperSolve :: (Scalar (SpVector t) ~ t, Elt t, InnerSpace (SpVector t), PrintDense (SpVector t), Epsilon t, MonadThrow m, MonadIO m) => SpMatrix t -> SpVector t -> m (SpVector t)

-- | `eigsQR n mm` performs at most <tt>n</tt> iterations of the QR
--   algorithm on matrix <tt>mm</tt>, and returns a SpVector containing all
--   eigenvalues.
eigsQR :: (MonadThrow m, MonadIO m, Num' a, Normed (SpVector a), MatrixRing (SpMatrix a), Typeable (Magnitude (SpVector a)), PrintDense (SpVector a), PrintDense (SpMatrix a)) => Int -> Bool -> SpMatrix a -> m (SpVector a)

-- | `eigsArnoldi n aa b` computes at most n iterations of the Arnoldi
--   algorithm to find a Krylov subspace of (A, b), denoted Q, along with a
--   Hessenberg matrix of coefficients H. After that, it computes the QR
--   decomposition of H, denoted (O, R) and the eigenvalues {λ_i} of A are
--   listed on the diagonal of the R factor.
eigsArnoldi :: (Scalar (SpVector t) ~ t, MatrixType (SpVector t) ~ SpMatrix t, Elt t, V (SpVector t), Epsilon t, PrintDense (SpMatrix t), MonadThrow m, MonadIO m) => Int -> SpMatrix t -> SpVector t -> m (SpMatrix t, SpMatrix t, SpVector t)

-- | Given a matrix A, returns a pair of matrices (Q, R) such that Q R = A,
--   where Q is orthogonal and R is upper triangular. Applies Givens
--   rotation iteratively to zero out sub-diagonal elements.
--   
--   NB: at each iteration <tt>i</tt> we multiply the Givens matrix
--   <tt>G_i</tt> by the previous partial result <tt>M</tt>. Since this
--   corresponds to a rotation, and the <a>givensCoef</a> function already
--   computes the value of the resulting non-zero component (output
--   <tt>r</tt>), `G_i ## M` can be simplified by just updating two entries
--   of <tt>M</tt> (i.e. zeroing one out and changing the other into
--   <tt>r</tt>).
--   
--   However, we must also accumulate the <tt>G_i</tt> in order to build
--   <tt>Q</tt>, and the present formulation follows this definition
--   closely.
qr :: (Elt a, MatrixRing (SpMatrix a), PrintDense (SpMatrix a), Epsilon a, MonadThrow m, MonadIO m) => SpMatrix a -> m (SpMatrix a, SpMatrix a)

-- | Given a matrix A, returns a pair of matrices (L, U) where L is lower
--   triangular and U is upper triangular such that L U = A . Implements
--   the Doolittle algorithm, which sets the diagonal of the L matrix to
--   ones and expects all diagonal entries of A to be nonzero. Apply
--   pivoting (row or column permutation) to enforce a nonzero diagonal of
--   the A matrix (the algorithm throws an appropriate exception
--   otherwise).
lu :: (Scalar (SpVector t) ~ t, Elt t, VectorSpace (SpVector t), Epsilon t, MonadThrow m) => SpMatrix t -> m (SpMatrix t, SpMatrix t)

-- | Given a positive semidefinite matrix A, returns a lower-triangular
--   matrix L such that L L^T = A . This is an implementation of the
--   Cholesky–Banachiewicz algorithm, i.e. proceeding row by row from the
--   upper-left corner. | NB: The algorithm throws an exception if some
--   diagonal element of A is zero.
chol :: (Elt a, Epsilon a, MonadThrow m, MonadIO m, PrintDense (SpMatrix a)) => SpMatrix a -> m (SpMatrix a)

-- | Given a matrix A, a vector b and a positive integer <tt>n</tt>, this
--   procedure finds the basis of an order <tt>n</tt> Krylov subspace (as
--   the columns of matrix Q), along with an upper Hessenberg matrix H,
--   such that A = Q^T H Q. At the i`th iteration, it finds (i + 1)
--   coefficients (the i`th column of the Hessenberg matrix H) and the (i +
--   1)`th Krylov vector.
arnoldi :: (MatrixType (SpVector a) ~ SpMatrix a, V (SpVector a), Scalar (SpVector a) ~ a, Epsilon a, MonadThrow m) => SpMatrix a -> SpVector a -> Int -> m (SpMatrix a, SpMatrix a)

-- | Givens matrix : a planar rotation embedded in R^n.
--   
--   <pre>
--   &gt;&gt;&gt; aa = fromListSM
--   
--   &gt;&gt;&gt; g &lt;- givens aa 1 0
--   </pre>
--   
--   Row version of the method: given a matrix element below the diagonal,
--   indexed (i,j), choose a row index i' that is below the diagonal as
--   well and distinct from i such that the corresponding element is
--   nonzero.
--   
--   To zero out entry A(i, j) we must find row i' such that A(i', j) is
--   non-zero but A has zeros in row i' for all column indices &lt; j.
--   
--   NB: The Givens' matrix differs from Identity in 4 entries
--   
--   NB2: The form of a Complex rotation matrix in R^2 is as follows
--   (<a>*</a> indicates complex conjugation):
--   
--   <pre>
--      ( c    s )
--   G =(        )
--      ( -s*  c*)
--   </pre>
givens :: (Elt a, MonadThrow m) => SpMatrix a -> IxRow -> IxCol -> m (SpMatrix a)

-- | Matrix condition number: computes the QR factorization and extracts
--   the extremal eigenvalues from the R factor
conditionNumberSM :: (MonadThrow m, MonadIO m, MatrixRing (SpMatrix a), PrintDense (SpMatrix a), Num' a) => SpMatrix a -> m a

-- | Householder reflection: a vector <tt>x</tt> uniquely defines an
--   orthogonal (hyper)plane, i.e. an orthogonal subspace; the Householder
--   operator reflects any point <tt>v</tt> through this subspace: v' = (I
--   - 2 x &gt;&lt; x) v
hhRefl :: Num a => SpVector a -> SpMatrix a

-- | Partition a matrix into strictly subdiagonal, diagonal and strictly
--   superdiagonal parts
diagPartitions :: SpMatrix a -> (SpMatrix a, SpMatrix a, SpMatrix a)

-- | Create new SpVector using data from a Foldable (e.g. a list) in
--   (index, value) form
fromListSV :: Foldable t => Int -> t (Int, a) -> SpVector a

-- | Populate a list with SpVector contents
toListSV :: SpVector a -> [(Int, a)]

-- | Create a <i>dense</i> SpVector from a list of Double's
vr :: [Double] -> SpVector Double

-- | Create a <i>dense</i> SpVector from a list of Complex Double's
vc :: [Complex Double] -> SpVector (Complex Double)

-- | Populate a SpVector with the contents of a Vector.
fromVector :: Vector a -> SpVector a

-- | Populate a Vector with the entries of a SpVector, replacing the
--   missing entries with 0
toVectorDense :: Num a => SpVector a -> Vector a

-- | DENSE vector with constant elements
constv :: Int -> a -> SpVector a

-- | Create new SpMatrix using data from a Foldable (e.g. a list) in (row,
--   col, value) form
fromListSM :: Foldable t => (Int, Int) -> t (IxRow, IxCol, a) -> SpMatrix a

-- | Populate list with SpMatrix contents
toListSM :: SpMatrix t -> [(IxRow, IxCol, t)]

-- | Pack a list of SpVectors as rows of an SpMatrix
fromRowsL :: [SpVector a] -> SpMatrix a

-- | Unpack the rows of an SpMatrix into a list of SpVectors
toRowsL :: SpMatrix a -> [SpVector a]

-- | Pack a list of SpVectors as columns an SpMatrix
fromColsL :: [SpVector a] -> SpMatrix a

-- | Unpack the columns of an SpMatrix into a list of SpVectors
toColsL :: SpMatrix a -> [SpVector a]

-- | Pack a V.Vector of SpVectors as rows of an SpMatrix
fromRowsV :: Vector (SpVector a) -> SpMatrix a

-- | Pack a V.Vector of SpVectors as columns of an SpMatrix
fromColsV :: Vector (SpVector a) -> SpMatrix a

-- | Vertical stacking of matrix blocks
(-=-) :: SpMatrix a -> SpMatrix a -> SpMatrix a

-- | Horizontal stacking of matrix blocks
(-||-) :: SpMatrix a -> SpMatrix a -> SpMatrix a

-- | Assemble a block-diagonal square matrix from a list of square
--   matrices, arranging these along the main diagonal
fromBlocksDiag :: [SpMatrix a] -> SpMatrix a

-- | `eye n` : identity matrix of rank <tt>n</tt>
eye :: Num a => Int -> SpMatrix a

-- | `mkDiagonal n ll` : create a diagonal matrix of size <tt>n</tt> from a
--   list <tt>ll</tt> of elements
mkDiagonal :: Int -> [a] -> SpMatrix a

-- | `mkSubDiagonal n o xx` creates a square SpMatrix of size <tt>n</tt>
--   with <tt>xx</tt> on the <tt>o</tt>th subdiagonal
mkSubDiagonal :: Int -> Int -> [a] -> SpMatrix a

-- | Permutation matrix from a (possibly incomplete) list of row swaps
--   starting from row 0 e.g. `permutationSM 5 [1,3]` first swaps rows (0,
--   1) and then rows (1, 3) :
--   
--   <pre>
--   &gt;&gt;&gt; prd (permutationSM 5 [1,3] :: SpMatrix Double)
--   </pre>
--   
--   <pre>
--   ( 5 rows, 5 columns ) , 5 NZ ( density 20.000 % )
--   
--   _      , 1.00   , _      , _      , _      
--   _      , _      , _      , 1.00   , _      
--   _      , _      , 1.00   , _      , _      
--   1.00   , _      , _      , _      , _      
--   _      , _      , _      , _      , 1.00
--   </pre>
permutationSM :: Num a => Int -> [IxRow] -> SpMatrix a

-- | Permutation matrix from a (possibly incomplete) list of row pair swaps
--   e.g. `permutPairs 5 [(2,4)]` swaps rows 2 and 4 :
--   
--   <pre>
--   &gt;&gt;&gt; prd (permutPairsSM 5 [(2,4)] :: SpMatrix Double)
--   </pre>
--   
--   <pre>
--   ( 5 rows, 5 columns ) , 5 NZ ( density 20.000 % )
--   
--   1.00   , _      , _      , _      , _      
--   _      , 1.00   , _      , _      , _      
--   _      , _      , _      , _      , 1.00   
--   _      , _      , _      , 1.00   , _      
--   _      , _      , 1.00   , _      , _
--   </pre>
permutPairsSM :: Num a => Int -> [(IxRow, IxRow)] -> SpMatrix a

-- | Is the matrix orthogonal? i.e. Q^t ## Q == I
isOrthogonalSM :: (Eq a, Epsilon a, MatrixRing (SpMatrix a)) => SpMatrix a -> Bool

-- | Is the matrix diagonal?
isDiagonalSM :: SpMatrix a -> Bool

-- | Filter
filterSV :: (a -> Bool) -> SpVector a -> SpVector a

-- | Indexed filter
ifilterSV :: (Int -> a -> Bool) -> SpVector a -> SpVector a

-- | Determine if a quantity is near zero.
nearZero :: Epsilon a => a -> Bool

-- | Is this quantity close to 1 ?
nearOne :: Epsilon a => a -> Bool

-- | Is this quantity distinguishable from 0 ?
isNz :: Epsilon a => a -> Bool

-- | Scale a vector
(.*) :: VectorSpace v => Scalar v -> v -> v
infixr 7 .*

-- | Scale a vector by the reciprocal of a number (e.g. for normalization)
(./) :: (VectorSpace v, s ~ Scalar v, Fractional s) => v -> s -> v
infixr 7 ./

-- | Inner/dot product
(<.>) :: InnerSpace v => v -> v -> Scalar v

-- | Matrix-vector action
(#>) :: LinearVectorSpace v => MatrixType v -> v -> v

-- | Dual matrix-vector action
(<#) :: LinearVectorSpace v => v -> MatrixType v -> v

-- | Matrix-matrix product
(##) :: MatrixRing m => m -> m -> m

-- | Matrix transpose times matrix (A^T B)
(#^#) :: MatrixRing m => m -> m -> m

-- | Matrix times matrix transpose (A B^T)
(##^) :: MatrixRing m => m -> m -> m

-- | After multiplying the two matrices, all elements <tt>x</tt> for which
--   `| x | &lt;= eps` are removed.
(#~#) :: (MatrixRing (SpMatrix a), Epsilon a) => SpMatrix a -> SpMatrix a -> SpMatrix a

-- | Sparsifying A B^T
(#~^#) :: (MatrixRing (SpMatrix a), Epsilon a) => SpMatrix a -> SpMatrix a -> SpMatrix a

-- | Sparsifying A^T B
(#~#^) :: (MatrixRing (SpMatrix a), Epsilon a) => SpMatrix a -> SpMatrix a -> SpMatrix a

-- | Outer product
(><) :: Num a => SpVector a -> SpVector a -> SpMatrix a

-- | Dimension (i.e. Int for SpVector, (Int, Int) for SpMatrix)
dim :: FiniteDim f => f -> FDSize f

-- | Number of nonzeros
nnz :: HasData f => f -> Int

-- | Sparsity (fraction of nonzero elements)
spy :: (Sparse f, Fractional b) => f -> b

-- | Convex combination of two vectors (NB: 0 &lt;= <tt>a</tt> &lt;= 1).
cvx :: VectorSpace v => Scalar v -> v -> v -> v

-- | Lp norm (p &gt; 0)
norm :: (Normed v, Floating (Magnitude v)) => RealScalar v -> v -> Magnitude v

-- | Euclidean (L2) norm
norm2 :: (Normed v, Floating (Magnitude v)) => v -> Magnitude v

-- | Euclidean (L2) norm; returns a Complex (norm :+ 0) for Complex-valued
--   vectors
norm2' :: (Normed v, Floating (Scalar v)) => v -> Scalar v

-- | Normalize w.r.t. Lp norm
normalize :: Normed v => RealScalar v -> v -> v

-- | Normalize w.r.t. L2 norm
normalize2 :: Normed v => v -> v

-- | Normalize w.r.t. norm2' instead of norm2
normalize2' :: (Normed v, Floating (Scalar v)) => v -> v

-- | L1 norm
norm1 :: Normed v => v -> Magnitude v

-- | `hilbertDistSq x y = || x - y ||^2` computes the squared L2 distance
--   between two vectors
hilbertDistSq :: InnerSpace v => v -> v -> Scalar v

-- | Matrix transpose (Hermitian conjugate in the Complex case)
transpose :: MatrixRing m => m -> m

-- | Matrix trace
trace :: Num b => SpMatrix b -> b

-- | Frobenius norm
normFrobenius :: MatrixRing m => m -> MatrixNorm m

-- | Pretty-print with a descriptive header
prd :: PrintDense a => a -> IO ()

-- | Pretty-print with no header
prd0 :: PrintDense a => a -> IO ()

-- | <a>untilConvergedG0</a> is a special case of <a>untilConvergedG</a>
--   that assesses convergence based on the L2 distance to a known solution
--   <tt>xKnown</tt>
untilConvergedG0 :: (Normed v, MonadThrow m, MonadIO m, Typeable (Magnitude v), Typeable s, Show s) => String -> IterationConfig s v -> v -> (s -> s) -> s -> m s

-- | This function makes some default choices on the
--   <a>modifyInspectGuarded</a> machinery: convergence is assessed using
--   the squared L2 distance between consecutive states, and divergence is
--   detected when this function is increasing between pairs of
--   measurements.
untilConvergedG :: (Normed v, MonadThrow m, MonadIO m, Typeable (Magnitude v), Typeable s, Show s) => String -> IterationConfig s v -> (v -> Bool) -> (s -> s) -> s -> m s

-- | ", monadic version
untilConvergedGM :: (Normed v, MonadThrow m, MonadIO m, Typeable (Magnitude v), Typeable s, Show s) => String -> IterationConfig s v -> (v -> Bool) -> (s -> m s) -> s -> m s

-- | <a>modifyInspectGuarded</a> is a high-order abstraction of a numerical
--   iterative process. It accumulates a rolling window of 3 states and
--   compares a summary <tt>q</tt> of the latest 2 with that of the
--   previous two in order to assess divergence (e.g. if `q latest2 &gt; q
--   prev2` then the function throws an exception and terminates). The
--   process ends by either hitting an iteration budget or by relative
--   convergence, whichever happens first. After the iterations stop, the
--   function then assesses the final state with a predicate
--   <tt>qfinal</tt> (e.g. for comparing the final state with a known one;
--   if this is not available, the user can just supply `const True`)
modifyInspectGuarded :: (MonadThrow m, MonadIO m, Typeable s, Typeable a, Show s, Show a) => String -> IterationConfig s v -> ([v] -> a) -> (a -> Bool) -> (a -> a -> Bool) -> (v -> Bool) -> (s -> s) -> s -> m s

-- | ", monadic version
modifyInspectGuardedM :: (MonadThrow m, MonadIO m, Typeable s, Show s, Typeable a, Show a) => String -> IterationConfig s v -> ([v] -> a) -> (a -> Bool) -> (a -> a -> Bool) -> (v -> Bool) -> (s -> m s) -> s -> m s
data IterationConfig a b

-- | print function for type <tt>b</tt>
IterConf :: Int -> Bool -> (a -> b) -> (b -> IO ()) -> IterationConfig a b

-- | Max.# of iterations
[numIterationsMax] :: IterationConfig a b -> Int

-- | Print iteration info to stdout
[printDebugInfo] :: IterationConfig a b -> Bool

-- | Project state to a type <tt>b</tt>
[iterationView] :: IterationConfig a b -> a -> b
[printDebugIO] :: IterationConfig a b -> b -> IO ()
modifyUntil :: MonadState s m => (s -> Bool) -> (s -> s) -> m s
modifyUntilM :: MonadState s m => (s -> Bool) -> (s -> m s) -> m s

-- | Interface method to individual linear solvers
linSolve0 :: ((~#) * * Scalar SpVector b b, (~#) * * MatrixType SpVector b SpMatrix b, Show b, Floating Scalar SpVector b, Epsilon b, Elt b, MatrixRing SpMatrix b, PrintDense SpMatrix b, PrintDense SpVector b, Normed SpVector b, MonadThrow m, MonadIO m, Typeable * Magnitude SpVector b, Typeable * b, LinearVectorSpace SpVector b) => LinSolveMethod -> SpMatrix b -> SpVector b -> SpVector b -> m SpVector b

-- | Iterative methods for linear systems
data LinSolveMethod

-- | Generalized Minimal RESidual
GMRES_ :: LinSolveMethod

-- | Conjugate Gradient on the Normal Equations
CGNE_ :: LinSolveMethod

-- | BiConjugate Gradient
BCG_ :: LinSolveMethod

-- | Conjugate Gradient Squared
CGS_ :: LinSolveMethod

-- | BiConjugate Gradient Stabilized
BICGSTAB_ :: LinSolveMethod

-- | Errors associated with partial functions
data PartialFunctionError

-- | Input errors
data InputError

-- | Out of bounds index errors
data OutOfBoundsIndexError i

-- | Operand size mismatch errors
data OperandSizeMismatch

-- | Matrix exceptions
data MatrixException i

-- | Numerical iteration errors
data IterationException a
instance GHC.Show.Show Numeric.LinearAlgebra.Sparse.LinSolveMethod
instance GHC.Classes.Eq Numeric.LinearAlgebra.Sparse.LinSolveMethod
instance GHC.Classes.Eq a => GHC.Classes.Eq (Numeric.LinearAlgebra.Sparse.BICGSTAB a)
instance GHC.Classes.Eq a => GHC.Classes.Eq (Numeric.LinearAlgebra.Sparse.CGS a)
instance GHC.Classes.Eq a => GHC.Classes.Eq (Numeric.LinearAlgebra.Sparse.BCG a)
instance GHC.Classes.Eq a => GHC.Classes.Eq (Numeric.LinearAlgebra.Sparse.CGNE a)
instance GHC.Show.Show a => GHC.Show.Show (Numeric.LinearAlgebra.Sparse.BICGSTAB a)
instance GHC.Show.Show a => GHC.Show.Show (Numeric.LinearAlgebra.Sparse.CGS a)
instance GHC.Show.Show a => GHC.Show.Show (Numeric.LinearAlgebra.Sparse.BCG a)
instance GHC.Show.Show a => GHC.Show.Show (Numeric.LinearAlgebra.Sparse.CGNE a)
