summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/parallel.hs19
-rw-r--r--lib/Numeric/LinearAlgebra/Algorithms.hs8
2 files changed, 6 insertions, 21 deletions
diff --git a/examples/parallel.hs b/examples/parallel.hs
index 3c83c54..435e367 100644
--- a/examples/parallel.hs
+++ b/examples/parallel.hs
@@ -6,19 +6,16 @@ import Control.Parallel.Strategies
6import System.Time 6import System.Time
7 7
8inParallel = parMap rwhnf id 8inParallel = parMap rwhnf id
9-- rdeepseq (or older rnf) not needed in this case 9
10 10
11-- matrix product decomposed into p parallel subtasks 11-- matrix product decomposed into p parallel subtasks
12parMul p x y = fromBlocks [ inParallel ( map (x <>) ys ) ] 12parMul p x y = fromBlocks [ inParallel ( map (x <>) ys ) ]
13 where ys = splitColumns p y 13 where [ys] = toBlocksEvery (rows y) (cols y `div` p) y
14
15-- x <||> y = fromColumns . inParallel . map (x <>) . toColumns $ y
16 14
17main = do 15main = do
18 n <- (read . head) `fmap` getArgs 16 n <- (read . head) `fmap` getArgs
19 let m = ident n :: Matrix Double 17 let m = ident n :: Matrix Double
20 time $ print $ vectorMax $ takeDiag $ m <> m 18 time $ print $ vectorMax $ takeDiag $ m <> m
21-- time $ print $ vectorMax $ takeDiag $ m <||> m
22 time $ print $ vectorMax $ takeDiag $ parMul 2 m m 19 time $ print $ vectorMax $ takeDiag $ parMul 2 m m
23 time $ print $ vectorMax $ takeDiag $ parMul 4 m m 20 time $ print $ vectorMax $ takeDiag $ parMul 4 m m
24 time $ print $ vectorMax $ takeDiag $ parMul 8 m m 21 time $ print $ vectorMax $ takeDiag $ parMul 8 m m
@@ -28,15 +25,3 @@ time act = do
28 act 25 act
29 t1 <- getClockTime 26 t1 <- getClockTime
30 print $ tdSec $ normalizeTimeDiff $ diffClockTimes t1 t0 27 print $ tdSec $ normalizeTimeDiff $ diffClockTimes t1 t0
31
32splitColumns n m = splitColumns' (f n (cols m)) m
33 where
34 splitColumns' [] m = []
35 splitColumns' ((a,b):rest) m = subMatrix (0,a) (rows m, b-a+1) m : splitColumns' rest m
36
37 f :: Int -> Int -> [(Int,Int)]
38 f n c = zip ks (map pred $ tail ks)
39 where ks = map round $ toList $ linspace (fromIntegral n+1) (0,fromIntegral c)
40
41splitRowsAt p m = (takeRows p m, dropRows p m)
42splitColumnsAt p m = (takeColumns p m, dropColumns p m)
diff --git a/lib/Numeric/LinearAlgebra/Algorithms.hs b/lib/Numeric/LinearAlgebra/Algorithms.hs
index 580f4bb..fc2fcb2 100644
--- a/lib/Numeric/LinearAlgebra/Algorithms.hs
+++ b/lib/Numeric/LinearAlgebra/Algorithms.hs
@@ -329,15 +329,15 @@ ctrans = ctrans'
329 329
330-- | Matrix product. 330-- | Matrix product.
331multiply :: Field t => Matrix t -> Matrix t -> Matrix t 331multiply :: Field t => Matrix t -> Matrix t -> Matrix t
332multiply = multiply' 332multiply = {-# SCC "multiply" #-} multiply'
333 333
334-- | Similar to 'cholSH', but instead of an error (e.g., caused by a matrix not positive definite) it returns 'Nothing'. 334-- | Similar to 'cholSH', but instead of an error (e.g., caused by a matrix not positive definite) it returns 'Nothing'.
335mbCholSH :: Field t => Matrix t -> Maybe (Matrix t) 335mbCholSH :: Field t => Matrix t -> Maybe (Matrix t)
336mbCholSH = mbCholSH' 336mbCholSH = {-# SCC "mbCholSH" #-} mbCholSH'
337 337
338-- | Similar to 'chol', without checking that the input matrix is hermitian or symmetric. It works with the upper triangular part. 338-- | Similar to 'chol', without checking that the input matrix is hermitian or symmetric. It works with the upper triangular part.
339cholSH :: Field t => Matrix t -> Matrix t 339cholSH :: Field t => Matrix t -> Matrix t
340cholSH = cholSH' 340cholSH = {-# SCC "cholSH" #-} cholSH'
341 341
342-- | Cholesky factorization of a positive definite hermitian or symmetric matrix. 342-- | Cholesky factorization of a positive definite hermitian or symmetric matrix.
343-- 343--
@@ -351,7 +351,7 @@ chol m | exactHermitian m = cholSH m
351 351
352-- | Determinant of a square matrix. 352-- | Determinant of a square matrix.
353det :: Field t => Matrix t -> t 353det :: Field t => Matrix t -> t
354det m | square m = s * (product $ toList $ takeDiag $ lup) 354det m | square m = {-# SCC "det" #-} s * (product $ toList $ takeDiag $ lup)
355 | otherwise = error "det of nonsquare matrix" 355 | otherwise = error "det of nonsquare matrix"
356 where (lup,perm) = luPacked m 356 where (lup,perm) = luPacked m
357 s = signlp (rows m) perm 357 s = signlp (rows m) perm