summaryrefslogtreecommitdiff
path: root/lib/Data
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-11-30 19:55:34 +0000
committerAlberto Ruiz <aruiz@um.es>2007-11-30 19:55:34 +0000
commitd7d3b731c037fca41bd9128c3da2a582189cb4d9 (patch)
treef1bf8f1fa538033ff184d6cc556e808bfaaa71a9 /lib/Data
parent975d3730a923387f9d1a0be4f7d11b01b27a09df (diff)
hide internal modules
Diffstat (limited to 'lib/Data')
-rw-r--r--lib/Data/Packed/Internal/Matrix.hs42
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
257foreign import ccall safe "auxi.h transR" 257foreign import ccall unsafe "auxi.h transR"
258 ctransR :: TMM -- Double ::> Double ::> IO Int 258 ctransR :: TMM -- Double ::> Double ::> IO Int
259foreign import ccall safe "auxi.h transC" 259foreign 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
279multiplyR = multiplyAux cmultiplyR 279multiplyR = multiplyAux cmultiplyR
280foreign import ccall safe "auxi.h multiplyR" 280foreign 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
286multiplyC = multiplyAux cmultiplyC 286multiplyC = multiplyAux cmultiplyC
287foreign import ccall safe "auxi.h multiplyC" 287foreign 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
293multiply' :: (Element a) => MatrixOrder -> Matrix a -> Matrix a -> Matrix a
294multiply' RowMajor a b = multiplyD a b
295multiply' ColumnMajor a b = trans $ multiplyD (trans b) (trans a)
296
297
298-- | matrix product 293-- | matrix product
299multiply :: (Element a) => Matrix a -> Matrix a -> Matrix a 294multiply :: (Element a) => Matrix a -> Matrix a -> Matrix a
300multiply = multiplyD 295multiply = 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
404foreign import ccall "auxi.h matrix_fscanf" c_gslReadMatrix:: Ptr CChar -> TM 399foreign import ccall "auxi.h matrix_fscanf" c_gslReadMatrix:: Ptr CChar -> TM
405
406-------------------------------------------------------------------------
407
408-- Generic definitions
409
410{-
411transL m = matrixFromVector RowMajor (rows m) $ transdata (cols m) (cdat m) (rows m)
412
413subMatrixG (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
416diagG 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
423transdataG c1 d _ = fromList . concat . transpose . partit c1 . toList $ d
424
425dotL a b = sum (zipWith (*) a b)
426
427multiplyG a b = matrixFromVector RowMajor (cols b) $ fromList $ concat $ multiplyL (toLists a) (toLists b)
428
429multiplyL 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