fromList,
head,
ifoldl,
+ imap,
map,
maximum,
replicate,
row_function :: b -> Int -> Vec n a -> b
row_function rowinit idx r = V.ifoldl (g idx) rowinit r
+
+
+-- | Map a function over a matrix of any dimensions, passing the
+-- coordinates @i@ and @j@ to the function @f@.
+--
+-- Examples:
+--
+-- >>> let m = fromList [[1,2],[3,4]] :: Mat2 Int
+-- >>> imap2 (\i j _ -> i+j) m
+-- ((0,1),(1,2))
+--
+imap2 :: (Int -> Int -> a -> b) -> Mat m n a -> Mat m n b
+imap2 f (Mat rows) =
+ Mat $ V.imap g rows
+ where
+ g i = V.imap (f i)