summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Internal/Matrix.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Data/Packed/Internal/Matrix.hs')
-rw-r--r--lib/Data/Packed/Internal/Matrix.hs11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs
index a220f1a..33c9324 100644
--- a/lib/Data/Packed/Internal/Matrix.hs
+++ b/lib/Data/Packed/Internal/Matrix.hs
@@ -135,11 +135,16 @@ type Mt t s = Int -> Int -> Ptr t -> s
135toLists :: (Element t) => Matrix t -> [[t]] 135toLists :: (Element t) => Matrix t -> [[t]]
136toLists m = partit (cols m) . toList . flatten $ m 136toLists m = partit (cols m) . toList . flatten $ m
137 137
138-- | creates a Matrix from a list of vectors 138-- | Create a matrix from a list of vectors.
139-- All vectors must have the same dimension,
140-- or dimension 1, which is are automatically expanded.
139fromRows :: Element t => [Vector t] -> Matrix t 141fromRows :: Element t => [Vector t] -> Matrix t
140fromRows vs = case common dim vs of 142fromRows vs = case compatdim (map dim vs) of
141 Nothing -> error "fromRows applied to [] or to vectors with different sizes" 143 Nothing -> error "fromRows applied to [] or to vectors with different sizes"
142 Just c -> reshape c (join vs) 144 Just c -> reshape c . join . map (adapt c) $ vs
145 where
146 adapt c v | dim v == c = v
147 | otherwise = constantD (v@>0) c
143 148
144-- | extracts the rows of a matrix as a list of vectors 149-- | extracts the rows of a matrix as a list of vectors
145toRows :: Element t => Matrix t -> [Vector t] 150toRows :: Element t => Matrix t -> [Vector t]