packages feed

sparse-linear-algebra 0.2.9.2 → 0.2.9.3

raw patch · 7 files changed

+77/−32 lines, 7 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Data.Sparse.Common: fromCols :: Vector (SpVector a) -> SpMatrix a
- Data.Sparse.Common: toCols :: SpMatrix a -> [SpVector a]
+ Data.Sparse.Common: fromColsV :: Vector (SpVector a) -> SpMatrix a
+ Data.Sparse.Common: fromRowsL :: [SpVector a] -> SpMatrix a
+ Data.Sparse.Common: fromRowsV :: Vector (SpVector a) -> SpMatrix a
+ Data.Sparse.Common: toColsL :: SpMatrix a -> [SpVector a]
+ Data.Sparse.Common: toRowsL :: SpMatrix a -> [SpVector a]
+ Numeric.LinearAlgebra.Sparse: fromColsL :: [SpVector a] -> SpMatrix a
+ Numeric.LinearAlgebra.Sparse: fromColsV :: Vector (SpVector a) -> SpMatrix a
+ Numeric.LinearAlgebra.Sparse: fromRowsL :: [SpVector a] -> SpMatrix a
+ Numeric.LinearAlgebra.Sparse: fromRowsV :: Vector (SpVector a) -> SpMatrix a
+ Numeric.LinearAlgebra.Sparse: prd :: PrintDense a => a -> IO ()
+ Numeric.LinearAlgebra.Sparse: prd0 :: PrintDense a => a -> IO ()
+ Numeric.LinearAlgebra.Sparse: toColsL :: SpMatrix a -> [SpVector a]
+ Numeric.LinearAlgebra.Sparse: toRowsL :: SpMatrix a -> [SpVector a]

Files

