summaryrefslogtreecommitdiff
path: root/lib/Numeric/LinearAlgebra
diff options
context:
space:
mode:
authorVivian McPhail <haskell.vivian.mcphail@gmail.com>2010-07-08 23:03:48 +0000
committerVivian McPhail <haskell.vivian.mcphail@gmail.com>2010-07-08 23:03:48 +0000
commit97e8a48be58fd53afccc7ae01ee6ec5805d5c1cd (patch)
tree837f4a6b21e0317da834c8ac42c8adfce9a22d24 /lib/Numeric/LinearAlgebra
parentb8699c4f1acff1e3f31cdbac1a7a4a8864b1eeba (diff)
Linear and Floating (Complex Float)
Diffstat (limited to 'lib/Numeric/LinearAlgebra')
-rw-r--r--lib/Numeric/LinearAlgebra/Instances.hs29
-rw-r--r--lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.c22
-rw-r--r--lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.h6
-rw-r--r--lib/Numeric/LinearAlgebra/Linear.hs11
4 files changed, 68 insertions, 0 deletions
diff --git a/lib/Numeric/LinearAlgebra/Instances.hs b/lib/Numeric/LinearAlgebra/Instances.hs
index bba89c8..04a9d88 100644
--- a/lib/Numeric/LinearAlgebra/Instances.hs
+++ b/lib/Numeric/LinearAlgebra/Instances.hs
@@ -118,6 +118,14 @@ instance Num (Vector (Complex Double)) where
118 abs = vectorMapC Abs 118 abs = vectorMapC Abs
119 fromInteger = fromList . return . fromInteger 119 fromInteger = fromList . return . fromInteger
120 120
121instance Num (Vector (Complex Float)) where
122 (+) = adaptScalar addConstant add (flip addConstant)
123 negate = scale (-1)
124 (*) = adaptScalar scale mul (flip scale)
125 signum = vectorMapQ Sign
126 abs = vectorMapQ Abs
127 fromInteger = fromList . return . fromInteger
128
121instance Linear Matrix a => Eq (Matrix a) where 129instance Linear Matrix a => Eq (Matrix a) where
122 (==) = equal 130 (==) = equal
123 131
@@ -209,6 +217,27 @@ instance Floating (Vector (Complex Double)) where
209 217
210----------------------------------------------------------- 218-----------------------------------------------------------
211 219
220instance Floating (Vector (Complex Float)) where
221 sin = vectorMapQ Sin
222 cos = vectorMapQ Cos
223 tan = vectorMapQ Tan
224 asin = vectorMapQ ASin
225 acos = vectorMapQ ACos
226 atan = vectorMapQ ATan
227 sinh = vectorMapQ Sinh
228 cosh = vectorMapQ Cosh
229 tanh = vectorMapQ Tanh
230 asinh = vectorMapQ ASinh
231 acosh = vectorMapQ ACosh
232 atanh = vectorMapQ ATanh
233 exp = vectorMapQ Exp
234 log = vectorMapQ Log
235 sqrt = vectorMapQ Sqrt
236 (**) = adaptScalar (vectorMapValQ PowSV) (vectorZipQ Pow) (flip (vectorMapValQ PowVS))
237 pi = fromList [pi]
238
239-----------------------------------------------------------
240
212instance (Linear Vector a, Floating (Vector a), Fractional (Matrix a)) => Floating (Matrix a) where 241instance (Linear Vector a, Floating (Vector a), Fractional (Matrix a)) => Floating (Matrix a) where
213 sin = liftMatrix sin 242 sin = liftMatrix sin
214 cos = liftMatrix cos 243 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)) {
1063 OK 1063 OK
1064} 1064}
1065 1065
1066int transQ(KQMAT(x),QMAT(t)) {
1067 REQUIRES(xr==tc && xc==tr,BAD_SIZE);
1068 DEBUGMSG("transQ");
1069 int i,j;
1070 for (i=0; i<tr; i++) {
1071 for (j=0; j<tc; j++) {
1072 ((complex*)tp)[i*tc+j] = ((complex*)xp)[j*xc+i];
1073 }
1074 }
1075 OK
1076}
1077
1066int transC(KCMAT(x),CMAT(t)) { 1078int transC(KCMAT(x),CMAT(t)) {
1067 REQUIRES(xr==tc && xc==tr,BAD_SIZE); 1079 REQUIRES(xr==tc && xc==tr,BAD_SIZE);
1068 DEBUGMSG("transC"); 1080 DEBUGMSG("transC");
@@ -1097,6 +1109,16 @@ int constantR(double * pval, DVEC(r)) {
1097 OK 1109 OK
1098} 1110}
1099 1111
1112int constantQ(complex* pval, QVEC(r)) {
1113 DEBUGMSG("constantQ")
1114 int k;
1115 complex val = *pval;
1116 for(k=0;k<rn;k++) {
1117 ((complex*)rp)[k]=val;
1118 }
1119 OK
1120}
1121
1100int constantC(doublecomplex* pval, CVEC(r)) { 1122int constantC(doublecomplex* pval, CVEC(r)) {
1101 DEBUGMSG("constantC") 1123 DEBUGMSG("constantC")
1102 int k; 1124 int k;
diff --git a/lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.h b/lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.h
index 415a6ab..d01d9e5 100644
--- a/lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.h
+++ b/lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.h
@@ -42,16 +42,20 @@ typedef short ftnlen;
42 42
43#define FVEC(A) int A##n, float*A##p 43#define FVEC(A) int A##n, float*A##p
44#define DVEC(A) int A##n, double*A##p 44#define DVEC(A) int A##n, double*A##p
45#define QVEC(A) int A##n, float*A##p
45#define CVEC(A) int A##n, double*A##p 46#define CVEC(A) int A##n, double*A##p
46#define FMAT(A) int A##r, int A##c, float* A##p 47#define FMAT(A) int A##r, int A##c, float* A##p
47#define DMAT(A) int A##r, int A##c, double* A##p 48#define DMAT(A) int A##r, int A##c, double* A##p
49#define QMAT(A) int A##r, int A##c, float* A##p
48#define CMAT(A) int A##r, int A##c, double* A##p 50#define CMAT(A) int A##r, int A##c, double* A##p
49 51
50#define KFVEC(A) int A##n, const float*A##p 52#define KFVEC(A) int A##n, const float*A##p
51#define KDVEC(A) int A##n, const double*A##p 53#define KDVEC(A) int A##n, const double*A##p
54#define KQVEC(A) int A##n, const float*A##p
52#define KCVEC(A) int A##n, const double*A##p 55#define KCVEC(A) int A##n, const double*A##p
53#define KFMAT(A) int A##r, int A##c, const float* A##p 56#define KFMAT(A) int A##r, int A##c, const float* A##p
54#define KDMAT(A) int A##r, int A##c, const double* A##p 57#define KDMAT(A) int A##r, int A##c, const double* A##p
58#define KQMAT(A) int A##r, int A##c, const float* A##p
55#define KCMAT(A) int A##r, int A##c, const double* A##p 59#define KCMAT(A) int A##r, int A##c, const double* A##p
56 60
57/********************************************************/ 61/********************************************************/
@@ -61,10 +65,12 @@ int multiplyC(int ta, int tb, KCMAT(a),KCMAT(b),CMAT(r));
61 65
62int transF(KFMAT(x),FMAT(t)); 66int transF(KFMAT(x),FMAT(t));
63int transR(KDMAT(x),DMAT(t)); 67int transR(KDMAT(x),DMAT(t));
68int transQ(KQMAT(x),QMAT(t));
64int transC(KCMAT(x),CMAT(t)); 69int transC(KCMAT(x),CMAT(t));
65 70
66int constantF(float * pval, FVEC(r)); 71int constantF(float * pval, FVEC(r));
67int constantR(double * pval, DVEC(r)); 72int constantR(double * pval, DVEC(r));
73int constantQ(complex* pval, QVEC(r));
68int constantC(doublecomplex* pval, CVEC(r)); 74int constantC(doublecomplex* pval, CVEC(r));
69 75
70int svd_l_R(KDMAT(x),DMAT(u),DVEC(s),DMAT(v)); 76int svd_l_R(KDMAT(x),DMAT(u),DVEC(s),DMAT(v));
diff --git a/lib/Numeric/LinearAlgebra/Linear.hs b/lib/Numeric/LinearAlgebra/Linear.hs
index aed6a2b..2351ff1 100644
--- a/lib/Numeric/LinearAlgebra/Linear.hs
+++ b/lib/Numeric/LinearAlgebra/Linear.hs
@@ -132,6 +132,17 @@ instance Linear Vector (Complex Double) where
132 equal u v = dim u == dim v && vectorMax (mapVector magnitude (sub u v)) == 0.0 132 equal u v = dim u == dim v && vectorMax (mapVector magnitude (sub u v)) == 0.0
133 scalar x = fromList [x] 133 scalar x = fromList [x]
134 134
135instance Linear Vector (Complex Float) where
136 scale = vectorMapValQ Scale
137 scaleRecip = vectorMapValQ Recip
138 addConstant = vectorMapValQ AddConstant
139 add = vectorZipQ Add
140 sub = vectorZipQ Sub
141 mul = vectorZipQ Mul
142 divide = vectorZipQ Div
143 equal u v = dim u == dim v && vectorMax (mapVector magnitude (sub u v)) == 0.0
144 scalar x = fromList [x]
145
135instance (Linear Vector a, Container Matrix a) => (Linear Matrix a) where 146instance (Linear Vector a, Container Matrix a) => (Linear Matrix a) where
136 scale x = liftMatrix (scale x) 147 scale x = liftMatrix (scale x)
137 scaleRecip x = liftMatrix (scaleRecip x) 148 scaleRecip x = liftMatrix (scaleRecip x)