diff options
Diffstat (limited to 'lib/Data/Packed/Internal/Matrix.hs')
-rw-r--r-- | lib/Data/Packed/Internal/Matrix.hs | 13 |
1 files changed, 13 insertions, 0 deletions
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 | |||
217 | -> (Int,Int) -- ^ (rt,ct) dimensions of submatrix | 217 | -> (Int,Int) -- ^ (rt,ct) dimensions of submatrix |
218 | -> Matrix a -> Matrix a | 218 | -> Matrix a -> Matrix a |
219 | transdata :: Int -> Vector a -> Int -> Vector a | 219 | transdata :: Int -> Vector a -> Int -> Vector a |
220 | constantD :: a -> Int -> Vector a | ||
220 | 221 | ||
221 | instance Element Double where | 222 | instance Element Double where |
222 | subMatrixD = subMatrixR | 223 | subMatrixD = subMatrixR |
223 | transdata = transdata' | 224 | transdata = transdata' |
225 | constantD = constant' | ||
224 | 226 | ||
225 | instance Element (Complex Double) where | 227 | instance Element (Complex Double) where |
226 | subMatrixD = subMatrixC | 228 | subMatrixD = subMatrixC |
227 | transdata = transdata' | 229 | transdata = transdata' |
230 | constantD = constant' | ||
228 | 231 | ||
229 | ------------------------------------------------------------------- | 232 | ------------------------------------------------------------------- |
230 | 233 | ||
@@ -256,6 +259,16 @@ transdata' c1 v c2 = | |||
256 | 259 | ||
257 | ---------------------------------------------------------------------- | 260 | ---------------------------------------------------------------------- |
258 | 261 | ||
262 | constant' v n = unsafePerformIO $ do | ||
263 | w <- createVector n | ||
264 | withForeignPtr (fptr w) $ \p -> do | ||
265 | let go (-1) = return () | ||
266 | go !k = pokeElemOff p k v >> go (k-1) | ||
267 | go (n-1) | ||
268 | return w | ||
269 | |||
270 | ---------------------------------------------------------------------- | ||
271 | |||
259 | -- | extraction of a submatrix from a real matrix | 272 | -- | extraction of a submatrix from a real matrix |
260 | subMatrixR :: (Int,Int) -> (Int,Int) -> Matrix Double -> Matrix Double | 273 | subMatrixR :: (Int,Int) -> (Int,Int) -> Matrix Double -> Matrix Double |
261 | subMatrixR (r0,c0) (rt,ct) x' = unsafePerformIO $ do | 274 | subMatrixR (r0,c0) (rt,ct) x' = unsafePerformIO $ do |