)
import qualified Data.Vector.Fixed as V (
and,
- foldl,
fromList,
head,
length,
toList,
zipWith
)
-import Data.Vector.Fixed.Boxed (Vec)
import Data.Vector.Fixed.Cont (Arity, arity)
import Linear.Vector
import Normed
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:
--
--
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