From 945ae28d720ab6367a293d8f6a5723b8f7bf835d Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Wed, 8 Sep 2010 08:58:35 +0000 Subject: fixed type of vector norms --- lib/Numeric/Container.hs | 24 ++++++++++++------------ lib/Numeric/LinearAlgebra/Algorithms.hs | 12 ++++++------ lib/Numeric/LinearAlgebra/Tests.hs | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) (limited to 'lib/Numeric') diff --git a/lib/Numeric/Container.hs b/lib/Numeric/Container.hs index fc4fb0d..a3a039a 100644 --- a/lib/Numeric/Container.hs +++ b/lib/Numeric/Container.hs @@ -216,13 +216,13 @@ class Num e => Vectors a e where -- | dot (inner) product dot :: a e -> a e -> e -- | sum of absolute value of elements (differs in complex case from @norm1@ - absSum :: a e -> e + absSum :: a e -> RealOf e -- | sum of absolute value of elements - norm1 :: a e -> e + norm1 :: a e -> RealOf e -- | euclidean norm - norm2 :: a e -> e + norm2 :: a e -> RealOf e -- | element of maximum magnitude - normInf :: a e -> e + normInf :: a e -> RealOf e instance Vectors Vector Float where norm2 = toScalarF Norm2 @@ -239,18 +239,18 @@ instance Vectors Vector Double where normInf = maxElement . vectorMapR Abs instance Vectors Vector (Complex Float) where - norm2 = (:+ 0) . toScalarQ Norm2 - absSum = (:+ 0) . toScalarQ AbsSum + norm2 = toScalarQ Norm2 + absSum = toScalarQ AbsSum dot = dotQ - norm1 = (:+ 0) . sumElements . fst . fromComplex . vectorMapQ Abs - normInf = (:+ 0) . maxElement . fst . fromComplex . vectorMapQ Abs + norm1 = sumElements . fst . fromComplex . vectorMapQ Abs + normInf = maxElement . fst . fromComplex . vectorMapQ Abs instance Vectors Vector (Complex Double) where - norm2 = (:+ 0) . toScalarC Norm2 - absSum = (:+ 0) . toScalarC AbsSum + norm2 = toScalarC Norm2 + absSum = toScalarC AbsSum dot = dotC - norm1 = (:+ 0) . sumElements . fst . fromComplex . vectorMapC Abs - normInf = (:+ 0) . maxElement . fst . fromComplex . vectorMapC Abs + norm1 = sumElements . fst . fromComplex . vectorMapC Abs + normInf = maxElement . fst . fromComplex . vectorMapC Abs ---------------------------------------------------- diff --git a/lib/Numeric/LinearAlgebra/Algorithms.hs b/lib/Numeric/LinearAlgebra/Algorithms.hs index fa6c475..cf86904 100644 --- a/lib/Numeric/LinearAlgebra/Algorithms.hs +++ b/lib/Numeric/LinearAlgebra/Algorithms.hs @@ -645,9 +645,9 @@ instance Normed (Vector Double) where pnorm Frobenius = norm2 instance Normed (Vector (Complex Double)) where - pnorm PNorm1 = realPart . norm1 - pnorm PNorm2 = realPart . norm2 - pnorm Infinity = realPart . normInf + pnorm PNorm1 = norm1 + pnorm PNorm2 = norm2 + pnorm Infinity = normInf pnorm Frobenius = pnorm PNorm2 instance Normed (Vector Float) where @@ -657,9 +657,9 @@ instance Normed (Vector Float) where pnorm Frobenius = pnorm PNorm2 instance Normed (Vector (Complex Float)) where - pnorm PNorm1 = realToFrac . realPart . norm1 - pnorm PNorm2 = realToFrac . realPart . norm2 - pnorm Infinity = realToFrac . realPart . normInf + pnorm PNorm1 = realToFrac . norm1 + pnorm PNorm2 = realToFrac . norm2 + pnorm Infinity = realToFrac . normInf pnorm Frobenius = pnorm PNorm2 diff --git a/lib/Numeric/LinearAlgebra/Tests.hs b/lib/Numeric/LinearAlgebra/Tests.hs index 5b42226..0b4e3bf 100644 --- a/lib/Numeric/LinearAlgebra/Tests.hs +++ b/lib/Numeric/LinearAlgebra/Tests.hs @@ -240,7 +240,7 @@ normsVTest = TestList [ ] where v = fromList [1,-2,3:+4] :: Vector (Complex Double) x = fromList [1,2,-3] :: Vector Double norm2PropR a = norm2 a =~= sqrt (dot a a) - norm2PropC a = norm2 a =~= sqrt (dot a (conj a)) + norm2PropC a = norm2 a =~= realPart (sqrt (dot a (conj a))) a =~= b = fromList [a] |~| fromList [b] normsMTest = TestList [ -- cgit v1.2.3