diff options
author | Alberto Ruiz <aruiz@um.es> | 2007-11-22 17:03:41 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2007-11-22 17:03:41 +0000 |
commit | 01a14ad32e0fd8586498ead61a426f20b724652b (patch) | |
tree | b894c4d09700c2cf1f6abf2c89e6df81eebddb71 /lib/Data/Packed/Internal/Matrix.hs | |
parent | 2f45fdd97f80c0ffd0e10cce68d1cd24a43696c0 (diff) |
app1, app2, ...
Diffstat (limited to 'lib/Data/Packed/Internal/Matrix.hs')
-rw-r--r-- | lib/Data/Packed/Internal/Matrix.hs | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs index 90a96b5..0519603 100644 --- a/lib/Data/Packed/Internal/Matrix.hs +++ b/lib/Data/Packed/Internal/Matrix.hs | |||
@@ -79,8 +79,7 @@ cmat MF {rows = r, cols = c, fdat = d } = MC {rows = r, cols = c, cdat = transda | |||
79 | fmat m@MF{} = m | 79 | fmat m@MF{} = m |
80 | fmat MC {rows = r, cols = c, cdat = d } = MF {rows = r, cols = c, fdat = transdata c d r} | 80 | fmat MC {rows = r, cols = c, cdat = d } = MF {rows = r, cols = c, fdat = transdata c d r} |
81 | 81 | ||
82 | --matc m f = f (rows m) (cols m) (ptr (cdat m)) | 82 | mat = withMatrix |
83 | --matf m f = f (rows m) (cols m) (ptr (fdat m)) | ||
84 | 83 | ||
85 | withMatrix MC {rows = r, cols = c, cdat = d } f = | 84 | withMatrix MC {rows = r, cols = c, cdat = d } f = |
86 | withForeignPtr (fptr d) $ \p -> do | 85 | withForeignPtr (fptr d) $ \p -> do |
@@ -308,8 +307,7 @@ subMatrixR :: (Int,Int) -> (Int,Int) -> Matrix Double -> Matrix Double | |||
308 | subMatrixR (r0,c0) (rt,ct) x' = unsafePerformIO $ do | 307 | subMatrixR (r0,c0) (rt,ct) x' = unsafePerformIO $ do |
309 | r <- createMatrix RowMajor rt ct | 308 | r <- createMatrix RowMajor rt ct |
310 | let x = cmat x' | 309 | let x = cmat x' |
311 | ww2 withMatrix x withMatrix r $ \x r -> | 310 | app2 (c_submatrixR r0 (r0+rt-1) c0 (c0+ct-1)) mat x mat r "subMatrixR" |
312 | c_submatrixR r0 (r0+rt-1) c0 (c0+ct-1) // x // r // check "subMatrixR" | ||
313 | return r | 311 | return r |
314 | foreign import ccall "auxi.h submatrixR" c_submatrixR :: Int -> Int -> Int -> Int -> TMM | 312 | foreign import ccall "auxi.h submatrixR" c_submatrixR :: Int -> Int -> Int -> Int -> TMM |
315 | 313 | ||
@@ -333,8 +331,7 @@ subMatrix = subMatrixD | |||
333 | 331 | ||
334 | diagAux fun msg (v@V {dim = n}) = unsafePerformIO $ do | 332 | diagAux fun msg (v@V {dim = n}) = unsafePerformIO $ do |
335 | m <- createMatrix RowMajor n n | 333 | m <- createMatrix RowMajor n n |
336 | ww2 withVector v withMatrix m $ \v m -> | 334 | app2 fun vec v mat m msg |
337 | fun // v // m // check msg | ||
338 | return m | 335 | return m |
339 | 336 | ||
340 | -- | diagonal matrix from a real vector | 337 | -- | diagonal matrix from a real vector |
@@ -356,19 +353,18 @@ diag = diagD | |||
356 | constantAux fun x n = unsafePerformIO $ do | 353 | constantAux fun x n = unsafePerformIO $ do |
357 | v <- createVector n | 354 | v <- createVector n |
358 | px <- newArray [x] | 355 | px <- newArray [x] |
359 | withVector v $ \v -> | 356 | app1 (fun px) vec v "constantAux" |
360 | fun px // v // check "constantAux" | ||
361 | free px | 357 | free px |
362 | return v | 358 | return v |
363 | 359 | ||
364 | constantR :: Double -> Int -> Vector Double | 360 | constantR :: Double -> Int -> Vector Double |
365 | constantR = constantAux cconstantR | 361 | constantR = constantAux cconstantR |
366 | foreign import ccall safe "auxi.h constantR" | 362 | foreign import ccall "auxi.h constantR" |
367 | cconstantR :: Ptr Double -> TV -- Double :> IO Int | 363 | cconstantR :: Ptr Double -> TV -- Double :> IO Int |
368 | 364 | ||
369 | constantC :: Complex Double -> Int -> Vector (Complex Double) | 365 | constantC :: Complex Double -> Int -> Vector (Complex Double) |
370 | constantC = constantAux cconstantC | 366 | constantC = constantAux cconstantC |
371 | foreign import ccall safe "auxi.h constantC" | 367 | foreign import ccall "auxi.h constantC" |
372 | cconstantC :: Ptr (Complex Double) -> TCV -- Complex Double :> IO Int | 368 | cconstantC :: Ptr (Complex Double) -> TCV -- Complex Double :> IO Int |
373 | 369 | ||
374 | {- | creates a vector with a given number of equal components: | 370 | {- | creates a vector with a given number of equal components: |
@@ -403,8 +399,7 @@ fromFile :: FilePath -> (Int,Int) -> IO (Matrix Double) | |||
403 | fromFile filename (r,c) = do | 399 | fromFile filename (r,c) = do |
404 | charname <- newCString filename | 400 | charname <- newCString filename |
405 | res <- createMatrix RowMajor r c | 401 | res <- createMatrix RowMajor r c |
406 | withMatrix res $ \res -> | 402 | app1 (c_gslReadMatrix charname) mat res "gslReadMatrix" |
407 | c_gslReadMatrix charname // res // check "gslReadMatrix" | ||
408 | --free charname -- TO DO: free the auxiliary CString | 403 | --free charname -- TO DO: free the auxiliary CString |
409 | return res | 404 | return res |
410 | foreign import ccall "auxi.h matrix_fscanf" c_gslReadMatrix:: Ptr CChar -> TM | 405 | foreign import ccall "auxi.h matrix_fscanf" c_gslReadMatrix:: Ptr CChar -> TM |