summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2010-09-11 18:45:27 +0000
committerAlberto Ruiz <aruiz@um.es>2010-09-11 18:45:27 +0000
commit996d2fdb53154993ac02b5350cd4941548e6a61e (patch)
tree0bb1cb4b8847e17d78ec87c383c3d4c610bf8030
parenta519a29770a6ef8d08dea3b3e7971ed1f4084126 (diff)
simple tests
-rw-r--r--lib/Numeric/GSL/gsl-aux.c16
-rw-r--r--lib/Numeric/LinearAlgebra/Algorithms.hs2
-rw-r--r--lib/Numeric/LinearAlgebra/LAPACK.hs2
-rw-r--r--lib/Numeric/LinearAlgebra/Tests.hs27
-rw-r--r--lib/Numeric/Matrix.hs3
-rw-r--r--lib/Numeric/Vector.hs3
6 files changed, 38 insertions, 15 deletions
diff --git a/lib/Numeric/GSL/gsl-aux.c b/lib/Numeric/GSL/gsl-aux.c
index 3e9e2cb..33d7dab 100644
--- a/lib/Numeric/GSL/gsl-aux.c
+++ b/lib/Numeric/GSL/gsl-aux.c
@@ -157,7 +157,7 @@ int prodF(KFVEC(x),FVEC(r)) {
157 DEBUGMSG("prodF"); 157 DEBUGMSG("prodF");
158 REQUIRES(rn==1,BAD_SIZE); 158 REQUIRES(rn==1,BAD_SIZE);
159 int i; 159 int i;
160 float res = 0; 160 float res = 1;
161 for (i = 0; i < xn; i++) res *= xp[i]; 161 for (i = 0; i < xn; i++) res *= xp[i];
162 rp[0] = res; 162 rp[0] = res;
163 OK 163 OK
@@ -167,7 +167,7 @@ int prodR(KRVEC(x),RVEC(r)) {
167 DEBUGMSG("prodR"); 167 DEBUGMSG("prodR");
168 REQUIRES(rn==1,BAD_SIZE); 168 REQUIRES(rn==1,BAD_SIZE);
169 int i; 169 int i;
170 double res = 0; 170 double res = 1;
171 for (i = 0; i < xn; i++) res *= xp[i]; 171 for (i = 0; i < xn; i++) res *= xp[i];
172 rp[0] = res; 172 rp[0] = res;
173 OK 173 OK
@@ -178,11 +178,13 @@ int prodQ(KQVEC(x),QVEC(r)) {
178 REQUIRES(rn==1,BAD_SIZE); 178 REQUIRES(rn==1,BAD_SIZE);
179 int i; 179 int i;
180 gsl_complex_float res; 180 gsl_complex_float res;
181 res.dat[0] = 0; 181 float temp;
182 res.dat[0] = 1;
182 res.dat[1] = 0; 183 res.dat[1] = 0;
183 for (i = 0; i < xn; i++) { 184 for (i = 0; i < xn; i++) {
184 res.dat[0] = res.dat[0] * xp[i].dat[0] - res.dat[1] * xp[i].dat[1]; 185 temp = res.dat[0] * xp[i].dat[0] - res.dat[1] * xp[i].dat[1];
185 res.dat[1] = res.dat[0] * xp[i].dat[1] + res.dat[1] * xp[i].dat[0]; 186 res.dat[1] = res.dat[0] * xp[i].dat[1] + res.dat[1] * xp[i].dat[0];
187 res.dat[0] = temp;
186 } 188 }
187 rp[0] = res; 189 rp[0] = res;
188 OK 190 OK
@@ -193,11 +195,13 @@ int prodC(KCVEC(x),CVEC(r)) {
193 REQUIRES(rn==1,BAD_SIZE); 195 REQUIRES(rn==1,BAD_SIZE);
194 int i; 196 int i;
195 gsl_complex res; 197 gsl_complex res;
196 res.dat[0] = 0; 198 double temp;
199 res.dat[0] = 1;
197 res.dat[1] = 0; 200 res.dat[1] = 0;
198 for (i = 0; i < xn; i++) { 201 for (i = 0; i < xn; i++) {
199 res.dat[0] = res.dat[0] * xp[i].dat[0] - res.dat[1] * xp[i].dat[1]; 202 temp = res.dat[0] * xp[i].dat[0] - res.dat[1] * xp[i].dat[1];
200 res.dat[1] = res.dat[0] * xp[i].dat[1] + res.dat[1] * xp[i].dat[0]; 203 res.dat[1] = res.dat[0] * xp[i].dat[1] + res.dat[1] * xp[i].dat[0];
204 res.dat[0] = temp;
201 } 205 }
202 rp[0] = res; 206 rp[0] = res;
203 OK 207 OK
diff --git a/lib/Numeric/LinearAlgebra/Algorithms.hs b/lib/Numeric/LinearAlgebra/Algorithms.hs
index 5bc9ca5..f2f5473 100644
--- a/lib/Numeric/LinearAlgebra/Algorithms.hs
+++ b/lib/Numeric/LinearAlgebra/Algorithms.hs
@@ -76,8 +76,6 @@ module Numeric.LinearAlgebra.Algorithms (
76 76
77import Data.Packed.Internal hiding ((//)) 77import Data.Packed.Internal hiding ((//))
78import Data.Packed.Matrix 78import Data.Packed.Matrix
79import Data.Complex
80
81import Numeric.LinearAlgebra.LAPACK as LAPACK 79import Numeric.LinearAlgebra.LAPACK as LAPACK
82import Data.List(foldl1') 80import Data.List(foldl1')
83import Data.Array 81import Data.Array
diff --git a/lib/Numeric/LinearAlgebra/LAPACK.hs b/lib/Numeric/LinearAlgebra/LAPACK.hs
index 288439f..cb48571 100644
--- a/lib/Numeric/LinearAlgebra/LAPACK.hs
+++ b/lib/Numeric/LinearAlgebra/LAPACK.hs
@@ -43,7 +43,7 @@ module Numeric.LinearAlgebra.LAPACK (
43 43
44import Data.Packed.Internal 44import Data.Packed.Internal
45import Data.Packed.Matrix 45import Data.Packed.Matrix
46import Data.Complex 46--import Data.Complex
47import Numeric.Conversion 47import Numeric.Conversion
48import Numeric.GSL.Vector(vectorMapValR, FunCodeSV(Scale)) 48import Numeric.GSL.Vector(vectorMapValR, FunCodeSV(Scale))
49import Foreign 49import Foreign
diff --git a/lib/Numeric/LinearAlgebra/Tests.hs b/lib/Numeric/LinearAlgebra/Tests.hs
index 426700b..2d5b0da 100644
--- a/lib/Numeric/LinearAlgebra/Tests.hs
+++ b/lib/Numeric/LinearAlgebra/Tests.hs
@@ -271,6 +271,31 @@ normsMTest = TestList [
271 271
272--------------------------------------------------------------------- 272---------------------------------------------------------------------
273 273
274sumprodTest = TestList [
275 utest "sumCD" $ sumElements z == 6
276 , utest "sumCF" $ sumElements (single z) == 6
277 , utest "sumD" $ sumElements v == 6
278 , utest "sumF" $ sumElements (single v) == 6
279
280 , utest "prodCD" $ prodProp z
281 , utest "prodCF" $ prodProp (single z)
282 , utest "prodD" $ prodProp v
283 , utest "prodF" $ prodProp (single v)
284 ] where v = fromList [1,2,3] :: Vector Double
285 z = fromList [1,2-i,3+i]
286 prodProp x = prodElements x == product (toList x)
287
288---------------------------------------------------------------------
289
290chainTest = utest "chain" $ foldl1' (<>) ms |~| chain ms where
291 ms = [ diag (fromList [1,2,3 :: Double])
292 , konst 3 (3,5)
293 , (5><10) [1 .. ]
294 , konst 5 (10,2)
295 ]
296
297---------------------------------------------------------------------
298
274conjuTest m = mapVector conjugate (flatten (trans m)) == flatten (ctrans m) 299conjuTest m = mapVector conjugate (flatten (trans m)) == flatten (ctrans m)
275 300
276--------------------------------------------------------------------- 301---------------------------------------------------------------------
@@ -439,6 +464,8 @@ runTests n = do
439 , utest "offset" offsetTest 464 , utest "offset" offsetTest
440 , normsVTest 465 , normsVTest
441 , normsMTest 466 , normsMTest
467 , sumprodTest
468 , chainTest
442 ] 469 ]
443 return () 470 return ()
444 471
diff --git a/lib/Numeric/Matrix.hs b/lib/Numeric/Matrix.hs
index ce36ef2..fe0ec13 100644
--- a/lib/Numeric/Matrix.hs
+++ b/lib/Numeric/Matrix.hs
@@ -36,10 +36,7 @@ module Numeric.Matrix (
36 36
37------------------------------------------------------------------- 37-------------------------------------------------------------------
38 38
39import Data.Packed.Vector
40import Data.Packed.Matrix 39import Data.Packed.Matrix
41
42import Numeric.Container
43import Numeric.Vector 40import Numeric.Vector
44import Numeric.Chain 41import Numeric.Chain
45import Numeric.LinearAlgebra.Algorithms 42import Numeric.LinearAlgebra.Algorithms
diff --git a/lib/Numeric/Vector.hs b/lib/Numeric/Vector.hs
index 1baa6f8..bd356b1 100644
--- a/lib/Numeric/Vector.hs
+++ b/lib/Numeric/Vector.hs
@@ -27,12 +27,9 @@ module Numeric.Vector (
27 (<.>) 27 (<.>)
28 ) where 28 ) where
29 29
30import Data.Complex
31
32import Data.Packed.Vector 30import Data.Packed.Vector
33import Data.Packed.Internal.Matrix 31import Data.Packed.Internal.Matrix
34import Numeric.GSL.Vector 32import Numeric.GSL.Vector
35
36import Numeric.Container 33import Numeric.Container
37 34
38------------------------------------------------------------------- 35-------------------------------------------------------------------