let (Mat rows) = diagonal matrix
in
element_sum $ V.map V.head rows
+
+
+-- | Zip together two column matrices.
+--
+-- Examples:
+--
+-- >>> let m1 = fromList [[1],[1],[1]] :: Col3 Int
+-- >>> let m2 = fromList [[1],[2],[3]] :: Col3 Int
+-- >>> zipcol m1 m2
+-- (((1,1)),((1,2)),((1,3)))
+--
+zipcol :: Arity m => Col m a -> Col m a -> Col m (a,a)
+zipcol c1 c2 =
+ construct lambda
+ where
+ lambda i j = (c1 !!! (i,j), c2 !!! (i,j))
+
+
+-- | Map a function over a matrix of any dimensions.
+--
+-- Examples:
+--
+-- >>> let m = fromList [[1,2],[3,4]] :: Mat2 Int
+-- >>> matmap (^2) m
+-- ((1,4),(9,16))
+--
+matmap :: (a -> b) -> Mat m n a -> Mat m n b
+matmap f (Mat rows) =
+ Mat $ V.map g rows
+ where
+ g = V.map f