diff options
Diffstat (limited to 'lib/Data/Packed/Internal/Matrix.hs')
-rw-r--r-- | lib/Data/Packed/Internal/Matrix.hs | 11 |
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 | |||
135 | toLists :: (Element t) => Matrix t -> [[t]] | 135 | toLists :: (Element t) => Matrix t -> [[t]] |
136 | toLists m = partit (cols m) . toList . flatten $ m | 136 | toLists 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. | ||
139 | fromRows :: Element t => [Vector t] -> Matrix t | 141 | fromRows :: Element t => [Vector t] -> Matrix t |
140 | fromRows vs = case common dim vs of | 142 | fromRows 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 |
145 | toRows :: Element t => Matrix t -> [Vector t] | 150 | toRows :: Element t => Matrix t -> [Vector t] |