From e499467d2c67f214b0871376b068c5b6fc7896a1 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Fri, 10 Apr 2015 09:53:23 +0200 Subject: merge recent --- examples/inplace.hs | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'examples') diff --git a/examples/inplace.hs b/examples/inplace.hs index dcfff56..574aa44 100644 --- a/examples/inplace.hs +++ b/examples/inplace.hs @@ -1,9 +1,8 @@ -- some tests of the interface for pure -- computations with inplace updates -import Numeric.LinearAlgebra -import Data.Packed.ST -import Data.Packed.Convert +import Numeric.LinearAlgebra.HMatrix +import Numeric.LinearAlgebra.Devel import Data.Array.Unboxed import Data.Array.ST @@ -15,15 +14,13 @@ main = sequence_[ print test2, print test3, print test4, - test5, - test6, - print test7, +-- test5, +-- test6, +-- print test7, test8, test0] --- helper functions -vector l = fromList l :: Vector Double -norm v = pnorm PNorm2 v + -- hmatrix vector and matrix v = vector [1..10] @@ -34,16 +31,16 @@ m = (5><10) [1..50::Double] -- vector creation by in-place updates on a copy of the argument test1 = fun v -fun :: Element t => Vector t -> Vector t +-- fun :: (Num t, Element t, Container) => Vector t -> Vector t fun x = runSTVector $ do a <- thawVector x - mapM_ (flip (modifyVector a) (+57)) [0 .. dim x `div` 2 - 1] + mapM_ (flip (modifyVector a) (+57)) [0 .. size x `div` 2 - 1] return a -- another example: creation of an antidiagonal matrix from a list test2 = antiDiag 5 8 [1..] :: Matrix Double -antiDiag :: (Element b) => Int -> Int -> [b] -> Matrix b +-- antiDiag :: (Element b) => Int -> Int -> [b] -> Matrix b antiDiag r c l = runSTMatrix $ do m <- newMatrix 0 r c let d = min r c - 1 @@ -55,21 +52,23 @@ test3 = g1 v g1 x = runST $ do a <- thawVector x - writeVector a (dim x -1) 0 + writeVector a (size x -1) 0 b <- freezeVector a - return (norm b) + return (norm_2 b) -- another possibility: test4 = g2 v g2 x = runST $ do a <- thawVector x - writeVector a (dim x -1) 0 - t <- liftSTVector norm a + writeVector a (size x -1) 0 + t <- liftSTVector norm_2 a return t -------------------------------------------------------------- +{- + -- haskell arrays hv = listArray (0,9) [1..10::Double] hm = listArray ((0,0),(4,9)) [1..50::Double] @@ -78,8 +77,8 @@ hm = listArray ((0,0),(4,9)) [1..50::Double] -- conversion from standard Haskell arrays test5 = do - print $ norm (vectorFromArray hv) - print $ norm v + print $ norm_2 (vectorFromArray hv) + print $ norm_2 v print $ rcond (matrixFromArray hm) print $ rcond m @@ -101,10 +100,11 @@ test7 = unitary (listArray (1,4) [3,5,7,2] :: UArray Int Double) unitary v = runSTUArray $ do a <- thaw v - n <- norm `fmap` vectorFromMArray a + n <- norm_2 `fmap` vectorFromMArray a b <- mapArray (/n) a return b +-} ------------------------------------------------- -- (just to check that they are not affected) @@ -150,3 +150,4 @@ test8 = do print $ histoCheck2 ds print $ histoCheck2 ds putStrLn "----------------------" + -- cgit v1.2.3