+ CHANGELOG.markdown view
@@ -0,0 +1,7 @@+0.2.9.1+-------++* Uses classes from `vector-space` such as AdditiveGroup, VectorSpace and InnerSpace+* QuickCheck tests for algebraic properties, such as matrix-vector products and soon more abstract ones e.g. positive semi-definite matrices+* Getting rid of `error` in favor of MonadThrow exceptions for high-level operations+such as matrix algorithms
README.md view
@@ -38,8 +38,10 @@      * QR (`eigsQR`) -    * Rayleigh quotient iteration (`eigRayleigh`)+    * QR-Arnoldi (`eigsArnoldi`)  ++ * Utilities : Vector and matrix norms, matrix condition number, Givens rotation, Householder reflection  * Predicates : Matrix orthogonality test (A^T A ~= I)@@ -47,6 +49,10 @@   ### Under development++* Eigenvalue algorithms++    * Rayleigh quotient iteration (`eigRayleigh`)  * Matrix factorization algorithms 
sparse-linear-algebra.cabal view
@@ -1,5 +1,5 @@ name:                sparse-linear-algebra-version:             0.2.9.2+version:             0.2.9.3 synopsis:            Numerical computation in native Haskell description:   /Overview/@@ -17,10 +17,11 @@ license-file:        LICENSE author:              Marco Zocca maintainer:          zocca.marco gmail-copyright:           2016 Marco Zocca+copyright:           2016-2017 Marco Zocca category:            Numeric build-type:          Simple extra-source-files:  README.md+                     CHANGELOG.markdown cabal-version:       >=1.10 tested-with:         GHC == 8.0.1 
src/Data/Sparse/Common.hs view
@@ -21,7 +21,7 @@          extractDiagDense,          extractSubRow, extractSubCol,          extractSubRow_RK, extractSubCol_RK,-         fromCols, fromColsL, toCols) where+         fromRowsL, fromRowsV, fromColsV, fromColsL, toRowsL, toColsL) where  -- import Control.Exception -- import Control.Exception.Common@@ -293,34 +293,41 @@   -+-- | Pack a list of SpVectors as rows of an SpMatrix+fromRowsL :: [SpVector a] -> SpMatrix a+fromRowsL = fromRowsV . V.fromList --- | Pack a list of SpVectors into an SpMatrix+-- | Pack a list of SpVectors as columns an SpMatrix fromColsL :: [SpVector a] -> SpMatrix a-fromColsL = fromCols . V.fromList+fromColsL = fromColsV . V.fromList --- | Unpack an SpMatrix into a list of SpVectors-toCols :: SpMatrix a -> [SpVector a]-toCols aa = map (extractCol aa) [0 .. n-1] where+-- | Unpack the rows of an SpMatrix into a list of SpVectors+toRowsL :: SpMatrix a -> [SpVector a]+toRowsL aa = map (extractRow aa) [0 .. m-1] where   (m,n) = dim aa ---+-- | Unpack the columns of an SpMatrix into a list of SpVectors+toColsL :: SpMatrix a -> [SpVector a]+toColsL aa = map (extractCol aa) [0 .. n-1] where+  (m,n) = dim aa     -- | Pack a V.Vector of SpVectors as columns of an SpMatrix-fromCols :: V.Vector (SpVector a) -> SpMatrix a-fromCols qv = V.ifoldl' ins (zeroSM m n) qv where+fromColsV :: V.Vector (SpVector a) -> SpMatrix a+fromColsV qv = V.ifoldl' ins (zeroSM m n) qv where   n = V.length qv   m = dim $ V.head qv   ins mm i c = insertCol mm c i  --+-- | Pack a V.Vector of SpVectors as rows of an SpMatrix+fromRowsV :: V.Vector (SpVector a) -> SpMatrix a+fromRowsV qv = V.ifoldl' ins (zeroSM m n) qv where+  n = V.length qv+  m = svDim $ V.head qv+  ins mm i c = insertRow mm c i   @@ -333,13 +340,13 @@ showNz x | nearZero x = " _ "          | otherwise = show x --- toDenseRow :: Num a => SpMatrix a -> IM.Key -> [a]+toDenseRow :: Num a => SpMatrix a -> IM.Key -> [a] toDenseRow sm irow =-  fmap (\icol -> sm @@ (irow,icol)) [0..ncol-1] where (_, ncol) = dim sm+  fmap (\icol -> sm @@ (irow,icol)) [0..ncol-1] where (_, ncol) = (nrows sm, ncols sm)   --- toDenseRowClip :: (Show a, Num a) => SpMatrix a -> IM.Key -> Int -> String+toDenseRowClip :: (Show a, Num a, Epsilon a) => SpMatrix a -> IM.Key -> Int -> String toDenseRowClip sm irow ncomax   | nco > ncomax = unwords (map showNz h) ++  " ... " ++ showNz t   | otherwise = unwords $ showNz <$> dr@@ -350,17 +357,22 @@   -- printDenseSM :: (Show t, Num t) => SpMatrix t -> IO ()-printDenseSM :: (ScIx c ~ (Int, Int), FDSize c ~ (Int, Int), SpContainer c a, Show a, Epsilon a) => c a -> IO ()+-- printDenseSM :: (ScIx c ~ (Int, Int), FDSize c ~ (Int, Int), SpContainer c a, Show a, Epsilon a) => c a -> IO () printDenseSM sm = do   newline   putStrLn $ sizeStr sm   newline+  printDenseSM0 sm++printDenseSM0 sm = do+  putStrLn $ sizeStr sm+  newline   printDenseSM' sm 5 5   newline   where         -- printDenseSM' :: (Show t, Num t) => SpMatrix t -> Int -> Int -> IO ()     printDenseSM' sm' nromax ncomax = mapM_ putStrLn rr_' where-      (nr, _) = dim sm'+      (nr, _) = (nrows sm, ncols sm)       rr_ = map (\i -> toDenseRowClip sm' i ncomax) [0..nr - 1]       rr_' | nr > nromax = take (nromax - 2) rr_ ++ [" ... "] ++[last rr_]            | otherwise = rr_@@ -380,6 +392,10 @@   newline   putStrLn $ sizeStrSV sv   newline+  printDenseSV0 sv++printDenseSV0 :: (Show t, Epsilon t) => SpVector t -> IO ()+printDenseSV0 sv = do   printDenseSV' sv 5   newline where     printDenseSV' v nco = putStrLn rr_' where@@ -392,9 +408,11 @@  instance (Show a, Num a, Epsilon a) => PrintDense (SpVector a) where   prd = printDenseSV+  prd0 = printDenseSV0  instance (Show a, Num a, Epsilon a) => PrintDense (SpMatrix a) where   prd = printDenseSM+  prd0 = printDenseSM0   
src/Data/Sparse/PPrint.hs view
@@ -17,7 +17,10 @@   class PrintDense a where+  -- | Pretty-print with a descriptive header   prd :: a -> IO ()+  -- | Pretty-print with no header+  prd0 :: a -> IO ()  newline :: IO () newline = putStrLn ""  
src/Numeric/LinearAlgebra/Class.hs view
@@ -265,7 +265,7 @@ -- ** Linear systems    class LinearVectorSpace v => LinearSystem v where-  -- | Solve a linear system+  -- | Solve a linear system; uses GMRES internally as default method   (<\>) :: (MonadIO m, MonadThrow m) =>            MatrixType v   -- ^ System matrix         -> v              -- ^ Right-hand side
src/Numeric/LinearAlgebra/Sparse.hs view
@@ -57,25 +57,35 @@          fromListSV, toListSV,          -- ** From/to SpMatrix          fromListSM, toListSM,+         -- ** Packing/unpacking rows/columns of a sparse matrix+         -- *** ", using lists as container+         fromRowsL, toRowsL,+         fromColsL, toColsL,+         -- *** ", using Vector as container+         fromRowsV, fromColsV,          -- * Operators+         (.*), (./),           -- ** Inner product          (<.>),-         -- ** Matrix-vector products+         -- ** Matrix-vector product          (#>), (<#),-         -- ** Matrix-matrix products+         -- ** Matrix-matrix product          (##), (#^#), (##^),-         -- *** Sparsifying matrix-matrix products+         -- *** Sparsifying matrix-matrix product          (#~#), (#~^#), (#~#^),          -- ** Vector outer product          (><),          -- * Common operations          dim, nnz, spy,          -- ** Vector-related-         (.*), (./), cvx,+         cvx,+         -- *** Norms and normalization          norm, norm2, norm2', normalize, normalize2, normalize2',          norm1, hilbertDistSq,          -- ** Matrix-related-         transpose, normFrobenius, +         transpose, normFrobenius,+         -- * Pretty-printing+         prd, prd0,          -- * Iteration combinators          untilConvergedG0, untilConvergedG, untilConvergedGM,          modifyInspectGuarded, modifyInspectGuardedM, IterationConfig (..),@@ -542,7 +552,7 @@      -> SpVector a                 -- ^ r.h.s.      -> Int                        -- ^ Max. # of iterations      -> m (SpMatrix a, SpMatrix a) -- ^ Q, H-arnoldi aa b kn | n == nb = return (fromCols qvfin, fromListSM (nmax + 1, nmax) hhfin)+arnoldi aa b kn | n == nb = return (fromColsV qvfin, fromListSM (nmax + 1, nmax) hhfin)                 | otherwise = throwM (MatVecSizeMismatchException "arnoldi" (m,n) nb)   where   (qvfin, hhfin, nmax, _) = execState (modifyUntil tf arnoldiStep) arnInit @@ -890,7 +900,7 @@   -- * Moore-Penrose pseudoinverse--- | Least-squares approximation of a rectangular system of equaitons. Uses (<\>) for the linear solve+-- | Least-squares approximation of a rectangular system of equaitons. Uses `(<\>)` for the linear solve pinv :: (MatrixType v ~ SpMatrix a, LinearSystem v, Epsilon a,          MonadThrow m, MonadIO m) =>      SpMatrix a -> v -> m v@@ -900,7 +910,7 @@   --- | Interface method to individual linear solvers+-- | Interface method to individual linear solvers, do not use directly linSolve0 method aa b x0   | m /= nb = throwM (MatVecSizeMismatchException "linSolve0" dm nb)   | otherwise = solve aa b where@@ -920,7 +930,7 @@       xf <- untilConvergedG fname config (const True) stepf initf       return $ fproj xf       where-        config = IterConf nitermax True fproj prd+        config = IterConf nitermax True fproj prd0     -- * Linear solver interface