diff options
Diffstat (limited to 'lib/Data/Packed/Internal/Matrix.hs')
-rw-r--r-- | lib/Data/Packed/Internal/Matrix.hs | 42 |
1 files changed, 4 insertions, 38 deletions
diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs index 4cc94b7..b0fea51 100644 --- a/lib/Data/Packed/Internal/Matrix.hs +++ b/lib/Data/Packed/Internal/Matrix.hs | |||
@@ -254,9 +254,9 @@ transdataAux fun c1 d c2 = | |||
254 | r2 = dim d `div` c2 | 254 | r2 = dim d `div` c2 |
255 | noneed = r1 == 1 || c1 == 1 | 255 | noneed = r1 == 1 || c1 == 1 |
256 | 256 | ||
257 | foreign import ccall safe "auxi.h transR" | 257 | foreign import ccall unsafe "auxi.h transR" |
258 | ctransR :: TMM -- Double ::> Double ::> IO Int | 258 | ctransR :: TMM -- Double ::> Double ::> IO Int |
259 | foreign import ccall safe "auxi.h transC" | 259 | foreign import ccall unsafe "auxi.h transC" |
260 | ctransC :: TCMCM -- Complex Double ::> Complex Double ::> IO Int | 260 | ctransC :: TCMCM -- Complex Double ::> Complex Double ::> IO Int |
261 | 261 | ||
262 | ------------------------------------------------------------------ | 262 | ------------------------------------------------------------------ |
@@ -277,24 +277,19 @@ multiplyAux fun a b = unsafePerformIO $ do | |||
277 | return r | 277 | return r |
278 | 278 | ||
279 | multiplyR = multiplyAux cmultiplyR | 279 | multiplyR = multiplyAux cmultiplyR |
280 | foreign import ccall safe "auxi.h multiplyR" | 280 | foreign import ccall unsafe "auxi.h multiplyR" |
281 | cmultiplyR :: Int -> Int -> Int -> Ptr Double | 281 | cmultiplyR :: Int -> Int -> Int -> Ptr Double |
282 | -> Int -> Int -> Int -> Ptr Double | 282 | -> Int -> Int -> Int -> Ptr Double |
283 | -> Int -> Int -> Ptr Double | 283 | -> Int -> Int -> Ptr Double |
284 | -> IO Int | 284 | -> IO Int |
285 | 285 | ||
286 | multiplyC = multiplyAux cmultiplyC | 286 | multiplyC = multiplyAux cmultiplyC |
287 | foreign import ccall safe "auxi.h multiplyC" | 287 | foreign import ccall unsafe "auxi.h multiplyC" |
288 | cmultiplyC :: Int -> Int -> Int -> Ptr (Complex Double) | 288 | cmultiplyC :: Int -> Int -> Int -> Ptr (Complex Double) |
289 | -> Int -> Int -> Int -> Ptr (Complex Double) | 289 | -> Int -> Int -> Int -> Ptr (Complex Double) |
290 | -> Int -> Int -> Ptr (Complex Double) | 290 | -> Int -> Int -> Ptr (Complex Double) |
291 | -> IO Int | 291 | -> IO Int |
292 | 292 | ||
293 | multiply' :: (Element a) => MatrixOrder -> Matrix a -> Matrix a -> Matrix a | ||
294 | multiply' RowMajor a b = multiplyD a b | ||
295 | multiply' ColumnMajor a b = trans $ multiplyD (trans b) (trans a) | ||
296 | |||
297 | |||
298 | -- | matrix product | 293 | -- | matrix product |
299 | multiply :: (Element a) => Matrix a -> Matrix a -> Matrix a | 294 | multiply :: (Element a) => Matrix a -> Matrix a -> Matrix a |
300 | multiply = multiplyD | 295 | multiply = multiplyD |
@@ -402,32 +397,3 @@ fromFile filename (r,c) = do | |||
402 | --free charname -- TO DO: free the auxiliary CString | 397 | --free charname -- TO DO: free the auxiliary CString |
403 | return res | 398 | return res |
404 | foreign import ccall "auxi.h matrix_fscanf" c_gslReadMatrix:: Ptr CChar -> TM | 399 | foreign import ccall "auxi.h matrix_fscanf" c_gslReadMatrix:: Ptr CChar -> TM |
405 | |||
406 | ------------------------------------------------------------------------- | ||
407 | |||
408 | -- Generic definitions | ||
409 | |||
410 | {- | ||
411 | transL m = matrixFromVector RowMajor (rows m) $ transdata (cols m) (cdat m) (rows m) | ||
412 | |||
413 | subMatrixG (r0,c0) (rt,ct) x = matrixFromVector RowMajor ct $ fromList $ concat $ map (subList c0 ct) (subList r0 rt (toLists x)) | ||
414 | where subList s n = take n . drop s | ||
415 | |||
416 | diagG v = matrixFromVector RowMajor c $ fromList $ [ l!!(i-1) * delta k i | k <- [1..c], i <- [1..c]] | ||
417 | where c = dim v | ||
418 | l = toList v | ||
419 | delta i j | i==j = 1 | ||
420 | | otherwise = 0 | ||
421 | -} | ||
422 | |||
423 | transdataG c1 d _ = fromList . concat . transpose . partit c1 . toList $ d | ||
424 | |||
425 | dotL a b = sum (zipWith (*) a b) | ||
426 | |||
427 | multiplyG a b = matrixFromVector RowMajor (cols b) $ fromList $ concat $ multiplyL (toLists a) (toLists b) | ||
428 | |||
429 | multiplyL a b | ok = [[dotL x y | y <- transpose b] | x <- a] | ||
430 | | otherwise = error "inconsistent dimensions in contraction " | ||
431 | where ok = case common length a of | ||
432 | Nothing -> False | ||
433 | Just c -> c == length b | ||