From 2747c2ba403dafcc52bac09d2fd51b6d66fa5e9e Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Sun, 3 Feb 2008 12:52:17 +0000 Subject: test modules reorganized --- lib/Numeric/LinearAlgebra/Tests/Instances.hs | 70 ++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 lib/Numeric/LinearAlgebra/Tests/Instances.hs (limited to 'lib/Numeric/LinearAlgebra/Tests/Instances.hs') diff --git a/lib/Numeric/LinearAlgebra/Tests/Instances.hs b/lib/Numeric/LinearAlgebra/Tests/Instances.hs new file mode 100644 index 0000000..fececdb --- /dev/null +++ b/lib/Numeric/LinearAlgebra/Tests/Instances.hs @@ -0,0 +1,70 @@ +{-# OPTIONS #-} +----------------------------------------------------------------------------- +{- | +Module : Numeric.LinearAlgebra.Tests.Instances +Copyright : (c) Alberto Ruiz 2008 +License : GPL-style + +Maintainer : Alberto Ruiz (aruiz at um dot es) +Stability : provisional +Portability : portable + +Arbitrary instances for vectors, matrices. + +-} + +module Numeric.LinearAlgebra.Tests.Instances( + Sq(..), + Rot(..), + Her(..) +) where + +import Numeric.LinearAlgebra +import Test.QuickCheck + +instance (Arbitrary a, RealFloat a) => Arbitrary (Complex a) where + arbitrary = do + r <- arbitrary + i <- arbitrary + return (r:+i) + coarbitrary = undefined + +chooseDim = sized $ \m -> choose (1,max 1 m) + +instance (Field a, Arbitrary a) => Arbitrary (Vector a) where + arbitrary = do m <- chooseDim + l <- vector m + return $ fromList l + coarbitrary = undefined + +instance (Element a, Arbitrary a) => Arbitrary (Matrix a) where + arbitrary = do + m <- chooseDim + n <- chooseDim + l <- vector (m*n) + return $ (m> Arbitrary (Sq a) where + arbitrary = do + n <- chooseDim + l <- vector (n*n) + return $ Sq $ (n> Arbitrary (Rot a) where + arbitrary = do + Sq m <- arbitrary + let (q,_) = qr m + return (Rot q) + coarbitrary = undefined + +newtype (Her a) = Her (Matrix a) deriving Show +instance (Field a, Arbitrary a) => Arbitrary (Her a) where + arbitrary = do + Sq m <- arbitrary + let m' = m/2 + return $ Her (m' + ctrans m') + coarbitrary = undefined -- cgit v1.2.3