summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README4
-rw-r--r--lib/Data/Packed/Internal/Vector.hs22
-rw-r--r--lib/Data/Packed/Matrix.hs16
-rw-r--r--lib/Data/Packed/Vector.hs2
4 files changed, 18 insertions, 26 deletions
diff --git a/README b/README
index 7b2c65a..50b492e 100644
--- a/README
+++ b/README
@@ -111,3 +111,7 @@ in the Haskell mailing lists for their help.
111- Daniel Schüssler added compatibility with QuickCheck 2 as well 111- Daniel Schüssler added compatibility with QuickCheck 2 as well
112 as QuickCheck 1 using the C preprocessor. He also added some 112 as QuickCheck 1 using the C preprocessor. He also added some
113 implementations for the new "shrink" method of class Arbitrary. 113 implementations for the new "shrink" method of class Arbitrary.
114
115- Tracy Wadleigh improved the definitions of (|>) and (><), which now
116 apply an appropriate 'take' to the given lists so that they may be
117 safely used on lists that are too long (or infinite).
diff --git a/lib/Data/Packed/Internal/Vector.hs b/lib/Data/Packed/Internal/Vector.hs
index 0e6b3f4..fc8a6be 100644
--- a/lib/Data/Packed/Internal/Vector.hs
+++ b/lib/Data/Packed/Internal/Vector.hs
@@ -91,21 +91,17 @@ inlinePerformIO (IO m) = case m realWorld# of (# _, r #) -> r
91toList :: Storable a => Vector a -> [a] 91toList :: Storable a => Vector a -> [a]
92toList v = safeRead v $ peekArray (dim v) 92toList v = safeRead v $ peekArray (dim v)
93 93
94-- | an alternative to 'fromList' with explicit dimension, used also in the instances for Show (Vector a). 94{- | An alternative to 'fromList' with explicit dimension. The input
95(|>) :: (Storable a) => Int -> [a] -> Vector a 95 list is explicitly truncated if it is too long, so it may safely
96infixl 9 |> 96 be used, for instance, with infinite lists.
97n |> l = if length l == n then fromList l else error "|> with wrong size"
98
99{- | Like '(|>)', but explicitly truncates the list, if it is too long.
100 97
101It may safely be used, for instance, with infinite lists. 98 This is the format used in the instances for Show (Vector a).
102-} 99-}
103(|>|) :: (Storable a) => Int -> [a] -> Vector a 100(|>) :: (Storable a) => Int -> [a] -> Vector a
104infixl 9 |>| 101infixl 9 |>
105n |>| l = if length l' == n then 102n |> l = if length l' == n
106 fromList l' 103 then fromList l'
107 else 104 else error "list too short for |>"
108 error "|>|: list too short"
109 where l' = take n l 105 where l' = take n l
110 106
111 107
diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs
index 5a73c06..0b50d8a 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,
@@ -118,15 +118,8 @@ ident n = diag (constant 1 n)
118 118
119This is the format produced by the instances of Show (Matrix a), which 119This is the format produced by the instances of Show (Matrix a), which
120can also be used for input. 120can also be used for input.
121-}
122(><) :: (Element a) => Int -> Int -> [a] -> Matrix a
123r >< c = f where
124 f l | dim v == r*c = matrixFromVector RowMajor c v
125 | otherwise = error $ "inconsistent list size = "
126 ++show (dim v) ++" in ("++show r++"><"++show c++")"
127 where v = fromList l
128 121
129{- | Like '(><)', but explicitly truncates the list, so that it can 122The input list is explicitly truncated, so that it can
130safely be used with lists that are too long (like infinite lists). 123safely be used with lists that are too long (like infinite lists).
131 124
132Example: 125Example:
@@ -136,10 +129,9 @@ Example:
136 [ 1.0, 2.0, 3.0 129 [ 1.0, 2.0, 3.0
137 , 4.0, 5.0, 6.0 ]@ 130 , 4.0, 5.0, 6.0 ]@
138 131
139Effectively, a more defined version of '(><)'.
140-} 132-}
141(>|<) :: (Element a) => Int -> Int -> [a] -> Matrix a 133(><) :: (Element a) => Int -> Int -> [a] -> Matrix a
142r >|< c = f where 134r >< c = f where
143 f l | dim v == r*c = matrixFromVector RowMajor c v 135 f l | dim v == r*c = matrixFromVector RowMajor c v
144 | otherwise = error $ "inconsistent list size = " 136 | otherwise = error $ "inconsistent list size = "
145 ++show (dim v) ++" in ("++show r++"><"++show c++")" 137 ++show (dim v) ++" in ("++show r++"><"++show c++")"
diff --git a/lib/Data/Packed/Vector.hs b/lib/Data/Packed/Vector.hs
index ae30c27..e53d455 100644
--- a/lib/Data/Packed/Vector.hs
+++ b/lib/Data/Packed/Vector.hs
@@ -14,7 +14,7 @@
14 14
15module Data.Packed.Vector ( 15module Data.Packed.Vector (
16 Vector, 16 Vector,
17 fromList, (|>), (|>|), toList, 17 fromList, (|>), toList,
18 dim, (@>), 18 dim, (@>),
19 subVector, join, 19 subVector, join,
20 constant, linspace, 20 constant, linspace,