From e1b4cc06a5f98e576524b37ad0d9132f0678d722 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Fri, 14 Nov 2008 11:01:14 +0000 Subject: constantD --- lib/Data/Packed/Internal/Matrix.hs | 13 +++++++++++++ 1 file changed, 13 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 9def473..09f081a 100644 --- a/lib/Data/Packed/Internal/Matrix.hs +++ b/lib/Data/Packed/Internal/Matrix.hs @@ -217,14 +217,17 @@ class (Storable a, Floating a) => Element a where -> (Int,Int) -- ^ (rt,ct) dimensions of submatrix -> Matrix a -> Matrix a transdata :: Int -> Vector a -> Int -> Vector a + constantD :: a -> Int -> Vector a instance Element Double where subMatrixD = subMatrixR transdata = transdata' + constantD = constant' instance Element (Complex Double) where subMatrixD = subMatrixC transdata = transdata' + constantD = constant' ------------------------------------------------------------------- @@ -256,6 +259,16 @@ transdata' c1 v c2 = ---------------------------------------------------------------------- +constant' v n = unsafePerformIO $ do + w <- createVector n + withForeignPtr (fptr w) $ \p -> do + let go (-1) = return () + go !k = pokeElemOff p k v >> go (k-1) + go (n-1) + return w + +---------------------------------------------------------------------- + -- | extraction of a submatrix from a real matrix subMatrixR :: (Int,Int) -> (Int,Int) -> Matrix Double -> Matrix Double subMatrixR (r0,c0) (rt,ct) x' = unsafePerformIO $ do -- cgit v1.2.3