summaryrefslogtreecommitdiff
path: root/lib/GSL/Vector.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-09-08 09:46:33 +0000
committerAlberto Ruiz <aruiz@um.es>2007-09-08 09:46:33 +0000
commit34380f2b5d7b048a4d68197f16a8db0e53742030 (patch)
tree444aff88cda5c247d49bac0d294d8cfb9ef7bf23 /lib/GSL/Vector.hs
parent0c38c1b0e122a56ea98c494e60ba90afe2688664 (diff)
type classes
Diffstat (limited to 'lib/GSL/Vector.hs')
-rw-r--r--lib/GSL/Vector.hs31
1 files changed, 1 insertions, 30 deletions
diff --git a/lib/GSL/Vector.hs b/lib/GSL/Vector.hs
index 0b3c3a9..b405ff8 100644
--- a/lib/GSL/Vector.hs
+++ b/lib/GSL/Vector.hs
@@ -17,8 +17,7 @@ module GSL.Vector (
17 FunCodeS(..), toScalarR, 17 FunCodeS(..), toScalarR,
18 FunCodeV(..), vectorMapR, vectorMapC, 18 FunCodeV(..), vectorMapR, vectorMapC,
19 FunCodeSV(..), vectorMapValR, vectorMapValC, 19 FunCodeSV(..), vectorMapValR, vectorMapValC,
20 FunCodeVV(..), vectorZipR, vectorZipC, 20 FunCodeVV(..), vectorZipR, vectorZipC
21 scale, addConstant, add, sub, mul,
22) where 21) where
23 22
24import Data.Packed.Internal.Common 23import Data.Packed.Internal.Common
@@ -70,34 +69,6 @@ data FunCodeS = Norm2
70 | Min 69 | Min
71 deriving Enum 70 deriving Enum
72 71
73
74scale :: (Num a, Field a) => a -> Vector a -> Vector a
75scale x v | isReal baseOf v = scast $ vectorMapValR Scale (scast x) (scast v)
76 | isComp baseOf v = scast $ vectorMapValC Scale (scast x) (scast v)
77 | otherwise = fromList $ map (*x) $ toList v
78
79addConstant :: (Num a, Field a) => a -> Vector a -> Vector a
80addConstant x v | isReal baseOf v = scast $ vectorMapValR AddConstant (scast x) (scast v)
81 | isComp baseOf v = scast $ vectorMapValC AddConstant (scast x) (scast v)
82 | otherwise = fromList $ map (*x) $ toList v
83
84add :: (Num a, Field a) => Vector a -> Vector a -> Vector a
85add u v | isReal baseOf v = scast $ vectorZipR Add (scast u) (scast v)
86 | isComp baseOf v = scast $ vectorZipC Add (scast u) (scast v)
87 | otherwise = fromList $ zipWith (+) (toList u) (toList v)
88
89sub :: (Num a, Field a) => Vector a -> Vector a -> Vector a
90sub u v | isReal baseOf v = scast $ vectorZipR Sub (scast u) (scast v)
91 | isComp baseOf v = scast $ vectorZipC Sub (scast u) (scast v)
92 | otherwise = fromList $ zipWith (-) (toList u) (toList v)
93
94mul :: (Num a, Field a) => Vector a -> Vector a -> Vector a
95mul u v | isReal baseOf v = scast $ vectorZipR Mul (scast u) (scast v)
96 | isComp baseOf v = scast $ vectorZipC Mul (scast u) (scast v)
97 | otherwise = fromList $ zipWith (*) (toList u) (toList v)
98
99
100
101------------------------------------------------------------------ 72------------------------------------------------------------------
102 73
103toScalarAux fun code v = unsafePerformIO $ do 74toScalarAux fun code v = unsafePerformIO $ do