From 6fbed842525491e280448a00a4b5426e6830ccaa Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Thu, 24 Apr 2014 10:30:01 +0200 Subject: cdot and (×) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit added cdot dot renamed to udot <.> changed to cdot and moved to Numeric.LinearAlgebra.Util new general contraction operator (×) Plot functions moved to Numeric.LinearAlgebra.Util --- packages/tests/src/Numeric/LinearAlgebra/Tests.hs | 26 ++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'packages/tests/src/Numeric') diff --git a/packages/tests/src/Numeric/LinearAlgebra/Tests.hs b/packages/tests/src/Numeric/LinearAlgebra/Tests.hs index 99c0c91..7e1799e 100644 --- a/packages/tests/src/Numeric/LinearAlgebra/Tests.hs +++ b/packages/tests/src/Numeric/LinearAlgebra/Tests.hs @@ -43,6 +43,8 @@ import Control.Arrow((***)) import Debug.Trace import Control.Monad(when) import Numeric.LinearAlgebra.Util hiding (ones,row,col) +import Control.Applicative +import Control.Monad(ap) import Data.Packed.ST @@ -266,9 +268,9 @@ normsVTest = TestList [ ] where v = fromList [1,-2,3:+4] :: Vector (Complex Double) x = fromList [1,2,-3] :: Vector Double #ifndef NONORMVTEST - norm2PropR a = norm2 a =~= sqrt (dot a a) + norm2PropR a = norm2 a =~= sqrt (udot a a) #endif - norm2PropC a = norm2 a =~= realPart (sqrt (dot a (conj a))) + norm2PropC a = norm2 a =~= realPart (sqrt (udot a (conj a))) a =~= b = fromList [a] |~| fromList [b] normsMTest = TestList [ @@ -330,6 +332,15 @@ conjuTest m = mapVector conjugate (flatten (trans m)) == flatten (ctrans m) newtype State s a = State { runState :: s -> (a,s) } +instance Functor (State s) + where + fmap f x = pure f <*> x + +instance Applicative (State s) + where + pure = return + (<*>) = ap + instance Monad (State s) where return a = State $ \s -> (a,s) m >>= f = State $ \s -> let (a,s') = runState m s @@ -347,6 +358,15 @@ evalState m s = let (a,s') = runState m s newtype MaybeT m a = MaybeT { runMaybeT :: m (Maybe a) } +instance Monad m => Functor (MaybeT m) + where + fmap f x = pure f <*> x + +instance Monad m => Applicative (MaybeT m) + where + pure = return + (<*>) = ap + instance Monad m => Monad (MaybeT m) where return a = MaybeT $ return $ Just a m >>= f = MaybeT $ do @@ -640,7 +660,7 @@ a |~~| b = a :~6~: b makeUnitary v | realPart n > 1 = v / scalar n | otherwise = v - where n = sqrt (conj v <.> v) + where n = sqrt (conj v `udot` v) -- -- | Some additional tests on big matrices. They take a few minutes. -- runBigTests :: IO () -- cgit v1.2.3