sparse-linear-algebra 0.2.0.3 → 0.2.0.4
raw patch · 2 files changed
+36/−25 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
sparse-linear-algebra.cabal view
@@ -1,5 +1,5 @@ name: sparse-linear-algebra-version: 0.2.0.3+version: 0.2.0.4 synopsis: Numerical computation in native Haskell description: Currently it provides iterative linear solvers, matrix decompositions, eigenvalue computations and related utilities. Please see README.md for details homepage: https://github.com/ocramz/sparse-linear-algebra
src/Numeric/LinearAlgebra/Sparse.hs view
@@ -337,7 +337,7 @@ --- * Element insertion+-- ** Element insertion -- |insert element `x` at index `i` in a preexisting SpVector insertSpVector :: Int -> a -> SpVector a -> SpVector a@@ -517,8 +517,21 @@ --- * fromList+-- ** Element insertion +-- | Insert an element in a preexisting Spmatrix at the specified indices+insertSpMatrix :: IxRow -> IxCol -> a -> SpMatrix a -> SpMatrix a+insertSpMatrix i j x s+ | inBounds02 d (i,j) = SM d $ insertIM2 i j x smd + | otherwise = error "insertSpMatrix : index out of bounds" where+ smd = immSM s+ d = dim s+++++-- ** fromList+ -- | Add to existing SpMatrix using data from list (row, col, value) fromListSM' :: Foldable t => t (IxRow, IxCol, a) -> SpMatrix a -> SpMatrix a fromListSM' iix sm = foldl ins sm iix where@@ -535,7 +548,7 @@ n = length ll `div` m --- * toList+-- ** toList -- |Populate list with SpMatrix contents and populate missing entries with 0 toDenseListSM :: Num t => SpMatrix t -> [(IxRow, IxCol, t)]@@ -546,15 +559,7 @@ --- ** Element insertion --- | Insert an element in a preexisting Spmatrix at the specified indices-insertSpMatrix :: IxRow -> IxCol -> a -> SpMatrix a -> SpMatrix a-insertSpMatrix i j x s- | inBounds02 d (i,j) = SM d $ insertIM2 i j x smd - | otherwise = error "insertSpMatrix : index out of bounds" where- smd = immSM s- d = dim s @@ -590,15 +595,7 @@ --- *** Multiply matrix by a scalar-matScale :: Num a => a -> SpMatrix a -> SpMatrix a-matScale a = fmap (*a) --- *** Frobenius norm (sqrt of trace of M^T M)-normFrobenius :: SpMatrix Double -> Double-normFrobenius m = sqrt $ foldlSM (+) 0 m' where- m' | nrows m > ncols m = transposeSM m ## m- | otherwise = m ## transposeSM m @@ -612,7 +609,7 @@ type IxRow = Int type IxCol = Int --- *** Predicates+-- ** Predicates -- |Are the supplied indices within matrix bounds? validIxSM :: SpMatrix a -> (Int, Int) -> Bool validIxSM mm = inBounds02 (dim mm)@@ -644,7 +641,7 @@ --- *** Matrix data and metadata+-- ** Matrix data and metadata -- | Data in internal representation (do not export) immSM :: SpMatrix t -> IM.IntMap (IM.IntMap t)@@ -680,7 +677,7 @@ --- *** Non-zero elements in a row+-- ** Non-zero elements in a row nzRow :: SpMatrix a -> IM.Key -> Int nzRow s i | inBounds0 (nrows s) i = nzRowU s i@@ -691,7 +688,7 @@ --- *** Bandwidth bounds (min, max)+-- ** Bandwidth bounds (min, max) bwMinSM :: SpMatrix a -> Int bwMinSM = fst . bwBoundsSM@@ -891,7 +888,7 @@ --- ** sparsify : remove almost-0 elements (i.e. if |x| < eps)+-- ** Sparsify : remove almost-0 elements (i.e. if |x| < eps) sparsifyIM2 :: IM.IntMap (IM.IntMap Double) -> IM.IntMap (IM.IntMap Double) sparsifyIM2 = ifilterIM2 (\_ _ x -> abs x >= eps) @@ -917,6 +914,7 @@ -- * Primitive algebra operations +-- * Matrix transpose -- | transposeSM, (#^) : Matrix transpose transposeSM, (#^) :: SpMatrix a -> SpMatrix a transposeSM (SM (m, n) im) = SM (n, m) (transposeIM2 im)@@ -924,6 +922,19 @@ (#^) = transposeSM +++++-- ** Multiply matrix by a scalar+matScale :: Num a => a -> SpMatrix a -> SpMatrix a+matScale a = fmap (*a)++-- ** Frobenius norm+normFrobenius :: SpMatrix Double -> Double+normFrobenius m = sqrt $ foldlSM (+) 0 m' where+ m' | nrows m > ncols m = transposeSM m ## m+ | otherwise = m ## transposeSM m