diff options
Diffstat (limited to 'lib/GSL/Vector.hs')
-rw-r--r-- | lib/GSL/Vector.hs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/GSL/Vector.hs b/lib/GSL/Vector.hs index e538b7e..3225139 100644 --- a/lib/GSL/Vector.hs +++ b/lib/GSL/Vector.hs | |||
@@ -18,7 +18,7 @@ module GSL.Vector ( | |||
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 | 21 | scale, addConstant, add, mul, |
22 | ) where | 22 | ) where |
23 | 23 | ||
24 | import Data.Packed.Internal | 24 | import Data.Packed.Internal |
@@ -79,6 +79,18 @@ addConstant x v | isReal baseOf v = scast $ vectorMapValR AddConstant (scast x) | |||
79 | | isComp baseOf v = scast $ vectorMapValC AddConstant (scast x) (scast v) | 79 | | isComp baseOf v = scast $ vectorMapValC AddConstant (scast x) (scast v) |
80 | | otherwise = fromList $ map (*x) $ toList v | 80 | | otherwise = fromList $ map (*x) $ toList v |
81 | 81 | ||
82 | add :: (Num a, Field a) => Vector a -> Vector a -> Vector a | ||
83 | add u v | isReal baseOf v = scast $ vectorZipR Add (scast u) (scast v) | ||
84 | | isComp baseOf v = scast $ vectorZipC Add (scast u) (scast v) | ||
85 | | otherwise = fromList $ zipWith (+) (toList u) (toList v) | ||
86 | |||
87 | mul :: (Num a, Field a) => Vector a -> Vector a -> Vector a | ||
88 | mul u v | isReal baseOf v = scast $ vectorZipR Mul (scast u) (scast v) | ||
89 | | isComp baseOf v = scast $ vectorZipC Mul (scast u) (scast v) | ||
90 | | otherwise = fromList $ zipWith (*) (toList u) (toList v) | ||
91 | |||
92 | |||
93 | |||
82 | ------------------------------------------------------------------ | 94 | ------------------------------------------------------------------ |
83 | 95 | ||
84 | toScalarAux fun code v = unsafePerformIO $ do | 96 | toScalarAux fun code v = unsafePerformIO $ do |