diff options
author | Alberto Ruiz <aruiz@um.es> | 2007-06-05 11:29:18 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2007-06-05 11:29:18 +0000 |
commit | a4254a0b9bfbd720efbe42b86aa50107a74d56c7 (patch) | |
tree | 83370b1c0f4dea228b100194ac1fb0da78be2a61 /lib/Data/Packed/Internal/Matrix.hs | |
parent | 1fb4ea70c517050d3cbad75357a4fffbf5a40e7b (diff) |
subMatrix
Diffstat (limited to 'lib/Data/Packed/Internal/Matrix.hs')
-rw-r--r-- | lib/Data/Packed/Internal/Matrix.hs | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs index a6f7f0c..a2a70dd 100644 --- a/lib/Data/Packed/Internal/Matrix.hs +++ b/lib/Data/Packed/Internal/Matrix.hs | |||
@@ -98,6 +98,8 @@ createMatrix order r c = do | |||
98 | p <- createVector (r*c) | 98 | p <- createVector (r*c) |
99 | return (matrixFromVector order c p) | 99 | return (matrixFromVector order c p) |
100 | 100 | ||
101 | reshape c v = matrixFromVector RowMajor c v | ||
102 | |||
101 | transdataG :: Storable a => Int -> Vector a -> Int -> Vector a | 103 | transdataG :: Storable a => Int -> Vector a -> Int -> Vector a |
102 | transdataG c1 d c2 = fromList . concat . transpose . partit c1 . toList $ d | 104 | transdataG c1 d c2 = fromList . concat . transpose . partit c1 . toList $ d |
103 | 105 | ||
@@ -184,8 +186,41 @@ multiply ColumnMajor a b = trans $ multiplyT ColumnMajor a b | |||
184 | 186 | ||
185 | multiplyT order a b = multiplyD order (trans b) (trans a) | 187 | multiplyT order a b = multiplyD order (trans b) (trans a) |
186 | 188 | ||
187 | multiplyD order a b | 189 | multiplyD order a b |
188 | | isReal (baseOf.dat) a = scast $ multiplyAux order cmultiplyR (scast a) (scast b) | 190 | | isReal (baseOf.dat) a = scast $ multiplyAux order cmultiplyR (scast a) (scast b) |
189 | | isComp (baseOf.dat) a = scast $ multiplyAux order cmultiplyC (scast a) (scast b) | 191 | | isComp (baseOf.dat) a = scast $ multiplyAux order cmultiplyC (scast a) (scast b) |
190 | | otherwise = multiplyG a b | 192 | | otherwise = multiplyG a b |
191 | 193 | ||
194 | ---------------------------------------------------------------------- | ||
195 | |||
196 | -- | extraction of a submatrix of a real matrix | ||
197 | subMatrixR :: (Int,Int) -- ^ (r0,c0) starting position | ||
198 | -> (Int,Int) -- ^ (rt,ct) dimensions of submatrix | ||
199 | -> Matrix Double -> Matrix Double | ||
200 | subMatrixR (r0,c0) (rt,ct) x = unsafePerformIO $ do | ||
201 | r <- createMatrix RowMajor rt ct | ||
202 | c_submatrixR r0 (r0+rt-1) c0 (c0+ct-1) // mat cdat x // mat cdat r // check "subMatrixR" [dat r] | ||
203 | return r | ||
204 | foreign import ccall "aux.h submatrixR" | ||
205 | c_submatrixR :: Int -> Int -> Int -> Int -> Double ::> Double ::> IO Int | ||
206 | |||
207 | -- | extraction of a submatrix of a complex matrix | ||
208 | subMatrixC :: (Int,Int) -- ^ (r0,c0) starting position | ||
209 | -> (Int,Int) -- ^ (rt,ct) dimensions of submatrix | ||
210 | -> Matrix (Complex Double) -> Matrix (Complex Double) | ||
211 | subMatrixC (r0,c0) (rt,ct) x = | ||
212 | reshape ct . asComplex . cdat . | ||
213 | subMatrixR (r0,2*c0) (rt,2*ct) . | ||
214 | reshape (2*cols x) . asReal . cdat $ x | ||
215 | |||
216 | subMatrix :: (Field a) | ||
217 | => (Int,Int) -- ^ (r0,c0) starting position | ||
218 | -> (Int,Int) -- ^ (rt,ct) dimensions of submatrix | ||
219 | -> Matrix a -> Matrix a | ||
220 | subMatrix st sz m | ||
221 | | isReal (baseOf.dat) m = scast $ subMatrixR st sz (scast m) | ||
222 | | isComp (baseOf.dat) m = scast $ subMatrixC st sz (scast m) | ||
223 | | otherwise = subMatrixG st sz m | ||
224 | |||
225 | subMatrixG (r0,c0) (rt,ct) x = reshape ct $ fromList $ concat $ map (subList c0 ct) (subList r0 rt (toLists x)) | ||
226 | where subList s n = take n . drop s | ||