From c210311be639e8774dca25a332542d6b64ce3ca3 Mon Sep 17 00:00:00 2001 From: Tracy Wadleigh Date: Fri, 24 Apr 2009 13:58:33 +0000 Subject: More defined list-to-V/M operators: (|>|), (>|<). Provides analogs of the (|>) and (><) operators that first apply an appropriate 'take' to the given lists so that they may be safely used on lists that are too long (or infinite) -- a feature I find particularly useful from the interactive prompt. As these operators are more defined, I would ask the package maintainer to consider, rather than adding (|>|) and (>|<), just updating the definitions of (|>) and (><) with the new semantics. --- lib/Data/Packed/Matrix.hs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'lib/Data/Packed/Matrix.hs') 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 @@ module Data.Packed.Matrix ( Element, Matrix,rows,cols, - (><), + (><), (>|<), trans, reshape, flatten, fromLists, toLists, @@ -126,6 +126,25 @@ r >< c = f where ++show (dim v) ++" in ("++show r++"><"++show c++")" where v = fromList l +{- | Like '(><)', but explicitly truncates the list, so that it can +safely be used with lists that are too long (like infinite lists). + +Example: + +@\> (2>|<3)[1..] +(2><3) + [ 1.0, 2.0, 3.0 + , 4.0, 5.0, 6.0 ]@ + +Effectively, a more defined version of '(><)'. +-} +(>|<) :: (Element a) => Int -> Int -> [a] -> Matrix a +r >|< c = f where + f l | dim v == r*c = matrixFromVector RowMajor c v + | otherwise = error $ "inconsistent list size = " + ++show (dim v) ++" in ("++show r++"><"++show c++")" + where v = fromList $ take (r*c) l + ---------------------------------------------------------------- -- | Creates a matrix with the first n rows of another matrix -- cgit v1.2.3