diff options
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Instances.hs')
-rw-r--r-- | lib/Numeric/LinearAlgebra/Instances.hs | 18 |
1 files changed, 18 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 | ||
51 | instance (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 | |||
58 | instance (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 | |||
64 | breakAt c l = (a++[c],tail b) where | ||
65 | (a,b) = break (==c) l | ||
66 | |||
67 | ------------------------------------------------------------------ | ||
68 | |||
51 | adaptScalar f1 f2 f3 x y | 69 | adaptScalar 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) |