summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Data/Packed/Internal/Signatures.hs2
-rw-r--r--lib/Numeric/GSL/Vector.hs14
-rw-r--r--lib/Numeric/GSL/gsl-aux.c29
-rw-r--r--lib/Numeric/LinearAlgebra/Interface.hs2
-rw-r--r--lib/Numeric/LinearAlgebra/Linear.hs49
5 files changed, 68 insertions, 28 deletions
diff --git a/lib/Data/Packed/Internal/Signatures.hs b/lib/Data/Packed/Internal/Signatures.hs
index 1370dbc..78d00fa 100644
--- a/lib/Data/Packed/Internal/Signatures.hs
+++ b/lib/Data/Packed/Internal/Signatures.hs
@@ -54,9 +54,11 @@ type TCMCMCM = CInt -> CInt -> PC -> TCMCM --
54type TCV = CInt -> PC -> IO CInt -- 54type TCV = CInt -> PC -> IO CInt --
55type TCVCV = CInt -> PC -> TCV -- 55type TCVCV = CInt -> PC -> TCV --
56type TCVCVCV = CInt -> PC -> TCVCV -- 56type TCVCVCV = CInt -> PC -> TCVCV --
57type TCVV = CInt -> PC -> TV --
57type TQV = CInt -> PQ -> IO CInt -- 58type TQV = CInt -> PQ -> IO CInt --
58type TQVQV = CInt -> PQ -> TQV -- 59type TQVQV = CInt -> PQ -> TQV --
59type TQVQVQV = CInt -> PQ -> TQVQV -- 60type TQVQVQV = CInt -> PQ -> TQVQV --
61type TQVF = CInt -> PQ -> TF --
60type TCMCV = CInt -> CInt -> PC -> TCV -- 62type TCMCV = CInt -> CInt -> PC -> TCV --
61type TVCV = CInt -> PD -> TCV -- 63type TVCV = CInt -> PD -> TCV --
62type TCVM = CInt -> PC -> TM -- 64type TCVM = CInt -> PC -> TM --
diff --git a/lib/Numeric/GSL/Vector.hs b/lib/Numeric/GSL/Vector.hs
index 97a0f9c..0148c4f 100644
--- a/lib/Numeric/GSL/Vector.hs
+++ b/lib/Numeric/GSL/Vector.hs
@@ -16,7 +16,7 @@
16module Numeric.GSL.Vector ( 16module Numeric.GSL.Vector (
17 sumF, sumR, sumQ, sumC, 17 sumF, sumR, sumQ, sumC,
18 dotF, dotR, dotQ, dotC, 18 dotF, dotR, dotQ, dotC,
19 FunCodeS(..), toScalarR, toScalarF, 19 FunCodeS(..), toScalarR, toScalarF, toScalarC, toScalarQ,
20 FunCodeV(..), vectorMapR, vectorMapC, vectorMapF, 20 FunCodeV(..), vectorMapR, vectorMapC, vectorMapF,
21 FunCodeSV(..), vectorMapValR, vectorMapValC, vectorMapValF, 21 FunCodeSV(..), vectorMapValR, vectorMapValC, vectorMapValF,
22 FunCodeVV(..), vectorZipR, vectorZipC, vectorZipF, 22 FunCodeVV(..), vectorZipR, vectorZipC, vectorZipF,
@@ -182,6 +182,18 @@ toScalarF oper = toScalarAux c_toScalarF (fromei oper)
182 182
183foreign import ccall safe "gsl-aux.h toScalarF" c_toScalarF :: CInt -> TFF 183foreign import ccall safe "gsl-aux.h toScalarF" c_toScalarF :: CInt -> TFF
184 184
185-- | obtains different functions of a vector: only norm1, norm2
186toScalarC :: FunCodeS -> Vector (Complex Double) -> Double
187toScalarC oper = toScalarAux c_toScalarC (fromei oper)
188
189foreign import ccall safe "gsl-aux.h toScalarC" c_toScalarC :: CInt -> TCVV
190
191-- | obtains different functions of a vector: only norm1, norm2
192toScalarQ :: FunCodeS -> Vector (Complex Float) -> Float
193toScalarQ oper = toScalarAux c_toScalarQ (fromei oper)
194
195foreign import ccall safe "gsl-aux.h toScalarQ" c_toScalarQ :: CInt -> TQVF
196
185------------------------------------------------------------------ 197------------------------------------------------------------------
186 198
187-- | map of real vectors with given function 199-- | map of real vectors with given function
diff --git a/lib/Numeric/GSL/gsl-aux.c b/lib/Numeric/GSL/gsl-aux.c
index fe33766..3f9eeba 100644
--- a/lib/Numeric/GSL/gsl-aux.c
+++ b/lib/Numeric/GSL/gsl-aux.c
@@ -234,6 +234,35 @@ int toScalarF(int code, KFVEC(x), FVEC(r)) {
234} 234}
235 235
236 236
237int toScalarC(int code, KCVEC(x), RVEC(r)) {
238 REQUIRES(rn==1,BAD_SIZE);
239 DEBUGMSG("toScalarC");
240 KCVVIEW(x);
241 double res;
242 switch(code) {
243 case 0: { res = gsl_blas_dznrm2(V(x)); break; }
244 case 1: { res = gsl_blas_dzasum(V(x)); break; }
245 default: ERROR(BAD_CODE);
246 }
247 rp[0] = res;
248 OK
249}
250
251int toScalarQ(int code, KQVEC(x), FVEC(r)) {
252 REQUIRES(rn==1,BAD_SIZE);
253 DEBUGMSG("toScalarQ");
254 KQVVIEW(x);
255 float res;
256 switch(code) {
257 case 0: { res = gsl_blas_scnrm2(V(x)); break; }
258 case 1: { res = gsl_blas_scasum(V(x)); break; }
259 default: ERROR(BAD_CODE);
260 }
261 rp[0] = res;
262 OK
263}
264
265
237inline double sign(double x) { 266inline double sign(double x) {
238 if(x>0) { 267 if(x>0) {
239 return +1.0; 268 return +1.0;
diff --git a/lib/Numeric/LinearAlgebra/Interface.hs b/lib/Numeric/LinearAlgebra/Interface.hs
index f8917a0..8d2b52a 100644
--- a/lib/Numeric/LinearAlgebra/Interface.hs
+++ b/lib/Numeric/LinearAlgebra/Interface.hs
@@ -28,7 +28,7 @@ import Numeric.LinearAlgebra.Instances()
28import Data.Packed.Vector 28import Data.Packed.Vector
29import Data.Packed.Matrix 29import Data.Packed.Matrix
30import Numeric.LinearAlgebra.Algorithms 30import Numeric.LinearAlgebra.Algorithms
31import Numeric.LinearAlgebra.Linear 31import Numeric.LinearAlgebra.Linear()
32 32
33--import Numeric.GSL.Vector 33--import Numeric.GSL.Vector
34 34
diff --git a/lib/Numeric/LinearAlgebra/Linear.hs b/lib/Numeric/LinearAlgebra/Linear.hs
index 1651247..e718e83 100644
--- a/lib/Numeric/LinearAlgebra/Linear.hs
+++ b/lib/Numeric/LinearAlgebra/Linear.hs
@@ -16,7 +16,7 @@ Basic optimized operations on vectors and matrices.
16----------------------------------------------------------------------------- 16-----------------------------------------------------------------------------
17 17
18module Numeric.LinearAlgebra.Linear ( 18module Numeric.LinearAlgebra.Linear (
19 Vectors(..), normalise, 19 Vectors(..),
20 Linear(..) 20 Linear(..)
21) where 21) where
22 22
@@ -25,21 +25,18 @@ import Data.Packed.Matrix
25import Data.Complex 25import Data.Complex
26import Numeric.GSL.Vector 26import Numeric.GSL.Vector
27 27
28-- | normalise a vector to unit length 28import Control.Monad(ap)
29normalise :: (Floating a, Vectors Vector a,
30 Linear Vector a, Fractional (Vector a)) => Vector a -> Vector a
31normalise v = scaleRecip (vectorSum v) v
32 29
33-- | basic Vector functions 30-- | basic Vector functions
34class (Num b) => Vectors a b where 31class Num e => Vectors a e where
35 vectorSum :: a b -> b 32 vectorSum :: a e -> e
36 euclidean :: a b -> b 33 euclidean :: a e -> e
37 absSum :: a b -> b 34 absSum :: a e -> e
38 vectorMin :: a b -> b 35 vectorMin :: a e -> e
39 vectorMax :: a b -> b 36 vectorMax :: a e -> e
40 minIdx :: a b -> Int 37 minIdx :: a e -> Int
41 maxIdx :: a b -> Int 38 maxIdx :: a e -> Int
42 dot :: a b -> a b -> b 39 dot :: a e -> a e -> e
43 40
44instance Vectors Vector Float where 41instance Vectors Vector Float where
45 vectorSum = sumF 42 vectorSum = sumF
@@ -63,22 +60,22 @@ instance Vectors Vector Double where
63 60
64instance Vectors Vector (Complex Float) where 61instance Vectors Vector (Complex Float) where
65 vectorSum = sumQ 62 vectorSum = sumQ
66 euclidean = undefined 63 euclidean = (:+ 0) . toScalarQ Norm2
67 absSum = undefined 64 absSum = (:+ 0) . toScalarQ AbsSum
68 vectorMin = undefined 65 vectorMin = ap (@>) minIdx
69 vectorMax = undefined 66 vectorMax = ap (@>) maxIdx
70 minIdx = undefined 67 minIdx = minIdx . (zipVector (*) `ap` mapVector conjugate)
71 maxIdx = undefined 68 maxIdx = maxIdx . (zipVector (*) `ap` mapVector conjugate)
72 dot = dotQ 69 dot = dotQ
73 70
74instance Vectors Vector (Complex Double) where 71instance Vectors Vector (Complex Double) where
75 vectorSum = sumC 72 vectorSum = sumC
76 euclidean = undefined 73 euclidean = (:+ 0) . toScalarC Norm2
77 absSum = undefined 74 absSum = (:+ 0) . toScalarC AbsSum
78 vectorMin = undefined 75 vectorMin = ap (@>) minIdx
79 vectorMax = undefined 76 vectorMax = ap (@>) maxIdx
80 minIdx = undefined 77 minIdx = minIdx . (zipVector (*) `ap` mapVector conjugate)
81 maxIdx = undefined 78 maxIdx = maxIdx . (zipVector (*) `ap` mapVector conjugate)
82 dot = dotC 79 dot = dotC
83 80
84---------------------------------------------------- 81----------------------------------------------------