summaryrefslogtreecommitdiff
path: root/examples/experiments
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-11-30 19:55:34 +0000
committerAlberto Ruiz <aruiz@um.es>2007-11-30 19:55:34 +0000
commitd7d3b731c037fca41bd9128c3da2a582189cb4d9 (patch)
treef1bf8f1fa538033ff184d6cc556e808bfaaa71a9 /examples/experiments
parent975d3730a923387f9d1a0be4f7d11b01b27a09df (diff)
hide internal modules
Diffstat (limited to 'examples/experiments')
-rw-r--r--examples/experiments/Static.hs22
-rw-r--r--examples/experiments/listlike.hs8
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
6import Numeric.LinearAlgebra 6import Numeric.LinearAlgebra
7import Foreign 7import Foreign
8import Language.Haskell.TH.Syntax 8import Language.Haskell.TH.Syntax
9import Data.Packed.Internal(Vector(..),Matrix(..))
10 9
11instance Lift Double where 10instance Lift Double where
12 lift x = return (LitE (RationalL (toRational x))) 11 lift x = return (LitE (RationalL (toRational x)))
13 12
14instance Lift (Ptr Double) where 13instance Lift (Vector a ) where
15 lift p = [e| p |] 14 lift v = [e| v |]
16 15
17instance Lift (ForeignPtr Double) where 16instance Lift (Matrix a) where
18 lift p = [e| p |] 17 lift m = [e| m |]
19
20instance (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
23instance (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
27tdim :: Int -> ExpQ 19tdim :: Int -> ExpQ
28tdim 0 = [| Z |] 20tdim 0 = [| Z |]
@@ -52,7 +44,7 @@ createl d l = SVec (fromList l)
52createv :: Storable t => d -> Vector t -> SVec d t 44createv :: Storable t => d -> Vector t -> SVec d t
53createv d v = SVec v 45createv d v = SVec v
54 46
55--vec'' v = [|createv ($(tdim (dim v))) v|] 47vec'' v = [|createv ($(tdim (dim v))) v|]
56 48
57vec' :: [Double] -> ExpQ 49vec' :: [Double] -> ExpQ
58vec' d = [| createl ($(tdim (length d))) d |] 50vec' d = [| createl ($(tdim (length d))) d |]
@@ -71,8 +63,8 @@ vec :: [Double] -> ExpQ
71vec d = mat (length d) 1 d 63vec d = mat (length d) 1 d
72 64
73 65
74mat' :: Matrix Double -> ExpQ 66--mat' :: Matrix Double -> ExpQ
75mat' m = [| createm ($(tdim (rows m))) ($(tdim (cols m))) m |] 67--mat' m = [| createm ($(tdim (rows m))) ($(tdim (cols m))) m |]
76 68
77covec :: [Double] -> ExpQ 69covec :: [Double] -> ExpQ
78covec d = mat 1 (length d) d 70covec 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 @@
3import qualified Data.ListLike as LL 3import qualified Data.ListLike as LL
4import Numeric.LinearAlgebra 4import Numeric.LinearAlgebra
5import Data.Monoid 5import Data.Monoid
6import Data.Packed.Internal.Vector
7import Foreign 6import Foreign
8 7
9instance (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
16instance Storable a => LL.FoldableLL (Vector a) a where 8instance 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)