summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Internal
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2008-11-05 14:01:11 +0000
committerAlberto Ruiz <aruiz@um.es>2008-11-05 14:01:11 +0000
commit2044be5a83d77536daed0f0f34d2baa6aa548dd1 (patch)
treee8ef80f329fe062ebc028e2fe4136cdce2ce8cb7 /lib/Data/Packed/Internal
parent3161c13c508fb578bbc66156a609dbe4b991948d (diff)
improved constant
Diffstat (limited to 'lib/Data/Packed/Internal')
-rw-r--r--lib/Data/Packed/Internal/Matrix.hs32
-rw-r--r--lib/Data/Packed/Internal/Vector.hs1
-rw-r--r--lib/Data/Packed/Internal/auxi.c28
-rw-r--r--lib/Data/Packed/Internal/auxi.h3
4 files changed, 1 insertions, 63 deletions
diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs
index 51fb6f8..477b453 100644
--- a/lib/Data/Packed/Internal/Matrix.hs
+++ b/lib/Data/Packed/Internal/Matrix.hs
@@ -208,19 +208,16 @@ compat m1 m2 = rows m1 == rows m2 && cols m1 == cols m2
208 208
209-- | Optimized matrix computations are provided for elements in the Element class. 209-- | Optimized matrix computations are provided for elements in the Element class.
210class (Storable a, Floating a) => Element a where 210class (Storable a, Floating a) => Element a where
211 constantD :: a -> Int -> Vector a
212 transdata :: Int -> Vector a -> Int -> Vector a 211 transdata :: Int -> Vector a -> Int -> Vector a
213 subMatrixD :: (Int,Int) -- ^ (r0,c0) starting position 212 subMatrixD :: (Int,Int) -- ^ (r0,c0) starting position
214 -> (Int,Int) -- ^ (rt,ct) dimensions of submatrix 213 -> (Int,Int) -- ^ (rt,ct) dimensions of submatrix
215 -> Matrix a -> Matrix a 214 -> Matrix a -> Matrix a
216 215
217instance Element Double where 216instance Element Double where
218 constantD = constantR
219 transdata = transdataR 217 transdata = transdataR
220 subMatrixD = subMatrixR 218 subMatrixD = subMatrixR
221 219
222instance Element (Complex Double) where 220instance Element (Complex Double) where
223 constantD = constantC
224 transdata = transdataC 221 transdata = transdataC
225 subMatrixD = subMatrixC 222 subMatrixD = subMatrixC
226 223
@@ -284,31 +281,6 @@ subMatrix :: Element a
284 -> Matrix a -- ^ result 281 -> Matrix a -- ^ result
285subMatrix = subMatrixD 282subMatrix = subMatrixD
286 283
287------------------------------------------------------------------------
288
289constantAux fun x n = unsafePerformIO $ do
290 v <- createVector n
291 px <- newArray [x]
292 app1 (fun px) vec v "constantAux"
293 free px
294 return v
295
296constantR :: Double -> Int -> Vector Double
297constantR = constantAux cconstantR
298foreign import ccall "auxi.h constantR" cconstantR :: Ptr Double -> TV
299
300constantC :: Complex Double -> Int -> Vector (Complex Double)
301constantC = constantAux cconstantC
302foreign import ccall "auxi.h constantC" cconstantC :: Ptr (Complex Double) -> TCV
303
304{- | creates a vector with a given number of equal components:
305
306@> constant 2 7
3077 |> [2.0,2.0,2.0,2.0,2.0,2.0,2.0]@
308-}
309constant :: Element a => a -> Int -> Vector a
310constant = constantD
311
312-------------------------------------------------------------------------- 284--------------------------------------------------------------------------
313 285
314-- | obtains the complex conjugate of a complex vector 286-- | obtains the complex conjugate of a complex vector
@@ -329,10 +301,6 @@ fromComplex :: Vector (Complex Double) -> (Vector Double, Vector Double)
329fromComplex z = (r,i) where 301fromComplex z = (r,i) where
330 [r,i] = toColumns $ reshape 2 $ asReal z 302 [r,i] = toColumns $ reshape 2 $ asReal z
331 303
332-- | converts a real vector into a complex representation (with zero imaginary parts)
333comp :: Vector Double -> Vector (Complex Double)
334comp v = toComplex (v,constant 0 (dim v))
335
336-- | loads a matrix efficiently from formatted ASCII text file (the number of rows and columns must be known in advance). 304-- | loads a matrix efficiently from formatted ASCII text file (the number of rows and columns must be known in advance).
337fromFile :: FilePath -> (Int,Int) -> IO (Matrix Double) 305fromFile :: FilePath -> (Int,Int) -> IO (Matrix Double)
338fromFile filename (r,c) = do 306fromFile filename (r,c) = do
diff --git a/lib/Data/Packed/Internal/Vector.hs b/lib/Data/Packed/Internal/Vector.hs
index 2df33e0..f590919 100644
--- a/lib/Data/Packed/Internal/Vector.hs
+++ b/lib/Data/Packed/Internal/Vector.hs
@@ -99,6 +99,7 @@ n |> l = if length l == n then fromList l else error "|> with wrong size"
99-- | access to Vector elements without range checking 99-- | access to Vector elements without range checking
100at' :: Storable a => Vector a -> Int -> a 100at' :: Storable a => Vector a -> Int -> a
101at' v n = safeRead v $ flip peekElemOff n 101at' v n = safeRead v $ flip peekElemOff n
102{-# INLINE at' #-}
102 103
103-- 104--
104-- turn off bounds checking with -funsafe at configure time. 105-- turn off bounds checking with -funsafe at configure time.
diff --git a/lib/Data/Packed/Internal/auxi.c b/lib/Data/Packed/Internal/auxi.c
index c449b9a..48b05e8 100644
--- a/lib/Data/Packed/Internal/auxi.c
+++ b/lib/Data/Packed/Internal/auxi.c
@@ -1,12 +1,5 @@
1#include "auxi.h" 1#include "auxi.h"
2#include <gsl/gsl_blas.h>
3#include <gsl/gsl_linalg.h>
4#include <gsl/gsl_matrix.h> 2#include <gsl/gsl_matrix.h>
5#include <gsl/gsl_math.h>
6#include <gsl/gsl_errno.h>
7#include <gsl/gsl_complex.h>
8#include <gsl/gsl_complex_math.h>
9#include <gsl/gsl_cblas.h>
10#include <string.h> 3#include <string.h>
11#include <stdio.h> 4#include <stdio.h>
12 5
@@ -92,27 +85,6 @@ int submatrixR(int r1, int r2, int c1, int c2, KRMAT(x),RMAT(r)) {
92} 85}
93 86
94 87
95int constantR(double * pval, RVEC(r)) {
96 DEBUGMSG("constantR")
97 int k;
98 double val = *pval;
99 for(k=0;k<rn;k++) {
100 rp[k]=val;
101 }
102 OK
103}
104
105int constantC(gsl_complex* pval, CVEC(r)) {
106 DEBUGMSG("constantC")
107 int k;
108 gsl_complex val = *pval;
109 for(k=0;k<rn;k++) {
110 rp[k]=val;
111 }
112 OK
113}
114
115
116int conjugate(KCVEC(x),CVEC(t)) { 88int conjugate(KCVEC(x),CVEC(t)) {
117 REQUIRES(xn==tn,BAD_SIZE); 89 REQUIRES(xn==tn,BAD_SIZE);
118 DEBUGMSG("conjugate"); 90 DEBUGMSG("conjugate");
diff --git a/lib/Data/Packed/Internal/auxi.h b/lib/Data/Packed/Internal/auxi.h
index b57fdaf..4698696 100644
--- a/lib/Data/Packed/Internal/auxi.h
+++ b/lib/Data/Packed/Internal/auxi.h
@@ -13,9 +13,6 @@
13int transR(KRMAT(x),RMAT(t)); 13int transR(KRMAT(x),RMAT(t));
14int transC(KCMAT(x),CMAT(t)); 14int transC(KCMAT(x),CMAT(t));
15 15
16int constantR(double *val , RVEC(r));
17int constantC(gsl_complex *val, CVEC(r));
18
19int submatrixR(int r1, int r2, int c1, int c2, KRMAT(x),RMAT(r)); 16int submatrixR(int r1, int r2, int c1, int c2, KRMAT(x),RMAT(r));
20 17
21const char * gsl_strerror (const int gsl_errno); 18const char * gsl_strerror (const int gsl_errno);