diff options
author | Alberto Ruiz <aruiz@um.es> | 2010-05-12 08:33:37 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2010-05-12 08:33:37 +0000 |
commit | ecb38d98f853d969864e586a445a1432445fdab2 (patch) | |
tree | 4ca5edd0b9a37adec66bffb764d86ae636f34d8f /lib/Numeric/LinearAlgebra/Instances.hs | |
parent | ff8ba85a52acdd1e30f45ba73ae0c40986c8a9d4 (diff) |
flag -fvector
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Instances.hs')
-rw-r--r-- | lib/Numeric/LinearAlgebra/Instances.hs | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/lib/Numeric/LinearAlgebra/Instances.hs b/lib/Numeric/LinearAlgebra/Instances.hs index b4a769e..1992db0 100644 --- a/lib/Numeric/LinearAlgebra/Instances.hs +++ b/lib/Numeric/LinearAlgebra/Instances.hs | |||
@@ -24,10 +24,11 @@ import Numeric.GSL.Vector | |||
24 | import Data.Packed.Matrix | 24 | import Data.Packed.Matrix |
25 | import Data.Complex | 25 | import Data.Complex |
26 | import Data.List(transpose,intersperse) | 26 | import Data.List(transpose,intersperse) |
27 | import Foreign(Storable) | ||
28 | -- import Data.Monoid | ||
29 | import Data.Packed.Internal.Vector | 27 | import Data.Packed.Internal.Vector |
30 | -- import Control.Parallel.Strategies | 28 | |
29 | #ifndef VECTOR | ||
30 | import Foreign(Storable) | ||
31 | #endif | ||
31 | 32 | ||
32 | ------------------------------------------------------------------ | 33 | ------------------------------------------------------------------ |
33 | 34 | ||
@@ -43,9 +44,13 @@ dsp as = (++" ]") . (" ["++) . init . drop 2 . unlines . map (" , "++) . map unw | |||
43 | pad n str = replicate (n - length str) ' ' ++ str | 44 | pad n str = replicate (n - length str) ' ' ++ str |
44 | unwords' = concat . intersperse ", " | 45 | unwords' = concat . intersperse ", " |
45 | 46 | ||
47 | #ifndef VECTOR | ||
48 | |||
46 | instance (Show a, Storable a) => (Show (Vector a)) where | 49 | instance (Show a, Storable a) => (Show (Vector a)) where |
47 | show v = (show (dim v))++" |> " ++ show (toList v) | 50 | show v = (show (dim v))++" |> " ++ show (toList v) |
48 | 51 | ||
52 | #endif | ||
53 | |||
49 | ------------------------------------------------------------------ | 54 | ------------------------------------------------------------------ |
50 | 55 | ||
51 | instance (Element a, Read a) => Read (Matrix a) where | 56 | instance (Element a, Read a) => Read (Matrix a) where |
@@ -55,12 +60,23 @@ instance (Element a, Read a) => Read (Matrix a) where | |||
55 | cs = read . init . fst. breakAt ')' . snd . breakAt '<' $ dims | 60 | cs = read . init . fst. breakAt ')' . snd . breakAt '<' $ dims |
56 | rs = read . snd . breakAt '(' .init . fst . breakAt '>' $ dims | 61 | rs = read . snd . breakAt '(' .init . fst . breakAt '>' $ dims |
57 | 62 | ||
63 | #ifdef VECTOR | ||
64 | |||
65 | instance (Element a, Read a) => Read (Vector a) where | ||
66 | readsPrec _ s = [(fromList . read $ listnums, rest)] | ||
67 | where (thing,trest) = breakAt ']' s | ||
68 | (dims,listnums) = breakAt ' ' (dropWhile (==' ') thing) | ||
69 | rest = drop 31 trest | ||
70 | #else | ||
71 | |||
58 | instance (Element a, Read a) => Read (Vector a) where | 72 | instance (Element a, Read a) => Read (Vector a) where |
59 | readsPrec _ s = [((d |>) . read $ listnums, rest)] | 73 | readsPrec _ s = [((d |>) . read $ listnums, rest)] |
60 | where (thing,rest) = breakAt ']' s | 74 | where (thing,rest) = breakAt ']' s |
61 | (dims,listnums) = breakAt '>' thing | 75 | (dims,listnums) = breakAt '>' thing |
62 | d = read . init . fst . breakAt '|' $ dims | 76 | d = read . init . fst . breakAt '|' $ dims |
63 | 77 | ||
78 | #endif | ||
79 | |||
64 | breakAt c l = (a++[c],tail b) where | 80 | breakAt c l = (a++[c],tail b) where |
65 | (a,b) = break (==c) l | 81 | (a,b) = break (==c) l |
66 | 82 | ||
@@ -71,10 +87,13 @@ adaptScalar f1 f2 f3 x y | |||
71 | | dim y == 1 = f3 x (y@>0) | 87 | | dim y == 1 = f3 x (y@>0) |
72 | | otherwise = f2 x y | 88 | | otherwise = f2 x y |
73 | 89 | ||
90 | #ifndef VECTOR | ||
74 | 91 | ||
75 | instance Linear Vector a => Eq (Vector a) where | 92 | instance Linear Vector a => Eq (Vector a) where |
76 | (==) = equal | 93 | (==) = equal |
77 | 94 | ||
95 | #endif | ||
96 | |||
78 | instance Num (Vector Double) where | 97 | instance Num (Vector Double) where |
79 | (+) = adaptScalar addConstant add (flip addConstant) | 98 | (+) = adaptScalar addConstant add (flip addConstant) |
80 | negate = scale (-1) | 99 | negate = scale (-1) |