diff options
Diffstat (limited to 'lib/Data')
-rw-r--r-- | lib/Data/Packed/Internal/Vector.hs | 22 | ||||
-rw-r--r-- | lib/Data/Packed/Matrix.hs | 16 | ||||
-rw-r--r-- | lib/Data/Packed/Vector.hs | 2 |
3 files changed, 14 insertions, 26 deletions
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 | |||
91 | toList :: Storable a => Vector a -> [a] | 91 | toList :: Storable a => Vector a -> [a] |
92 | toList v = safeRead v $ peekArray (dim v) | 92 | toList 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 |
96 | infixl 9 |> | 96 | be used, for instance, with infinite lists. |
97 | n |> 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 | ||
101 | It 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 |
104 | infixl 9 |>| | 101 | infixl 9 |> |
105 | n |>| l = if length l' == n then | 102 | n |> 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 @@ | |||
16 | module Data.Packed.Matrix ( | 16 | module 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 | ||
119 | This is the format produced by the instances of Show (Matrix a), which | 119 | This is the format produced by the instances of Show (Matrix a), which |
120 | can also be used for input. | 120 | can also be used for input. |
121 | -} | ||
122 | (><) :: (Element a) => Int -> Int -> [a] -> Matrix a | ||
123 | r >< 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 | 122 | The input list is explicitly truncated, so that it can |
130 | safely be used with lists that are too long (like infinite lists). | 123 | safely be used with lists that are too long (like infinite lists). |
131 | 124 | ||
132 | Example: | 125 | Example: |
@@ -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 | ||
139 | Effectively, a more defined version of '(><)'. | ||
140 | -} | 132 | -} |
141 | (>|<) :: (Element a) => Int -> Int -> [a] -> Matrix a | 133 | (><) :: (Element a) => Int -> Int -> [a] -> Matrix a |
142 | r >|< c = f where | 134 | r >< 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 | ||
15 | module Data.Packed.Vector ( | 15 | module 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, |