From 8c890d59088015865a4e8c6b0ebec13e58d8b295 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Tue, 21 May 2013 14:02:17 +0200 Subject: NFData (Matrix t) --- lib/Data/Packed/Internal/Matrix.hs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lib/Data/Packed/Internal/Matrix.hs') diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs index b8ed18d..367c189 100644 --- a/lib/Data/Packed/Internal/Matrix.hs +++ b/lib/Data/Packed/Internal/Matrix.hs @@ -47,6 +47,7 @@ import Data.Complex(Complex) import Foreign.C.Types import Foreign.C.String(newCString) import System.IO.Unsafe(unsafePerformIO) +import Control.DeepSeq ----------------------------------------------------------------- @@ -459,3 +460,13 @@ size m = (rows m, cols m) shSize m = "(" ++ show (rows m) ++"><"++ show (cols m)++")" +---------------------------------------------------------------------- + +instance (Storable t, NFData t) => NFData (Matrix t) + where + rnf m | d > 0 = rnf (v @> 0) + | otherwise = () + where + d = dim v + v = xdat m + -- cgit v1.2.3 From d302e91710db7cccb32853cfd861b9f869eb4e31 Mon Sep 17 00:00:00 2001 From: Mike Ledger Date: Mon, 24 Jun 2013 21:19:48 +1000 Subject: add CDouble/CFloat instances for Element --- lib/Data/Packed/Internal/Matrix.hs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'lib/Data/Packed/Internal/Matrix.hs') diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs index 367c189..ce2720e 100644 --- a/lib/Data/Packed/Internal/Matrix.hs +++ b/lib/Data/Packed/Internal/Matrix.hs @@ -262,18 +262,34 @@ instance Element Float where transdata = transdataAux ctransF constantD = constantAux cconstantF +instance Element CFloat where + transdata = transdataAux ctransCF + constantD = constantAux cconstantCF + instance Element Double where transdata = transdataAux ctransR constantD = constantAux cconstantR +instance Element CDouble where + transdata = transdataAux ctransCR + constantD = constantAux cconstantCR + instance Element (Complex Float) where transdata = transdataAux ctransQ constantD = constantAux cconstantQ +instance Element (Complex CFloat) where + transdata = transdataAux ctransCQ + constantD = constantAux cconstantCQ + instance Element (Complex Double) where transdata = transdataAux ctransC constantD = constantAux cconstantC +instance Element (Complex CDouble) where + transdata = transdataAux ctransCC + constantD = constantAux cconstantCC + ------------------------------------------------------------------- transdata' :: Storable a => Int -> Vector a -> Int -> Vector a @@ -333,9 +349,17 @@ transdataP c1 d c2 = noneed = r1 == 1 || c1 == 1 foreign import ccall unsafe "transF" ctransF :: TFMFM +foreign import ccall unsafe "transF" ctransCF :: CInt -> CInt -> Ptr CFloat -> CInt -> CInt -> Ptr CFloat -> IO CInt + foreign import ccall unsafe "transR" ctransR :: TMM +foreign import ccall unsafe "transR" ctransCR :: CInt -> CInt -> Ptr CDouble -> CInt -> CInt -> Ptr CDouble -> IO CInt + foreign import ccall unsafe "transQ" ctransQ :: TQMQM +foreign import ccall unsafe "transQ" ctransCQ :: CInt -> CInt -> Ptr (Complex CFloat) -> CInt -> CInt -> Ptr (Complex CFloat) -> IO CInt + foreign import ccall unsafe "transC" ctransC :: TCMCM +foreign import ccall unsafe "transC" ctransCC :: CInt -> CInt -> Ptr (Complex CDouble) -> CInt -> CInt -> Ptr (Complex CDouble) -> IO CInt + foreign import ccall unsafe "transP" ctransP :: CInt -> CInt -> Ptr () -> CInt -> CInt -> CInt -> Ptr () -> CInt -> IO CInt ---------------------------------------------------------------------- @@ -360,18 +384,22 @@ constantAux fun x n = unsafePerformIO $ do constantF :: Float -> Int -> Vector Float constantF = constantAux cconstantF foreign import ccall unsafe "constantF" cconstantF :: Ptr Float -> TF +foreign import ccall unsafe "constantF" cconstantCF :: Ptr CFloat -> CInt -> Ptr CFloat -> IO CInt constantR :: Double -> Int -> Vector Double constantR = constantAux cconstantR foreign import ccall unsafe "constantR" cconstantR :: Ptr Double -> TV +foreign import ccall unsafe "constantR" cconstantCR :: Ptr CDouble -> CInt -> Ptr CDouble -> IO CInt constantQ :: Complex Float -> Int -> Vector (Complex Float) constantQ = constantAux cconstantQ foreign import ccall unsafe "constantQ" cconstantQ :: Ptr (Complex Float) -> TQV +foreign import ccall unsafe "constantQ" cconstantCQ :: Ptr (Complex CFloat) -> CInt -> Ptr (Complex CFloat) -> IO CInt constantC :: Complex Double -> Int -> Vector (Complex Double) constantC = constantAux cconstantC foreign import ccall unsafe "constantC" cconstantC :: Ptr (Complex Double) -> TCV +foreign import ccall unsafe "constantC" cconstantCC :: Ptr (Complex CDouble) -> CInt -> Ptr (Complex CDouble) -> IO CInt constantP :: Storable a => a -> Int -> Vector a constantP a n = unsafePerformIO $ do -- cgit v1.2.3 From 3c3760017f01a54f95f609f05f4e0e25c6fdf88f Mon Sep 17 00:00:00 2001 From: Mike Ledger Date: Mon, 24 Jun 2013 21:32:28 +1000 Subject: improve haddocks for flatten --- lib/Data/Packed/Internal/Matrix.hs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'lib/Data/Packed/Internal/Matrix.hs') diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs index ce2720e..8158679 100644 --- a/lib/Data/Packed/Internal/Matrix.hs +++ b/lib/Data/Packed/Internal/Matrix.hs @@ -132,12 +132,10 @@ mat a f = let m g = do g (fi (rows a)) (fi (cols a)) p f m - -{- | Creates a vector by concatenation of rows - -@\> flatten ('ident' 3) -9 |> [1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0]@ --} +-- | Creates a vector by concatenation of rows. If the matrix is ColumnMajor, this operation requires a transpose. +-- +-- @\> flatten ('ident' 3) +-- 9 |> [1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0]@ flatten :: Element t => Matrix t -> Vector t flatten = xdat . cmat -- cgit v1.2.3 From 027fa6391bc7b21a8aecbdc577ad485aee274333 Mon Sep 17 00:00:00 2001 From: Mike Ledger Date: Mon, 24 Jun 2013 23:17:39 +1000 Subject: Revert "add CDouble/CFloat instances for Element" This reverts commit d302e91710db7cccb32853cfd861b9f869eb4e31. --- lib/Data/Packed/Internal/Matrix.hs | 28 ---------------------------- 1 file changed, 28 deletions(-) (limited to 'lib/Data/Packed/Internal/Matrix.hs') diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs index 8158679..255009c 100644 --- a/lib/Data/Packed/Internal/Matrix.hs +++ b/lib/Data/Packed/Internal/Matrix.hs @@ -260,34 +260,18 @@ instance Element Float where transdata = transdataAux ctransF constantD = constantAux cconstantF -instance Element CFloat where - transdata = transdataAux ctransCF - constantD = constantAux cconstantCF - instance Element Double where transdata = transdataAux ctransR constantD = constantAux cconstantR -instance Element CDouble where - transdata = transdataAux ctransCR - constantD = constantAux cconstantCR - instance Element (Complex Float) where transdata = transdataAux ctransQ constantD = constantAux cconstantQ -instance Element (Complex CFloat) where - transdata = transdataAux ctransCQ - constantD = constantAux cconstantCQ - instance Element (Complex Double) where transdata = transdataAux ctransC constantD = constantAux cconstantC -instance Element (Complex CDouble) where - transdata = transdataAux ctransCC - constantD = constantAux cconstantCC - ------------------------------------------------------------------- transdata' :: Storable a => Int -> Vector a -> Int -> Vector a @@ -347,17 +331,9 @@ transdataP c1 d c2 = noneed = r1 == 1 || c1 == 1 foreign import ccall unsafe "transF" ctransF :: TFMFM -foreign import ccall unsafe "transF" ctransCF :: CInt -> CInt -> Ptr CFloat -> CInt -> CInt -> Ptr CFloat -> IO CInt - foreign import ccall unsafe "transR" ctransR :: TMM -foreign import ccall unsafe "transR" ctransCR :: CInt -> CInt -> Ptr CDouble -> CInt -> CInt -> Ptr CDouble -> IO CInt - foreign import ccall unsafe "transQ" ctransQ :: TQMQM -foreign import ccall unsafe "transQ" ctransCQ :: CInt -> CInt -> Ptr (Complex CFloat) -> CInt -> CInt -> Ptr (Complex CFloat) -> IO CInt - foreign import ccall unsafe "transC" ctransC :: TCMCM -foreign import ccall unsafe "transC" ctransCC :: CInt -> CInt -> Ptr (Complex CDouble) -> CInt -> CInt -> Ptr (Complex CDouble) -> IO CInt - foreign import ccall unsafe "transP" ctransP :: CInt -> CInt -> Ptr () -> CInt -> CInt -> CInt -> Ptr () -> CInt -> IO CInt ---------------------------------------------------------------------- @@ -382,22 +358,18 @@ constantAux fun x n = unsafePerformIO $ do constantF :: Float -> Int -> Vector Float constantF = constantAux cconstantF foreign import ccall unsafe "constantF" cconstantF :: Ptr Float -> TF -foreign import ccall unsafe "constantF" cconstantCF :: Ptr CFloat -> CInt -> Ptr CFloat -> IO CInt constantR :: Double -> Int -> Vector Double constantR = constantAux cconstantR foreign import ccall unsafe "constantR" cconstantR :: Ptr Double -> TV -foreign import ccall unsafe "constantR" cconstantCR :: Ptr CDouble -> CInt -> Ptr CDouble -> IO CInt constantQ :: Complex Float -> Int -> Vector (Complex Float) constantQ = constantAux cconstantQ foreign import ccall unsafe "constantQ" cconstantQ :: Ptr (Complex Float) -> TQV -foreign import ccall unsafe "constantQ" cconstantCQ :: Ptr (Complex CFloat) -> CInt -> Ptr (Complex CFloat) -> IO CInt constantC :: Complex Double -> Int -> Vector (Complex Double) constantC = constantAux cconstantC foreign import ccall unsafe "constantC" cconstantC :: Ptr (Complex Double) -> TCV -foreign import ccall unsafe "constantC" cconstantCC :: Ptr (Complex CDouble) -> CInt -> Ptr (Complex CDouble) -> IO CInt constantP :: Storable a => a -> Int -> Vector a constantP a n = unsafePerformIO $ do -- cgit v1.2.3