diff options
author | Alberto Ruiz <aruiz@um.es> | 2007-11-30 19:55:34 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2007-11-30 19:55:34 +0000 |
commit | d7d3b731c037fca41bd9128c3da2a582189cb4d9 (patch) | |
tree | f1bf8f1fa538033ff184d6cc556e808bfaaa71a9 /examples/experiments | |
parent | 975d3730a923387f9d1a0be4f7d11b01b27a09df (diff) |
hide internal modules
Diffstat (limited to 'examples/experiments')
-rw-r--r-- | examples/experiments/Static.hs | 22 | ||||
-rw-r--r-- | examples/experiments/listlike.hs | 8 |
2 files changed, 7 insertions, 23 deletions
diff --git a/examples/experiments/Static.hs b/examples/experiments/Static.hs index 385bb7b..2e4ef4e 100644 --- a/examples/experiments/Static.hs +++ b/examples/experiments/Static.hs | |||
@@ -6,23 +6,15 @@ import Language.Haskell.TH | |||
6 | import Numeric.LinearAlgebra | 6 | import Numeric.LinearAlgebra |
7 | import Foreign | 7 | import Foreign |
8 | import Language.Haskell.TH.Syntax | 8 | import Language.Haskell.TH.Syntax |
9 | import Data.Packed.Internal(Vector(..),Matrix(..)) | ||
10 | 9 | ||
11 | instance Lift Double where | 10 | instance Lift Double where |
12 | lift x = return (LitE (RationalL (toRational x))) | 11 | lift x = return (LitE (RationalL (toRational x))) |
13 | 12 | ||
14 | instance Lift (Ptr Double) where | 13 | instance Lift (Vector a ) where |
15 | lift p = [e| p |] | 14 | lift v = [e| v |] |
16 | 15 | ||
17 | instance Lift (ForeignPtr Double) where | 16 | instance Lift (Matrix a) where |
18 | lift p = [e| p |] | 17 | lift m = [e| m |] |
19 | |||
20 | instance (Lift a, Storable a, Lift (Ptr a), Lift (ForeignPtr a)) => Lift (Vector a ) where | ||
21 | lift (V n fp) = [e| V $(lift n) $(lift fp) |] | ||
22 | |||
23 | instance (Lift (Vector a)) => Lift (Matrix a) where | ||
24 | lift (MC r c v) = [e| MC $(lift r) $(lift c) $(lift v) |] | ||
25 | lift (MF r c v) = [e| MF $(lift r) $(lift c) $(lift v) |] | ||
26 | 18 | ||
27 | tdim :: Int -> ExpQ | 19 | tdim :: Int -> ExpQ |
28 | tdim 0 = [| Z |] | 20 | tdim 0 = [| Z |] |
@@ -52,7 +44,7 @@ createl d l = SVec (fromList l) | |||
52 | createv :: Storable t => d -> Vector t -> SVec d t | 44 | createv :: Storable t => d -> Vector t -> SVec d t |
53 | createv d v = SVec v | 45 | createv d v = SVec v |
54 | 46 | ||
55 | --vec'' v = [|createv ($(tdim (dim v))) v|] | 47 | vec'' v = [|createv ($(tdim (dim v))) v|] |
56 | 48 | ||
57 | vec' :: [Double] -> ExpQ | 49 | vec' :: [Double] -> ExpQ |
58 | vec' d = [| createl ($(tdim (length d))) d |] | 50 | vec' d = [| createl ($(tdim (length d))) d |] |
@@ -71,8 +63,8 @@ vec :: [Double] -> ExpQ | |||
71 | vec d = mat (length d) 1 d | 63 | vec d = mat (length d) 1 d |
72 | 64 | ||
73 | 65 | ||
74 | mat' :: Matrix Double -> ExpQ | 66 | --mat' :: Matrix Double -> ExpQ |
75 | mat' m = [| createm ($(tdim (rows m))) ($(tdim (cols m))) m |] | 67 | --mat' m = [| createm ($(tdim (rows m))) ($(tdim (cols m))) m |] |
76 | 68 | ||
77 | covec :: [Double] -> ExpQ | 69 | covec :: [Double] -> ExpQ |
78 | covec d = mat 1 (length d) d | 70 | covec d = mat 1 (length d) d |
diff --git a/examples/experiments/listlike.hs b/examples/experiments/listlike.hs index 43216cb..2d62447 100644 --- a/examples/experiments/listlike.hs +++ b/examples/experiments/listlike.hs | |||
@@ -3,16 +3,8 @@ | |||
3 | import qualified Data.ListLike as LL | 3 | import qualified Data.ListLike as LL |
4 | import Numeric.LinearAlgebra | 4 | import Numeric.LinearAlgebra |
5 | import Data.Monoid | 5 | import Data.Monoid |
6 | import Data.Packed.Internal.Vector | ||
7 | import Foreign | 6 | import Foreign |
8 | 7 | ||
9 | instance (Storable a) => Monoid (Vector a) where | ||
10 | mempty = V { dim = 0, fptr = undefined, ptr = undefined } | ||
11 | mappend a b = mconcat [a,b] | ||
12 | mconcat = j . filter ((>0).dim) | ||
13 | where j [] = mempty | ||
14 | j l = join l | ||
15 | |||
16 | instance Storable a => LL.FoldableLL (Vector a) a where | 8 | instance Storable a => LL.FoldableLL (Vector a) a where |
17 | foldl f x v = foldl f x (toList v) | 9 | foldl f x v = foldl f x (toList v) |
18 | foldr f x v = foldr f x (toList v) | 10 | foldr f x v = foldr f x (toList v) |