summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Internal/Matrix.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Data/Packed/Internal/Matrix.hs')
-rw-r--r--lib/Data/Packed/Internal/Matrix.hs19
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
79fmat m@MF{} = m 79fmat m@MF{} = m
80fmat MC {rows = r, cols = c, cdat = d } = MF {rows = r, cols = c, fdat = transdata c d r} 80fmat 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)) 82mat = withMatrix
83--matf m f = f (rows m) (cols m) (ptr (fdat m))
84 83
85withMatrix MC {rows = r, cols = c, cdat = d } f = 84withMatrix 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
308subMatrixR (r0,c0) (rt,ct) x' = unsafePerformIO $ do 307subMatrixR (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
314foreign import ccall "auxi.h submatrixR" c_submatrixR :: Int -> Int -> Int -> Int -> TMM 312foreign import ccall "auxi.h submatrixR" c_submatrixR :: Int -> Int -> Int -> Int -> TMM
315 313
@@ -333,8 +331,7 @@ subMatrix = subMatrixD
333 331
334diagAux fun msg (v@V {dim = n}) = unsafePerformIO $ do 332diagAux 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
356constantAux fun x n = unsafePerformIO $ do 353constantAux 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
364constantR :: Double -> Int -> Vector Double 360constantR :: Double -> Int -> Vector Double
365constantR = constantAux cconstantR 361constantR = constantAux cconstantR
366foreign import ccall safe "auxi.h constantR" 362foreign import ccall "auxi.h constantR"
367 cconstantR :: Ptr Double -> TV -- Double :> IO Int 363 cconstantR :: Ptr Double -> TV -- Double :> IO Int
368 364
369constantC :: Complex Double -> Int -> Vector (Complex Double) 365constantC :: Complex Double -> Int -> Vector (Complex Double)
370constantC = constantAux cconstantC 366constantC = constantAux cconstantC
371foreign import ccall safe "auxi.h constantC" 367foreign 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)
403fromFile filename (r,c) = do 399fromFile 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
410foreign import ccall "auxi.h matrix_fscanf" c_gslReadMatrix:: Ptr CChar -> TM 405foreign import ccall "auxi.h matrix_fscanf" c_gslReadMatrix:: Ptr CChar -> TM