packages feed

bed-and-breakfast 0.4.1 → 0.4.2

raw patch · 3 files changed

+22/−84 lines, 3 files

Files

bed-and-breakfast.cabal view
@@ -1,5 +1,5 @@ Name:           bed-and-breakfast-Version:        0.4.1+Version:        0.4.2 Synopsis:       Efficient Matrix operations in 100% Haskell. Description:    Efficient Matrix operations in 100% Haskell.                 .@@ -55,8 +55,11 @@                 .                 [@v0.4.1@] The unsafe operations used in v0.4 turned out                     to fatally fail on certain platforms. Revoked this-                    change. Thanks to Marcin Fatyga for pointing at the-                    issue.+                    change.+                .+                [@v0.4.2@] Fixed a tiny bug regarding the @row@ function+                    for extracting the number of rows in a Matrix.+                    Thanks to Tim Makarios for finding and fixing the bug.   License:        MIT@@ -67,11 +70,11 @@ Cabal-Version:  >= 1.8 Category:       Numeric, Math, Linear Algebra Stability:      experimental-Homepage:       http://hub.darcs.net/scravy/bed-and-breakfast+Homepage:       https://hackage.haskell.org/package/bed-and-breakfast  Source-Repository head-    type: darcs-    location: hub.darcs.net:bed-and-breakfast+    type: git+    location: https://github.com/scravy/bed-and-breakfast.git  Library     Exposed-Modules:    Numeric.Matrix,
quickcheck-tests.hs view
@@ -1,8 +1,5 @@ {-# LANGUAGE Haskell2010, TemplateHaskell #-} -import Prelude-import qualified Prelude as P- import Control.Monad  import Numeric.Matrix@@ -12,11 +9,7 @@  import System.Exit -import Data.Ratio-import Data.Int-import Data.Word - dim :: Num a => a dim = 6 @@ -25,40 +18,12 @@     arbitrary = sequence (replicate dim (vector dim)) >>= return . fromList  -basic m = m + m == scale m 2 && m * m * m == m ^ 3--prop_zero :: Word8 -> Bool-prop_zero = isZero . (zero :: Int -> Matrix Double) . fromIntegral--prop_sum_trace :: Word8 -> Bool-prop_sum_trace n = ((== nd) . P.sum . trace . (unit :: Int -> Matrix Double) . fromIntegral) n'-  where n' = n + 1-        nd = fromIntegral n'--prop_basic_integer :: Matrix Integer -> Bool-prop_basic_integer = basic--prop_basic_int :: Matrix Int -> Bool-prop_basic_int = basic--prop_basic_float :: Matrix Float -> Bool-prop_basic_float = basic--prop_basic_double :: Matrix Double -> Bool-prop_basic_double = basic--prop_basic_rational :: Matrix Rational -> Bool-prop_basic_rational = basic--prop_zero_det_double :: Matrix Double -> Bool-prop_zero_det_double m1 = let m1' = inv m1 in case m1' of (Just _) -> det m1 /= 0; _ -> det m1 == 0--prop_zero_det_rational :: Matrix Rational -> Bool-prop_zero_det_rational m1 = let m1' = inv m1 in case m1' of (Just _) -> det m1 /= 0; _ -> det m1 == 0- prop_plus_commutative :: Matrix Double -> Matrix Double -> Bool prop_plus_commutative m1 m2 = m1 + m2 == m2 + m1 +prop_zero_det :: Matrix Rational -> Bool+prop_zero_det m1 = let m1' = inv m1 in case m1' of (Just _) -> det m1 /= 0; _ -> det m1 == 0+ prop_inv :: Matrix Rational -> Bool prop_inv m1 = let m1' = inv m1 in case m1' of (Just m1') -> m1' * m1 == unit dim; _ -> True @@ -74,8 +39,11 @@ prop_inv_twice :: Matrix Rational -> Bool prop_inv_twice m1 = let m1' = inv m1 in case m1' of (Just m1') -> inv m1' == Just m1; _ -> True + main = do+     success <- $(quickCheckAll)+         (if success then exitSuccess else exitFailure)  
src/Numeric/Matrix.hs view
@@ -135,16 +135,9 @@ -- See @encode@ and @decode@. data family Matrix e - data instance Matrix Int     = IntMatrix !Int !Int (Array Int (UArray Int Int)) -data instance Matrix Int32-    = Int32Matrix !Int !Int (Array Int (UArray Int Int32))--data instance Matrix Int64-    = Int64Matrix !Int !Int (Array Int (UArray Int Int64))- data instance Matrix Float     = FloatMatrix !Int !Int (Array Int (UArray Int Float)) @@ -195,8 +188,8 @@             = allWithIndex (\ix e -> m `at` ix == e) n         | otherwise = False -instance (MatrixElement e, NFData e) => NFData (Matrix e) where-    rnf matrix = map (\x -> x `deepseq` x) matrix `deepseq` ()+instance (MatrixElement e) => NFData (Matrix e) where+    rnf matrix = matrix `deepseq` ()  instance (MatrixElement e, Binary e) => Binary (Matrix e) where     @@ -506,30 +499,6 @@     det        (IntMatrix m n arr) = if m /= n then 0 else runST (_det thawsUnboxed arr)     rank       (IntMatrix _ _ arr) = runST (_rank thawsBoxed arr) -instance MatrixElement Int32 where-    matrix d g = runST (_matrix Int32Matrix arrayST arraySTU d g)-    fromList = _fromList Int32Matrix--    at         (Int32Matrix _ _ arr) = _at arr-    dimensions (Int32Matrix m n _) = (m, n)-    row i      (Int32Matrix _ _ arr) = _row i arr-    col j      (Int32Matrix _ _ arr) = _col j arr-    toList     (Int32Matrix _ _ arr) = _toList arr-    det        (Int32Matrix m n arr) = if m /= n then 0 else runST (_det thawsUnboxed arr)-    rank       (Int32Matrix _ _ arr) = runST (_rank thawsBoxed arr)--instance MatrixElement Int64 where-    matrix d g = runST (_matrix Int64Matrix arrayST arraySTU d g)-    fromList = _fromList Int64Matrix--    at         (Int64Matrix _ _ arr) = _at arr-    dimensions (Int64Matrix m n _) = (m, n)-    row i      (Int64Matrix _ _ arr) = _row i arr-    col j      (Int64Matrix _ _ arr) = _col j arr-    toList     (Int64Matrix _ _ arr) = _toList arr-    det        (Int64Matrix m n arr) = if m /= n then 0 else runST (_det thawsUnboxed arr)-    rank       (Int64Matrix _ _ arr) = runST (_rank thawsBoxed arr)- instance MatrixElement Integer where     matrix d g = runST (_matrix IntegerMatrix arrayST arrayST d g)     fromList   = _fromList IntegerMatrix@@ -608,7 +577,7 @@ _at arr (i,j) = arr ! i ! j  _row, _col :: (IArray a (u Int e), IArray u e) => Int -> a Int (u Int e) -> [e]-_row i arr = let row = arr ! i in [ row ! j | j <- [1..(snd (bounds arr))] ]+_row i arr = let row = arr ! i in [ row ! j | j <- [1..(snd (bounds row))] ] _col j arr = [ arr ! i ! j | i <- [1..(snd (bounds arr))] ]  _toList :: (IArray a e) => Array Int (a Int e) -> [[e]]@@ -841,12 +810,10 @@   _mult :: MatrixElement e => Matrix e -> Matrix e -> Matrix e-_mult a b =-    let rowsA = numRows a-        rowsB = numRows b-        colsB = numCols b-        gen i j = L.foldl' (+) 0 [a `at` (i, k) * b `at` (k, j) | k <- [1..rowsB]]-    in  matrix (rowsA, colsB) (uncurry gen)+_mult a b = let rowsA = numRows a+                rowsB = numRows b+                colsB = numCols b+            in  matrix (rowsA, colsB) (\(i,j) -> L.foldl' (+) 0 [a `at` (i, k) * b `at` (k, j) | k <- [1..rowsB]])   _matrix :: (IArray a1 (u Int e), IArray u e,