summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Matrix.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Data/Packed/Matrix.hs')
-rw-r--r--lib/Data/Packed/Matrix.hs21
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs
index 4fd61a1..5a73c06 100644
--- a/lib/Data/Packed/Matrix.hs
+++ b/lib/Data/Packed/Matrix.hs
@@ -16,7 +16,7 @@
16module Data.Packed.Matrix ( 16module Data.Packed.Matrix (
17 Element, 17 Element,
18 Matrix,rows,cols, 18 Matrix,rows,cols,
19 (><), 19 (><), (>|<),
20 trans, 20 trans,
21 reshape, flatten, 21 reshape, flatten,
22 fromLists, toLists, 22 fromLists, toLists,
@@ -126,6 +126,25 @@ r >< c = f where
126 ++show (dim v) ++" in ("++show r++"><"++show c++")" 126 ++show (dim v) ++" in ("++show r++"><"++show c++")"
127 where v = fromList l 127 where v = fromList l
128 128
129{- | Like '(><)', but explicitly truncates the list, so that it can
130safely be used with lists that are too long (like infinite lists).
131
132Example:
133
134@\> (2>|<3)[1..]
135(2><3)
136 [ 1.0, 2.0, 3.0
137 , 4.0, 5.0, 6.0 ]@
138
139Effectively, a more defined version of '(><)'.
140-}
141(>|<) :: (Element a) => Int -> Int -> [a] -> Matrix a
142r >|< c = f where
143 f l | dim v == r*c = matrixFromVector RowMajor c v
144 | otherwise = error $ "inconsistent list size = "
145 ++show (dim v) ++" in ("++show r++"><"++show c++")"
146 where v = fromList $ take (r*c) l
147
129---------------------------------------------------------------- 148----------------------------------------------------------------
130 149
131-- | Creates a matrix with the first n rows of another matrix 150-- | Creates a matrix with the first n rows of another matrix