diff options
Diffstat (limited to 'packages/base/src/Internal/Matrix.hs')
-rw-r--r-- | packages/base/src/Internal/Matrix.hs | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/packages/base/src/Internal/Matrix.hs b/packages/base/src/Internal/Matrix.hs index df56207..5163421 100644 --- a/packages/base/src/Internal/Matrix.hs +++ b/packages/base/src/Internal/Matrix.hs | |||
@@ -70,7 +70,7 @@ is1d (size->(r,c)) = r==1 || c==1 | |||
70 | {-# INLINE is1d #-} | 70 | {-# INLINE is1d #-} |
71 | 71 | ||
72 | -- data is not contiguous | 72 | -- data is not contiguous |
73 | isSlice m@(size->(r,c)) = (c < xRow m || r < xCol m) && min r c > 1 | 73 | isSlice m@(size->(r,c)) = r*c < dim (xdat m) |
74 | {-# INLINE isSlice #-} | 74 | {-# INLINE isSlice #-} |
75 | 75 | ||
76 | orderOf :: Matrix t -> MatrixOrder | 76 | orderOf :: Matrix t -> MatrixOrder |
@@ -359,26 +359,16 @@ instance Element Z where | |||
359 | 359 | ||
360 | ------------------------------------------------------------------- | 360 | ------------------------------------------------------------------- |
361 | 361 | ||
362 | -- | reference to a rectangular slice of a matrix (no data copy) | ||
362 | subMatrix :: Element a | 363 | subMatrix :: Element a |
363 | => (Int,Int) -- ^ (r0,c0) starting position | ||
364 | -> (Int,Int) -- ^ (rt,ct) dimensions of submatrix | ||
365 | -> Matrix a -- ^ input matrix | ||
366 | -> Matrix a -- ^ result | ||
367 | subMatrix (r0,c0) (rt,ct) m | ||
368 | | 0 <= r0 && 0 <= rt && r0+rt <= rows m && | ||
369 | 0 <= c0 && 0 <= ct && c0+ct <= cols m = unsafePerformIO $ extractR RowMajor m 0 (idxs[r0,r0+rt-1]) 0 (idxs[c0,c0+ct-1]) | ||
370 | | otherwise = error $ "wrong subMatrix "++show ((r0,c0),(rt,ct))++" of "++shSize m | ||
371 | |||
372 | |||
373 | sliceMatrix :: Element a | ||
374 | => (Int,Int) -- ^ (r0,c0) starting position | 364 | => (Int,Int) -- ^ (r0,c0) starting position |
375 | -> (Int,Int) -- ^ (rt,ct) dimensions of submatrix | 365 | -> (Int,Int) -- ^ (rt,ct) dimensions of submatrix |
376 | -> Matrix a -- ^ input matrix | 366 | -> Matrix a -- ^ input matrix |
377 | -> Matrix a -- ^ result | 367 | -> Matrix a -- ^ result |
378 | sliceMatrix (r0,c0) (rt,ct) m | 368 | subMatrix (r0,c0) (rt,ct) m |
379 | | 0 <= r0 && 0 <= rt && r0+rt <= rows m && | 369 | | 0 <= r0 && 0 <= rt && r0+rt <= rows m && |
380 | 0 <= c0 && 0 <= ct && c0+ct <= cols m = res | 370 | 0 <= c0 && 0 <= ct && c0+ct <= cols m = res |
381 | | otherwise = error $ "wrong sliceMatrix "++show ((r0,c0),(rt,ct))++" of "++shSize m | 371 | | otherwise = error $ "wrong subMatrix "++show ((r0,c0),(rt,ct))++" of "++shSize m |
382 | where | 372 | where |
383 | p = r0 * xRow m + c0 * xCol m | 373 | p = r0 * xRow m + c0 * xCol m |
384 | tot | rowOrder m = ct + (rt-1) * xRow m | 374 | tot | rowOrder m = ct + (rt-1) * xRow m |