diff options
author | Vivian McPhail <haskell.vivian.mcphail@gmail.com> | 2010-06-29 09:03:19 +0000 |
---|---|---|
committer | Vivian McPhail <haskell.vivian.mcphail@gmail.com> | 2010-06-29 09:03:19 +0000 |
commit | 4957cff8af91cbb23c12382e25f5373fe96acb95 (patch) | |
tree | 2f2968d5ca88f7d76e208982b8938c4dfc46ce8a /lib/Numeric/LinearAlgebra | |
parent | d18a86d37d55a39d4ec9b16397dd59f35aa13688 (diff) |
add-vector-float
Diffstat (limited to 'lib/Numeric/LinearAlgebra')
-rw-r--r-- | lib/Numeric/LinearAlgebra/Instances.hs | 29 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.c | 22 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.h | 6 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra/Linear.hs | 11 |
4 files changed, 68 insertions, 0 deletions
diff --git a/lib/Numeric/LinearAlgebra/Instances.hs b/lib/Numeric/LinearAlgebra/Instances.hs index 1992db0..bba89c8 100644 --- a/lib/Numeric/LinearAlgebra/Instances.hs +++ b/lib/Numeric/LinearAlgebra/Instances.hs | |||
@@ -94,6 +94,14 @@ instance Linear Vector a => Eq (Vector a) where | |||
94 | 94 | ||
95 | #endif | 95 | #endif |
96 | 96 | ||
97 | instance Num (Vector Float) where | ||
98 | (+) = adaptScalar addConstant add (flip addConstant) | ||
99 | negate = scale (-1) | ||
100 | (*) = adaptScalar scale mul (flip scale) | ||
101 | signum = vectorMapF Sign | ||
102 | abs = vectorMapF Abs | ||
103 | fromInteger = fromList . return . fromInteger | ||
104 | |||
97 | instance Num (Vector Double) where | 105 | instance Num (Vector Double) where |
98 | (+) = adaptScalar addConstant add (flip addConstant) | 106 | (+) = adaptScalar addConstant add (flip addConstant) |
99 | negate = scale (-1) | 107 | negate = scale (-1) |
@@ -138,6 +146,27 @@ instance (Linear Vector a, Fractional (Vector a), Num (Matrix a)) => Fractional | |||
138 | 146 | ||
139 | --------------------------------------------------------- | 147 | --------------------------------------------------------- |
140 | 148 | ||
149 | instance Floating (Vector Float) where | ||
150 | sin = vectorMapF Sin | ||
151 | cos = vectorMapF Cos | ||
152 | tan = vectorMapF Tan | ||
153 | asin = vectorMapF ASin | ||
154 | acos = vectorMapF ACos | ||
155 | atan = vectorMapF ATan | ||
156 | sinh = vectorMapF Sinh | ||
157 | cosh = vectorMapF Cosh | ||
158 | tanh = vectorMapF Tanh | ||
159 | asinh = vectorMapF ASinh | ||
160 | acosh = vectorMapF ACosh | ||
161 | atanh = vectorMapF ATanh | ||
162 | exp = vectorMapF Exp | ||
163 | log = vectorMapF Log | ||
164 | sqrt = vectorMapF Sqrt | ||
165 | (**) = adaptScalar (vectorMapValF PowSV) (vectorZipF Pow) (flip (vectorMapValF PowVS)) | ||
166 | pi = fromList [pi] | ||
167 | |||
168 | ------------------------------------------------------------- | ||
169 | |||
141 | instance Floating (Vector Double) where | 170 | instance Floating (Vector Double) where |
142 | sin = vectorMapR Sin | 171 | sin = vectorMapR Sin |
143 | cos = vectorMapR Cos | 172 | cos = vectorMapR Cos |
diff --git a/lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.c b/lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.c index fd840e3..b9c2572 100644 --- a/lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.c +++ b/lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.c | |||
@@ -1039,6 +1039,18 @@ int multiplyC(int ta, int tb, KCMAT(a),KCMAT(b),CMAT(r)) { | |||
1039 | 1039 | ||
1040 | //////////////////// transpose ///////////////////////// | 1040 | //////////////////// transpose ///////////////////////// |
1041 | 1041 | ||
1042 | int transF(KFMAT(x),FMAT(t)) { | ||
1043 | REQUIRES(xr==tc && xc==tr,BAD_SIZE); | ||
1044 | DEBUGMSG("transF"); | ||
1045 | int i,j; | ||
1046 | for (i=0; i<tr; i++) { | ||
1047 | for (j=0; j<tc; j++) { | ||
1048 | tp[i*tc+j] = xp[j*xc+i]; | ||
1049 | } | ||
1050 | } | ||
1051 | OK | ||
1052 | } | ||
1053 | |||
1042 | int transR(KDMAT(x),DMAT(t)) { | 1054 | int transR(KDMAT(x),DMAT(t)) { |
1043 | REQUIRES(xr==tc && xc==tr,BAD_SIZE); | 1055 | REQUIRES(xr==tc && xc==tr,BAD_SIZE); |
1044 | DEBUGMSG("transR"); | 1056 | DEBUGMSG("transR"); |
@@ -1065,6 +1077,16 @@ int transC(KCMAT(x),CMAT(t)) { | |||
1065 | 1077 | ||
1066 | //////////////////// constant ///////////////////////// | 1078 | //////////////////// constant ///////////////////////// |
1067 | 1079 | ||
1080 | int constantF(float * pval, FVEC(r)) { | ||
1081 | DEBUGMSG("constantF") | ||
1082 | int k; | ||
1083 | double val = *pval; | ||
1084 | for(k=0;k<rn;k++) { | ||
1085 | rp[k]=val; | ||
1086 | } | ||
1087 | OK | ||
1088 | } | ||
1089 | |||
1068 | int constantR(double * pval, DVEC(r)) { | 1090 | int constantR(double * pval, DVEC(r)) { |
1069 | DEBUGMSG("constantR") | 1091 | DEBUGMSG("constantR") |
1070 | int k; | 1092 | int k; |
diff --git a/lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.h b/lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.h index adf096e..415a6ab 100644 --- a/lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.h +++ b/lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.h | |||
@@ -40,13 +40,17 @@ typedef short ftnlen; | |||
40 | 40 | ||
41 | /********************************************************/ | 41 | /********************************************************/ |
42 | 42 | ||
43 | #define FVEC(A) int A##n, float*A##p | ||
43 | #define DVEC(A) int A##n, double*A##p | 44 | #define DVEC(A) int A##n, double*A##p |
44 | #define CVEC(A) int A##n, double*A##p | 45 | #define CVEC(A) int A##n, double*A##p |
46 | #define FMAT(A) int A##r, int A##c, float* A##p | ||
45 | #define DMAT(A) int A##r, int A##c, double* A##p | 47 | #define DMAT(A) int A##r, int A##c, double* A##p |
46 | #define CMAT(A) int A##r, int A##c, double* A##p | 48 | #define CMAT(A) int A##r, int A##c, double* A##p |
47 | 49 | ||
50 | #define KFVEC(A) int A##n, const float*A##p | ||
48 | #define KDVEC(A) int A##n, const double*A##p | 51 | #define KDVEC(A) int A##n, const double*A##p |
49 | #define KCVEC(A) int A##n, const double*A##p | 52 | #define KCVEC(A) int A##n, const double*A##p |
53 | #define KFMAT(A) int A##r, int A##c, const float* A##p | ||
50 | #define KDMAT(A) int A##r, int A##c, const double* A##p | 54 | #define KDMAT(A) int A##r, int A##c, const double* A##p |
51 | #define KCMAT(A) int A##r, int A##c, const double* A##p | 55 | #define KCMAT(A) int A##r, int A##c, const double* A##p |
52 | 56 | ||
@@ -55,9 +59,11 @@ typedef short ftnlen; | |||
55 | int multiplyR(int ta, int tb, KDMAT(a),KDMAT(b),DMAT(r)); | 59 | int multiplyR(int ta, int tb, KDMAT(a),KDMAT(b),DMAT(r)); |
56 | int multiplyC(int ta, int tb, KCMAT(a),KCMAT(b),CMAT(r)); | 60 | int multiplyC(int ta, int tb, KCMAT(a),KCMAT(b),CMAT(r)); |
57 | 61 | ||
62 | int transF(KFMAT(x),FMAT(t)); | ||
58 | int transR(KDMAT(x),DMAT(t)); | 63 | int transR(KDMAT(x),DMAT(t)); |
59 | int transC(KCMAT(x),CMAT(t)); | 64 | int transC(KCMAT(x),CMAT(t)); |
60 | 65 | ||
66 | int constantF(float * pval, FVEC(r)); | ||
61 | int constantR(double * pval, DVEC(r)); | 67 | int constantR(double * pval, DVEC(r)); |
62 | int constantC(doublecomplex* pval, CVEC(r)); | 68 | int constantC(doublecomplex* pval, CVEC(r)); |
63 | 69 | ||
diff --git a/lib/Numeric/LinearAlgebra/Linear.hs b/lib/Numeric/LinearAlgebra/Linear.hs index c802712..481d72a 100644 --- a/lib/Numeric/LinearAlgebra/Linear.hs +++ b/lib/Numeric/LinearAlgebra/Linear.hs | |||
@@ -42,6 +42,17 @@ class (Container c e) => Linear c e where | |||
42 | equal :: c e -> c e -> Bool | 42 | equal :: c e -> c e -> Bool |
43 | 43 | ||
44 | 44 | ||
45 | instance Linear Vector Float where | ||
46 | scale = vectorMapValF Scale | ||
47 | scaleRecip = vectorMapValF Recip | ||
48 | addConstant = vectorMapValF AddConstant | ||
49 | add = vectorZipF Add | ||
50 | sub = vectorZipF Sub | ||
51 | mul = vectorZipF Mul | ||
52 | divide = vectorZipF Div | ||
53 | equal u v = dim u == dim v && vectorFMax (vectorMapF Abs (sub u v)) == 0.0 | ||
54 | scalar x = fromList [x] | ||
55 | |||
45 | instance Linear Vector Double where | 56 | instance Linear Vector Double where |
46 | scale = vectorMapValR Scale | 57 | scale = vectorMapValR Scale |
47 | scaleRecip = vectorMapValR Recip | 58 | scaleRecip = vectorMapValR Recip |