packages feed

bed-and-breakfast 0.1.3 → 0.1.4

raw patch · 2 files changed

+11/−4 lines, 2 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Numeric.Matrix: class (Eq e, Num e) => MatrixElement e where select p m = [at m (i, j) | i <- [1 .. numRows m], j <- [1 .. numCols m], p (i, j)] at m (i, j) = ((!! j) . (!! i) . toList) m unit n = fromList [[if i == j then 1 else 0 | j <- [1 .. n]] | i <- [1 .. n]] zero n = matrix (n, n) (const 0) empty = fromList [] diag xs = matrix (n, n) (\ (i, j) -> if i == j then xs !! (i - 1) else 0) where n = length xs row i m = ((!! (i - 1)) . toList) m col i m = (row i . transpose) m numRows = fst . dimensions numCols = snd . dimensions dimensions m = case toList m of { [] -> (0, 0) (x : xs) -> (length xs + 1, length x) } transpose = fromList . transpose . toList trace = select (uncurry (==)) inv _ = Nothing isZero = all (== 0) isUnit m = isSquare m && all (== 1) (trace m) isEmpty m = numRows m == 0 || numCols m == 0 isDiagonal = allWithIndex (uncurry $ \ x y z -> if x /= y then z == 0 else True) isSquare m = let (a, b) = dimensions m in a == b map f = mapWithIndex (const f) all f = allWithIndex (const f) any f = anyWithIndex (const f) mapWithIndex f m = matrix (dimensions m) (\ x -> f x (m `at` x)) allWithIndex f m = all id [f (i, j) (m `at` (i, j)) | i <- [1 .. numRows m], j <- [1 .. numCols m]] anyWithIndex f m = any id [f (i, j) (m `at` (i, j)) | i <- [1 .. numRows m], j <- [1 .. numCols m]] a plus b | dimensions a /= dimensions b = error "Matrix.plus: dimensions don't match." | otherwise = matrix (dimensions a) (\ x -> a `at` x + b `at` x) a minus b | dimensions a /= dimensions b = error "Matrix.minus: dimensions don't match." | otherwise = matrix (dimensions a) (\ x -> a `at` x - b `at` x) a times b | numRows a /= numCols b = error "Matrix.times: `numRows a' and `numCols b' don't match." | otherwise = fromList [[row i a `dotProd` col j b | j <- [1 .. numCols b]] | i <- [1 .. numRows a]]
+ Numeric.Matrix: class (Eq e, Num e) => MatrixElement e where select p m = [at m (i, j) | i <- [1 .. numRows m], j <- [1 .. numCols m], p (i, j)] at m (i, j) = ((!! j) . (!! i) . toList) m unit n = fromList [[if i == j then 1 else 0 | j <- [1 .. n]] | i <- [1 .. n]] zero n = matrix (n, n) (const 0) empty = fromList [] diag xs = matrix (n, n) (\ (i, j) -> if i == j then xs !! (i - 1) else 0) where n = length xs row i m = ((!! (i - 1)) . toList) m col i m = (row i . transpose) m numRows = fst . dimensions numCols = snd . dimensions dimensions m = case toList m of { [] -> (0, 0) (x : xs) -> (length xs + 1, length x) } transpose = fromList . transpose . toList trace = select (uncurry (==)) inv _ = Nothing isZero = all (== 0) isUnit m = isSquare m && allWithIndex (uncurry check) m where check = \ i j e -> if i == j then e == 1 else e == 0 isEmpty m = numRows m == 0 || numCols m == 0 isDiagonal m = isSquare m && allWithIndex (uncurry check) m where check = \ i j e -> if i /= j then e == 0 else True isSquare m = let (a, b) = dimensions m in a == b map f = mapWithIndex (const f) all f = allWithIndex (const f) any f = anyWithIndex (const f) mapWithIndex f m = matrix (dimensions m) (\ x -> f x (m `at` x)) allWithIndex f m = all id [f (i, j) (m `at` (i, j)) | i <- [1 .. numRows m], j <- [1 .. numCols m]] anyWithIndex f m = any id [f (i, j) (m `at` (i, j)) | i <- [1 .. numRows m], j <- [1 .. numCols m]] a plus b | dimensions a /= dimensions b = error "Matrix.plus: dimensions don't match." | otherwise = matrix (dimensions a) (\ x -> a `at` x + b `at` x) a minus b | dimensions a /= dimensions b = error "Matrix.minus: dimensions don't match." | otherwise = matrix (dimensions a) (\ x -> a `at` x - b `at` x) a times b | numRows a /= numCols b = error "Matrix.times: `numRows a' and `numCols b' don't match." | otherwise = fromList [[row i a `dotProd` col j b | j <- [1 .. numCols b]] | i <- [1 .. numRows a]]

Files

bed-and-breakfast.cabal view
@@ -1,5 +1,5 @@ Name:           bed-and-breakfast-Version:        0.1.3+Version:        0.1.4 Synopsis:       Efficient Matrix operations in 100% Haskell. Description:    Efficient Matrix operations in 100% Haskell.                 .@@ -17,6 +17,11 @@                     no longer call `error' if a matrix is not                     invertible. Also @Matrix@ derives 'Data.Typeable'                     now.+                .+                [@v0.1.4@] Added @scale@, @<->@, and @<|>@. Corrected+                    a bug in @isUnit@ reported by Charles Durham+                    (would have returned True for any matrix for which+                    @all (== 1) . trace@ would have, which is wrong).  License:        MIT License-File:   LICENSE@@ -24,7 +29,7 @@ Maintainer:     Julian Fleischer <julian.fleischer@fu-berlin.de> Build-Type:     Simple Cabal-Version:  >= 1.8-Category:       Numeric, Math+Category:       Numeric, Math, Linear Algebra Stability:      stable Homepage:       http://hub.darcs.net/scravy/bed-and-breakfast 
src/Numeric/Matrix.hs view
@@ -238,9 +238,11 @@     inv _ = Nothing      isZero = all (== 0)-    isUnit m = isSquare m && P.all (== 1) (trace m)+    isUnit m = isSquare m && allWithIndex (uncurry check) m+        where check = \i j e -> if i == j then e == 1 else e == 0     isEmpty m = numRows m == 0 || numCols m == 0-    isDiagonal = allWithIndex (uncurry $ \x y z -> if x /= y then z == 0 else True)+    isDiagonal m = isSquare m && allWithIndex (uncurry check) m+        where check = \i j e -> if i /= j then e == 0 else True     isSquare m = let (a, b) = dimensions m in a == b      map f = mapWithIndex (const f)