-- Do not edit! Automatically created with doctest-extract from src/Numeric/BLAS/Matrix/TransposablePrivate.hs {-# LINE 36 "src/Numeric/BLAS/Matrix/TransposablePrivate.hs" #-} {-# OPTIONS_GHC -XTypeOperators #-} module Test.ComplexFloat.Numeric.BLAS.Matrix.TransposablePrivate where import qualified Test.DocTest.Driver as DocTest {-# LINE 38 "src/Numeric/BLAS/Matrix/TransposablePrivate.hs" #-} import Test.ComplexFloat.Numeric.BLAS.Matrix.RowMajor (forMatrix) import Test.ComplexFloat.Numeric.BLAS.Vector (genVector, number_) import Test.Slice (ShapeInt, shapeInt) import qualified Numeric.BLAS.Matrix.Transposable as Transp import qualified Numeric.BLAS.Matrix.RowMajor.Square as Square import qualified Numeric.BLAS.Matrix.RowMajor as Matrix import qualified Numeric.BLAS.Vector as Vector import qualified Numeric.Netlib.Class as Class import Numeric.BLAS.Matrix.Transposable (Transposable, transposed, nonTransposed) -- import Numeric.BLAS.Vector (Vector) -- import Numeric.Netlib.Modifier (Conjugation(NonConjugated, Conjugated)) import qualified Numeric.Netlib.Modifier as Modi import qualified Data.Array.Comfort.Boxed as BoxedArray import qualified Data.Array.Comfort.Storable as Array import qualified Data.Array.Comfort.Shape as Shape import Data.Tuple.HT (swap) import qualified Test.QuickCheck as QC import Test.QuickCheck ((===)) maxDim :: Int maxDim = 10 genIdentityTrans :: (Shape.C sh, Class.Floating a) => sh -> QC.Gen (Transp.Transposable sh sh a) genIdentityTrans sh = do trans <- QC.arbitrary return $ case trans of Modi.Transposed -> transposed (Matrix.identity sh) Modi.NonTransposed -> nonTransposed (Matrix.identity sh) forTransposable :: (QC.Testable prop, QC.Arbitrary a, Class.Floating a, Show a) => QC.Gen a -> (Transposable ShapeInt ShapeInt a -> prop) -> QC.Property forTransposable genElem prop = forMatrix genElem $ \a trans -> prop $ case trans of Modi.Transposed -> transposed a Modi.NonTransposed -> nonTransposed a genTransposable :: (Shape.C height, Shape.C width, Class.Floating a) => (height,width) -> QC.Gen a -> QC.Gen (Transposable height width a) genTransposable shape genElem = QC.oneof [fmap nonTransposed $ genVector shape genElem, fmap transposed $ genVector (swap shape) genElem] test :: DocTest.T () test = do DocTest.printPrefix "Numeric.BLAS.Matrix.TransposablePrivate:176: " {-# LINE 176 "src/Numeric/BLAS/Matrix/TransposablePrivate.hs" #-} DocTest.property( {-# LINE 176 "src/Numeric/BLAS/Matrix/TransposablePrivate.hs" #-} forMatrix number_ $ \a -> QC.forAll (genIdentityTrans (Matrix.height a)) $ \eye -> a === Transp.multiply eye (nonTransposed a) ) DocTest.printPrefix "Numeric.BLAS.Matrix.TransposablePrivate:181: " {-# LINE 181 "src/Numeric/BLAS/Matrix/TransposablePrivate.hs" #-} DocTest.property( {-# LINE 181 "src/Numeric/BLAS/Matrix/TransposablePrivate.hs" #-} forMatrix number_ $ \a -> QC.forAll (genIdentityTrans (Matrix.width a)) $ \eye -> a === Transp.multiply (nonTransposed a) eye ) DocTest.printPrefix "Numeric.BLAS.Matrix.TransposablePrivate:186: " {-# LINE 186 "src/Numeric/BLAS/Matrix/TransposablePrivate.hs" #-} DocTest.property( {-# LINE 186 "src/Numeric/BLAS/Matrix/TransposablePrivate.hs" #-} forMatrix number_ $ \a -> QC.forAll (genIdentityTrans (Matrix.width a)) $ \leftEye -> QC.forAll (genIdentityTrans (Matrix.height a)) $ \rightEye -> Transp.multiply leftEye (transposed a) === Transp.multiply (transposed a) rightEye ) DocTest.printPrefix "Numeric.BLAS.Matrix.TransposablePrivate:194: " {-# LINE 194 "src/Numeric/BLAS/Matrix/TransposablePrivate.hs" #-} DocTest.property( {-# LINE 194 "src/Numeric/BLAS/Matrix/TransposablePrivate.hs" #-} forMatrix number_ $ \a -> QC.forAll (QC.choose (0,maxDim)) $ \n -> QC.forAll (genVector (Matrix.width a, shapeInt n) number_) $ \b -> Matrix.transpose (Matrix.multiply a b) === Transp.multiply (transposed b) (transposed a) ) DocTest.printPrefix "Numeric.BLAS.Matrix.TransposablePrivate:256: " {-# LINE 256 "src/Numeric/BLAS/Matrix/TransposablePrivate.hs" #-} DocTest.property( {-# LINE 256 "src/Numeric/BLAS/Matrix/TransposablePrivate.hs" #-} forTransposable number_ $ \a -> QC.forAll (genTransposable (Transp.shape a) number_) $ \b -> Array.toBoxed (Transp.dotRowwise a b) === BoxedArray.zipWith Vector.dot (Matrix.toRowArray $ Transp.toMatrix a) (Matrix.toRowArray $ Transp.toMatrix b) ) DocTest.printPrefix "Numeric.BLAS.Matrix.TransposablePrivate:267: " {-# LINE 267 "src/Numeric/BLAS/Matrix/TransposablePrivate.hs" #-} DocTest.property( {-# LINE 267 "src/Numeric/BLAS/Matrix/TransposablePrivate.hs" #-} forTransposable number_ $ \a -> QC.forAll (genTransposable (Transp.shape a) number_) $ \b -> Square.takeDiagonal (Array.mapShape (Shape.Square . fst) (Transp.multiply a (Transp.transpose b))) === Transp.dotRowwise a b ) DocTest.printPrefix "Numeric.BLAS.Matrix.TransposablePrivate:278: " {-# LINE 278 "src/Numeric/BLAS/Matrix/TransposablePrivate.hs" #-} DocTest.property( {-# LINE 278 "src/Numeric/BLAS/Matrix/TransposablePrivate.hs" #-} forMatrix number_ $ \a -> QC.forAll (genVector (Array.shape a) number_) $ \b -> Vector.dot a b === Vector.sum (Transp.dotRowwise (transposed a) (transposed b)) ) DocTest.printPrefix "Numeric.BLAS.Matrix.TransposablePrivate:287: " {-# LINE 287 "src/Numeric/BLAS/Matrix/TransposablePrivate.hs" #-} DocTest.property( {-# LINE 287 "src/Numeric/BLAS/Matrix/TransposablePrivate.hs" #-} forTransposable number_ $ \a -> QC.forAll (genTransposable (Transp.shape a) number_) $ \b -> Transp.dotRowwise a b === Transp.dotRowwise b a ) DocTest.printPrefix "Numeric.BLAS.Matrix.TransposablePrivate:312: " {-# LINE 312 "src/Numeric/BLAS/Matrix/TransposablePrivate.hs" #-} DocTest.property( {-# LINE 312 "src/Numeric/BLAS/Matrix/TransposablePrivate.hs" #-} forTransposable number_ $ \a -> QC.forAll (genTransposable (Transp.shape a) number_) $ \b -> Transp.innerRowwise a b === Transp.dotRowwise (Transp.conjugate a) b ) DocTest.printPrefix "Numeric.BLAS.Matrix.TransposablePrivate:321: " {-# LINE 321 "src/Numeric/BLAS/Matrix/TransposablePrivate.hs" #-} DocTest.property( {-# LINE 321 "src/Numeric/BLAS/Matrix/TransposablePrivate.hs" #-} forMatrix number_ $ \a -> QC.forAll (genVector (Array.shape a) number_) $ \b -> Vector.inner a b === Vector.sum (Transp.innerRowwise (transposed a) (transposed b)) )