summaryrefslogtreecommitdiff
path: root/lib/Numeric
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Numeric')
-rw-r--r--lib/Numeric/LinearAlgebra/Instances.hs18
-rw-r--r--lib/Numeric/LinearAlgebra/Tests.hs5
2 files changed, 23 insertions, 0 deletions
diff --git a/lib/Numeric/LinearAlgebra/Instances.hs b/lib/Numeric/LinearAlgebra/Instances.hs
index c8bf126..8e11d78 100644
--- a/lib/Numeric/LinearAlgebra/Instances.hs
+++ b/lib/Numeric/LinearAlgebra/Instances.hs
@@ -48,6 +48,24 @@ instance (Show a, Storable a) => (Show (Vector a)) where
48 48
49------------------------------------------------------------------ 49------------------------------------------------------------------
50 50
51instance (Element a, Read a) => Read (Matrix a) where
52 readsPrec _ s = [((rows><cols) . read $ listnums, rest)]
53 where (thing,rest) = breakAt ']' s
54 (dims,listnums) = breakAt ')' thing
55 cols = read . init . fst. breakAt ')' . snd . breakAt '<' $ dims
56 rows = read . snd . breakAt '(' .init . fst . breakAt '>' $ dims
57
58instance (Element a, Read a) => Read (Vector a) where
59 readsPrec _ s = [((d |>) . read $ listnums, rest)]
60 where (thing,rest) = breakAt ']' s
61 (dims,listnums) = breakAt '>' thing
62 d = read . init . fst . breakAt '|' $ dims
63
64breakAt c l = (a++[c],tail b) where
65 (a,b) = break (==c) l
66
67------------------------------------------------------------------
68
51adaptScalar f1 f2 f3 x y 69adaptScalar f1 f2 f3 x y
52 | dim x == 1 = f1 (x@>0) y 70 | dim x == 1 = f1 (x@>0) y
53 | dim y == 1 = f3 x (y@>0) 71 | dim y == 1 = f3 x (y@>0)
diff --git a/lib/Numeric/LinearAlgebra/Tests.hs b/lib/Numeric/LinearAlgebra/Tests.hs
index 31ba2ff..7b28075 100644
--- a/lib/Numeric/LinearAlgebra/Tests.hs
+++ b/lib/Numeric/LinearAlgebra/Tests.hs
@@ -174,6 +174,11 @@ runTests n = do
174 test (\u -> sin u ** 2 + cos u ** 2 |~| (1::RM)) 174 test (\u -> sin u ** 2 + cos u ** 2 |~| (1::RM))
175 test (\u -> cos u * tan u |~| sin (u::RM)) 175 test (\u -> cos u * tan u |~| sin (u::RM))
176 test (\u -> (cos u * tan u) |~| sin (u::CM)) 176 test (\u -> (cos u * tan u) |~| sin (u::CM))
177 putStrLn "------ read . show"
178 test (\m -> (m::RM) == read (show m))
179 test (\m -> (m::CM) == read (show m))
180 test (\m -> toRows (m::RM) == read (show (toRows m)))
181 test (\m -> toRows (m::CM) == read (show (toRows m)))
177 putStrLn "------ some unit tests" 182 putStrLn "------ some unit tests"
178 runTestTT $ TestList 183 runTestTT $ TestList
179 [ utest "1E5 rots" rotTest 184 [ utest "1E5 rots" rotTest