diff options
author | Alberto Ruiz <aruiz@um.es> | 2010-03-01 11:15:22 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2010-03-01 11:15:22 +0000 |
commit | 283f3033f86fabde2290bb28a59e7d87fd0754f5 (patch) | |
tree | ac9000c976a805636b557b916af9e139922df70c /lib/Numeric/LinearAlgebra | |
parent | 54bcc1fc1e0f9676cb10f627f412eeeea34b5d2c (diff) |
compatible with vector
Diffstat (limited to 'lib/Numeric/LinearAlgebra')
-rw-r--r-- | lib/Numeric/LinearAlgebra/Instances.hs | 14 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra/Tests.hs | 14 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra/Tests/Properties.hs | 4 |
3 files changed, 25 insertions, 7 deletions
diff --git a/lib/Numeric/LinearAlgebra/Instances.hs b/lib/Numeric/LinearAlgebra/Instances.hs index 67496f2..b17da5a 100644 --- a/lib/Numeric/LinearAlgebra/Instances.hs +++ b/lib/Numeric/LinearAlgebra/Instances.hs | |||
@@ -25,7 +25,7 @@ import Data.Packed.Matrix | |||
25 | import Complex | 25 | import Complex |
26 | import Data.List(transpose,intersperse) | 26 | import Data.List(transpose,intersperse) |
27 | import Foreign(Storable) | 27 | import Foreign(Storable) |
28 | import Data.Monoid | 28 | -- import Data.Monoid |
29 | import Data.Packed.Internal.Vector | 29 | import Data.Packed.Internal.Vector |
30 | -- import Control.Parallel.Strategies | 30 | -- import Control.Parallel.Strategies |
31 | 31 | ||
@@ -182,12 +182,12 @@ instance (Linear Vector a, Floating (Vector a), Fractional (Matrix a)) => Floati | |||
182 | 182 | ||
183 | --------------------------------------------------------------- | 183 | --------------------------------------------------------------- |
184 | 184 | ||
185 | instance (Storable a, Num (Vector a)) => Monoid (Vector a) where | 185 | -- instance (Storable a, Num (Vector a)) => Monoid (Vector a) where |
186 | mempty = 0 { idim = 0 } | 186 | -- mempty = 0 { idim = 0 } |
187 | mappend a b = mconcat [a,b] | 187 | -- mappend a b = mconcat [a,b] |
188 | mconcat = j . filter ((>0).dim) | 188 | -- mconcat = j . filter ((>0).dim) |
189 | where j [] = mempty | 189 | -- where j [] = mempty |
190 | j l = join l | 190 | -- j l = join l |
191 | 191 | ||
192 | --------------------------------------------------------------- | 192 | --------------------------------------------------------------- |
193 | 193 | ||
diff --git a/lib/Numeric/LinearAlgebra/Tests.hs b/lib/Numeric/LinearAlgebra/Tests.hs index 016b9a1..3f7c847 100644 --- a/lib/Numeric/LinearAlgebra/Tests.hs +++ b/lib/Numeric/LinearAlgebra/Tests.hs | |||
@@ -180,6 +180,9 @@ runTests n = do | |||
180 | test (multProp1 . cConsist) | 180 | test (multProp1 . cConsist) |
181 | test (multProp2 . rConsist) | 181 | test (multProp2 . rConsist) |
182 | test (multProp2 . cConsist) | 182 | test (multProp2 . cConsist) |
183 | putStrLn "------ sub-trans" | ||
184 | test (subProp . rM) | ||
185 | test (subProp . cM) | ||
183 | putStrLn "------ lu" | 186 | putStrLn "------ lu" |
184 | test (luProp . rM) | 187 | test (luProp . rM) |
185 | test (luProp . cM) | 188 | test (luProp . cM) |
@@ -305,6 +308,7 @@ makeUnitary v | realPart n > 1 = v / scalar n | |||
305 | -- | Performance measurements. | 308 | -- | Performance measurements. |
306 | runBenchmarks :: IO () | 309 | runBenchmarks :: IO () |
307 | runBenchmarks = do | 310 | runBenchmarks = do |
311 | subBench | ||
308 | multBench | 312 | multBench |
309 | svdBench | 313 | svdBench |
310 | eigBench | 314 | eigBench |
@@ -335,6 +339,16 @@ multb n = foldl1' (<>) (replicate (10^6) (ident n :: Matrix Double)) | |||
335 | 339 | ||
336 | -------------------------------- | 340 | -------------------------------- |
337 | 341 | ||
342 | subBench = do | ||
343 | putStrLn "" | ||
344 | let g = foldl1' (.) (replicate (10^5) (\v -> subVector 1 (dim v -1) v)) | ||
345 | time "0.1M subVector " (g (constant 1 (1+10^5) :: Vector Double) @> 0) | ||
346 | let f = foldl1' (.) (replicate (10^5) (fromRows.toRows)) | ||
347 | time "subVector-join 3" (f (ident 3 :: Matrix Double) @@>(0,0)) | ||
348 | time "subVector-join 10" (f (ident 10 :: Matrix Double) @@>(0,0)) | ||
349 | |||
350 | -------------------------------- | ||
351 | |||
338 | multBench = do | 352 | multBench = do |
339 | let a = ident 1000 :: Matrix Double | 353 | let a = ident 1000 :: Matrix Double |
340 | let b = ident 2000 :: Matrix Double | 354 | let b = ident 2000 :: Matrix Double |
diff --git a/lib/Numeric/LinearAlgebra/Tests/Properties.hs b/lib/Numeric/LinearAlgebra/Tests/Properties.hs index 93175f2..6d176fa 100644 --- a/lib/Numeric/LinearAlgebra/Tests/Properties.hs +++ b/lib/Numeric/LinearAlgebra/Tests/Properties.hs | |||
@@ -38,6 +38,7 @@ module Numeric.LinearAlgebra.Tests.Properties ( | |||
38 | cholProp, | 38 | cholProp, |
39 | expmDiagProp, | 39 | expmDiagProp, |
40 | multProp1, multProp2, | 40 | multProp1, multProp2, |
41 | subProp, | ||
41 | linearSolveProp, linearSolveProp2 | 42 | linearSolveProp, linearSolveProp2 |
42 | ) where | 43 | ) where |
43 | 44 | ||
@@ -243,3 +244,6 @@ linearSolveProp2 f (a,x) = not wc `trivial` (not wc || a <> f a b |~| b) | |||
243 | where q = min (rows a) (cols a) | 244 | where q = min (rows a) (cols a) |
244 | b = a <> x | 245 | b = a <> x |
245 | wc = rank a == q | 246 | wc = rank a == q |
247 | |||
248 | subProp m = m == (trans . fromColumns . toRows) m | ||
249 | |||