-- | Convert a matrix to a nested list.
toList :: (V.Vector v (Vn w a), V.Vector w a) => Mat v w a -> [[a]]
-toList m = Prelude.map FV.toList (FV.toList m)
+toList m = Prelude.map V.toList (V.toList m)
-- | Create a matrix from a nested list.
fromList :: (V.Vector v (Vn w a), V.Vector w a) => [[a]] -> Mat v w a
-fromList vs = FV.fromList $ Prelude.map FV.fromList vs
+fromList vs = V.fromList $ Prelude.map V.fromList vs
-- | Unsafe indexing.
(!) :: (V.Vector v (Vn w a), V.Vector w a) => Mat v w a -> (Int, Int) -> a
-(!) m (i, j) = (row m i) FV.! j
+(!) m (i, j) = (row m i) V.! j
-- | Safe indexing.
(!?) :: (V.Vector v (Vn w a), V.Vector w a) => Mat v w a
-> Maybe a
(!?) m (i, j)
| i < 0 || j < 0 = Nothing
- | i > FV.length m = Nothing
- | otherwise = if j > FV.length (row m j)
+ | i > V.length m = Nothing
+ | otherwise = if j > V.length (row m j)
then Nothing
- else Just $ (row m j) FV.! j
+ else Just $ (row m j) V.! j
--- | The number of rows in the matrix. Implementation stolen from
--- Data.Vector.Fixed.Length.
+-- | The number of rows in the matrix.
nrows :: forall v w a. (V.Vector v (Vn w a), V.Vector w a) => Mat v w a -> Int
-nrows _ = arity (undefined :: V.Dim v)
+nrows = V.length
-- | The number of columns in the first row of the
--- matrix. Implementation stolen from
+-- matrix. Implementation stolen from Data.Vector.Fixed.length.
ncols :: forall v w a. (V.Vector v (Vn w a), V.Vector w a) => Mat v w a -> Int
ncols _ = arity (undefined :: V.Dim w)
row :: (V.Vector v (Vn w a), V.Vector w a) => Mat v w a
-> Int
-> Vn w a
-row m i = m FV.! i
+row m i = m V.! i
-- | Return the @j@th column of @m@. Unsafe.
-> Int
-> Vn v a
column m j =
- FV.map (element j) m
+ V.map (element j) m
where
- element = flip (FV.!)
+ element = flip (V.!)
-- | Transose @m@; switch it's columns and its rows. This is a dirty
V.Vector w a)
=> Mat v w a
-> Mat w v a
-transpose m = FV.fromList column_list
+transpose m = V.fromList column_list
where
column_list = [ column m i | i <- [0..(ncols m)-1] ]
construct lambda = rows
where
-- The arity trick is used in Data.Vector.Fixed.length.
- imax = (arity (undefined :: V.Dim w)) - 1
+ imax = (arity (undefined :: V.Dim v)) - 1
jmax = (arity (undefined :: V.Dim w)) - 1
- row' i = FV.fromList [ lambda i j | j <- [0..jmax] ]
- rows = FV.fromList [ row' i | i <- [0..imax] ]
+ row' i = V.fromList [ lambda i j | j <- [0..jmax] ]
+ rows = V.fromList [ row' i | i <- [0..imax] ]