From 97e8a48be58fd53afccc7ae01ee6ec5805d5c1cd Mon Sep 17 00:00:00 2001 From: Vivian McPhail Date: Thu, 8 Jul 2010 23:03:48 +0000 Subject: Linear and Floating (Complex Float) --- lib/Numeric/GSL/Vector.hs | 24 ++++- lib/Numeric/GSL/gsl-aux.c | 126 ++++++++++++++++++++++++++ lib/Numeric/LinearAlgebra/Instances.hs | 29 ++++++ lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.c | 22 +++++ lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.h | 6 ++ lib/Numeric/LinearAlgebra/Linear.hs | 11 +++ 6 files changed, 215 insertions(+), 3 deletions(-) (limited to 'lib/Numeric') diff --git a/lib/Numeric/GSL/Vector.hs b/lib/Numeric/GSL/Vector.hs index 0148c4f..14ba0ff 100644 --- a/lib/Numeric/GSL/Vector.hs +++ b/lib/Numeric/GSL/Vector.hs @@ -17,9 +17,9 @@ module Numeric.GSL.Vector ( sumF, sumR, sumQ, sumC, dotF, dotR, dotQ, dotC, FunCodeS(..), toScalarR, toScalarF, toScalarC, toScalarQ, - FunCodeV(..), vectorMapR, vectorMapC, vectorMapF, - FunCodeSV(..), vectorMapValR, vectorMapValC, vectorMapValF, - FunCodeVV(..), vectorZipR, vectorZipC, vectorZipF, + FunCodeV(..), vectorMapR, vectorMapC, vectorMapF, vectorMapQ, + FunCodeSV(..), vectorMapValR, vectorMapValC, vectorMapValF, vectorMapValQ, + FunCodeVV(..), vectorZipR, vectorZipC, vectorZipF, vectorZipQ, RandDist(..), randomVector ) where @@ -214,6 +214,12 @@ vectorMapF = vectorMapAux c_vectorMapF foreign import ccall safe "gsl-aux.h mapF" c_vectorMapF :: CInt -> TFF +-- | map of real vectors with given function +vectorMapQ :: FunCodeV -> Vector (Complex Float) -> Vector (Complex Float) +vectorMapQ = vectorMapAux c_vectorMapQ + +foreign import ccall safe "gsl-aux.h mapQ" c_vectorMapQ :: CInt -> TQVQV + ------------------------------------------------------------------- -- | map of real vectors with given function @@ -234,6 +240,12 @@ vectorMapValF oper = vectorMapValAux c_vectorMapValF (fromei oper) foreign import ccall safe "gsl-aux.h mapValF" c_vectorMapValF :: CInt -> Ptr Float -> TFF +-- | map of complex vectors with given function +vectorMapValQ :: FunCodeSV -> Complex Float -> Vector (Complex Float) -> Vector (Complex Float) +vectorMapValQ oper = vectorMapValAux c_vectorMapValQ (fromei oper) + +foreign import ccall safe "gsl-aux.h mapValQ" c_vectorMapValQ :: CInt -> Ptr (Complex Float) -> TQVQV + ------------------------------------------------------------------- -- | elementwise operation on real vectors @@ -254,6 +266,12 @@ vectorZipF = vectorZipAux c_vectorZipF foreign import ccall safe "gsl-aux.h zipF" c_vectorZipF :: CInt -> TFFF +-- | elementwise operation on complex vectors +vectorZipQ :: FunCodeVV -> Vector (Complex Float) -> Vector (Complex Float) -> Vector (Complex Float) +vectorZipQ = vectorZipAux c_vectorZipQ + +foreign import ccall safe "gsl-aux.h zipQ" c_vectorZipQ :: CInt -> TQVQVQV + ----------------------------------------------------------------------- data RandDist = Uniform -- ^ uniform distribution in [0,1) diff --git a/lib/Numeric/GSL/gsl-aux.c b/lib/Numeric/GSL/gsl-aux.c index 3f9eeba..689989d 100644 --- a/lib/Numeric/GSL/gsl-aux.c +++ b/lib/Numeric/GSL/gsl-aux.c @@ -393,6 +393,83 @@ int mapC(int code, KCVEC(x), CVEC(r)) { } +gsl_complex_float complex_float_math_fun(gsl_complex (*cf)(gsl_complex), gsl_complex_float a) +{ + gsl_complex c; + gsl_complex r; + + gsl_complex_float float_r; + + c.dat[0] = a.dat[0]; + c.dat[1] = a.dat[1]; + + r = (*cf)(c); + + float_r.dat[0] = r.dat[0]; + float_r.dat[1] = r.dat[1]; + + return float_r; +} + +gsl_complex_float complex_float_math_op(gsl_complex (*cf)(gsl_complex,gsl_complex), + gsl_complex_float a,gsl_complex_float b) +{ + gsl_complex c1; + gsl_complex c2; + gsl_complex r; + + gsl_complex_float float_r; + + c1.dat[0] = a.dat[0]; + c1.dat[1] = a.dat[1]; + + c2.dat[0] = b.dat[0]; + c2.dat[1] = b.dat[1]; + + r = (*cf)(c1,c2); + + float_r.dat[0] = r.dat[0]; + float_r.dat[1] = r.dat[1]; + + return float_r; +} + +#define OPC(C,F) case C: { for(k=0;k Eq (Matrix a) where (==) = equal @@ -209,6 +217,27 @@ instance Floating (Vector (Complex Double)) where ----------------------------------------------------------- +instance Floating (Vector (Complex Float)) where + sin = vectorMapQ Sin + cos = vectorMapQ Cos + tan = vectorMapQ Tan + asin = vectorMapQ ASin + acos = vectorMapQ ACos + atan = vectorMapQ ATan + sinh = vectorMapQ Sinh + cosh = vectorMapQ Cosh + tanh = vectorMapQ Tanh + asinh = vectorMapQ ASinh + acosh = vectorMapQ ACosh + atanh = vectorMapQ ATanh + exp = vectorMapQ Exp + log = vectorMapQ Log + sqrt = vectorMapQ Sqrt + (**) = adaptScalar (vectorMapValQ PowSV) (vectorZipQ Pow) (flip (vectorMapValQ PowVS)) + pi = fromList [pi] + +----------------------------------------------------------- + instance (Linear Vector a, Floating (Vector a), Fractional (Matrix a)) => Floating (Matrix a) where sin = liftMatrix sin cos = liftMatrix cos diff --git a/lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.c b/lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.c index b9c2572..7a40991 100644 --- a/lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.c +++ b/lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.c @@ -1063,6 +1063,18 @@ int transR(KDMAT(x),DMAT(t)) { OK } +int transQ(KQMAT(x),QMAT(t)) { + REQUIRES(xr==tc && xc==tr,BAD_SIZE); + DEBUGMSG("transQ"); + int i,j; + for (i=0; i (Linear Matrix a) where scale x = liftMatrix (scale x) scaleRecip x = liftMatrix (scaleRecip x) -- cgit v1.2.3