]> gitweb.michael.orlitzky.com - numerical-analysis.git/blobdiff - src/Linear/Matrix.hs
Switch Linear.Vector to the numeric prelude and add the element_sum function to it.
[numerical-analysis.git] / src / Linear / Matrix.hs
index 66b22f9f9d964e843e596678c0f7ebe34e8e9a22..69a74b50eeacf7ea944c790d3858dd0cba12c266 100644 (file)
@@ -35,7 +35,6 @@ import Data.Vector.Fixed (
   )
 import qualified Data.Vector.Fixed as V (
   and,
-  foldl,
   fromList,
   head,
   length,
@@ -45,7 +44,6 @@ import qualified Data.Vector.Fixed as V (
   toList,
   zipWith
   )
-import Data.Vector.Fixed.Boxed (Vec)
 import Data.Vector.Fixed.Cont (Arity, arity)
 import Linear.Vector
 import Normed
@@ -430,8 +428,8 @@ instance (Algebraic.C a,
           ToRational.C a,
           Arity m)
          => Normed (Mat (S m) N1 a) where
-  -- | Generic p-norms. The usual norm in R^n is (norm_p 2). We treat
-  --   all matrices as big vectors.
+  -- | Generic p-norms for vectors in R^n that are represented as nx1
+  --   matrices.
   --
   --   Examples:
   --
@@ -475,15 +473,10 @@ instance (Algebraic.C a,
 --
 frobenius_norm :: (Algebraic.C a, Ring.C a) => Mat m n a -> a
 frobenius_norm (Mat rows) =
-  sqrt $ vsum $ V.map row_sum rows
+  sqrt $ element_sum $ V.map row_sum rows
   where
-    -- | The \"sum\" function defined in fixed-vector requires a 'Num'
-    --   constraint whereas we want to use the classes from
-    --   numeric-prelude.
-    vsum = V.foldl (+) (fromInteger 0)
-
     -- | Square and add up the entries of a row.
-    row_sum = vsum . V.map (^2)
+    row_sum = element_sum . V.map (^2)
 
 
 -- Vector helpers. We want it to be easy to create low-dimension