diff options
Diffstat (limited to 'lib/Data')
-rw-r--r-- | lib/Data/Packed/Internal/Matrix.hs | 27 | ||||
-rw-r--r-- | lib/Data/Packed/Matrix.hs | 1 |
2 files changed, 28 insertions, 0 deletions
diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs index 86c5915..1c58f6e 100644 --- a/lib/Data/Packed/Internal/Matrix.hs +++ b/lib/Data/Packed/Internal/Matrix.hs | |||
@@ -385,3 +385,30 @@ fromFile filename (r,c) = do | |||
385 | --free charname -- TO DO: free the auxiliary CString | 385 | --free charname -- TO DO: free the auxiliary CString |
386 | return res | 386 | return res |
387 | foreign import ccall "auxi.h matrix_fscanf" c_gslReadMatrix:: Ptr CChar -> TM | 387 | foreign import ccall "auxi.h matrix_fscanf" c_gslReadMatrix:: Ptr CChar -> TM |
388 | |||
389 | ---------------------------------------------------------------------------- | ||
390 | |||
391 | {- | creates a new matrix with the given position updated with a modification function | ||
392 | |||
393 | @> updateMatrix (0,2) (const 57) (ident 3 :: Matrix Double) | ||
394 | (3><3) | ||
395 | [ 1.0, 0.0, 57.0 | ||
396 | , 0.0, 1.0, 0.0 | ||
397 | , 0.0, 0.0, 1.0 ]@ | ||
398 | |||
399 | -} | ||
400 | updateMatrix :: Storable t | ||
401 | => (Int,Int) -- ^ position (row,column) | ||
402 | -> (t -> t) -- ^ modification function | ||
403 | -> Matrix t -- ^ source matrix | ||
404 | -> Matrix t -- ^ result | ||
405 | |||
406 | updateMatrix (i,j) f (m@MC {rows = r, cols = c, cdat = v}) | ||
407 | | i<0 || i>=r || j<0 || j>=c = error $ "updateMatrix out of range(size="++show (r,c)++", pos="++show (i,j)++")" | ||
408 | | otherwise = let pos = i*c+j | ||
409 | in m { cdat = updateVector pos f v } | ||
410 | |||
411 | updateMatrix (i,j) f (m@MF {rows = r, cols = c, fdat = v}) | ||
412 | | i<0 || i>=r || j<0 || j>=c = error $ "updateMatrix out of range(size="++show (r,c)++", pos="++show (i,j)++")" | ||
413 | | otherwise = let pos = j*r+i | ||
414 | in m { fdat = updateVector pos f v } | ||
diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs index 62d28b1..b2e58b5 100644 --- a/lib/Data/Packed/Matrix.hs +++ b/lib/Data/Packed/Matrix.hs | |||
@@ -28,6 +28,7 @@ module Data.Packed.Matrix ( | |||
28 | subMatrix, takeRows, dropRows, takeColumns, dropColumns, | 28 | subMatrix, takeRows, dropRows, takeColumns, dropColumns, |
29 | extractRows, | 29 | extractRows, |
30 | ident, diag, diagRect, takeDiag, | 30 | ident, diag, diagRect, takeDiag, |
31 | updateMatrix, | ||
31 | liftMatrix, liftMatrix2, | 32 | liftMatrix, liftMatrix2, |
32 | format, readMatrix, fromFile, fromArray2D | 33 | format, readMatrix, fromFile, fromArray2D |
33 | ) where | 34 | ) where |