diff options
Diffstat (limited to 'lib/Data/Packed/Internal')
-rw-r--r-- | lib/Data/Packed/Internal/Matrix.hs | 23 | ||||
-rw-r--r-- | lib/Data/Packed/Internal/Vector.hs | 26 |
2 files changed, 29 insertions, 20 deletions
diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs index 5e6e649..8709a00 100644 --- a/lib/Data/Packed/Internal/Matrix.hs +++ b/lib/Data/Packed/Internal/Matrix.hs | |||
@@ -132,17 +132,22 @@ mat a f = | |||
132 | let m g = do | 132 | let m g = do |
133 | g (fi (rows a)) (fi (cols a)) p | 133 | g (fi (rows a)) (fi (cols a)) p |
134 | f m | 134 | f m |
135 | -- | Creates a vector by concatenation of rows. If the matrix is ColumnMajor, this operation requires a transpose. | 135 | |
136 | -- | 136 | {- | Creates a vector by concatenation of rows. If the matrix is ColumnMajor, this operation requires a transpose. |
137 | -- @\> flatten ('ident' 3) | 137 | |
138 | -- 9 |> [1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0]@ | 138 | >>> flatten (ident 3) |
139 | fromList [1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0] | ||
140 | |||
141 | -} | ||
139 | flatten :: Element t => Matrix t -> Vector t | 142 | flatten :: Element t => Matrix t -> Vector t |
140 | flatten = xdat . cmat | 143 | flatten = xdat . cmat |
141 | 144 | ||
145 | {- | ||
142 | type Mt t s = Int -> Int -> Ptr t -> s | 146 | type Mt t s = Int -> Int -> Ptr t -> s |
143 | -- not yet admitted by my haddock version | 147 | |
144 | -- infixr 6 ::> | 148 | infixr 6 ::> |
145 | -- type t ::> s = Mt t s | 149 | type t ::> s = Mt t s |
150 | -} | ||
146 | 151 | ||
147 | -- | the inverse of 'Data.Packed.Matrix.fromLists' | 152 | -- | the inverse of 'Data.Packed.Matrix.fromLists' |
148 | toLists :: (Element t) => Matrix t -> [[t]] | 153 | toLists :: (Element t) => Matrix t -> [[t]] |
@@ -207,11 +212,11 @@ createMatrix ord r c = do | |||
207 | {- | Creates a matrix from a vector by grouping the elements in rows with the desired number of columns. (GNU-Octave groups by columns. To do it you can define @reshapeF r = trans . reshape r@ | 212 | {- | Creates a matrix from a vector by grouping the elements in rows with the desired number of columns. (GNU-Octave groups by columns. To do it you can define @reshapeF r = trans . reshape r@ |
208 | where r is the desired number of rows.) | 213 | where r is the desired number of rows.) |
209 | 214 | ||
210 | @\> reshape 4 ('fromList' [1..12]) | 215 | >>> reshape 4 (fromList [1..12]) |
211 | (3><4) | 216 | (3><4) |
212 | [ 1.0, 2.0, 3.0, 4.0 | 217 | [ 1.0, 2.0, 3.0, 4.0 |
213 | , 5.0, 6.0, 7.0, 8.0 | 218 | , 5.0, 6.0, 7.0, 8.0 |
214 | , 9.0, 10.0, 11.0, 12.0 ]@ | 219 | , 9.0, 10.0, 11.0, 12.0 ] |
215 | 220 | ||
216 | -} | 221 | -} |
217 | reshape :: Storable t => Int -> Vector t -> Matrix t | 222 | reshape :: Storable t => Int -> Vector t -> Matrix t |
diff --git a/lib/Data/Packed/Internal/Vector.hs b/lib/Data/Packed/Internal/Vector.hs index f0bd9aa..415c972 100644 --- a/lib/Data/Packed/Internal/Vector.hs +++ b/lib/Data/Packed/Internal/Vector.hs | |||
@@ -113,16 +113,20 @@ inlinePerformIO (IO m) = case m realWorld# of (# _, r #) -> r | |||
113 | 113 | ||
114 | {- | extracts the Vector elements to a list | 114 | {- | extracts the Vector elements to a list |
115 | 115 | ||
116 | @> toList (linspace 5 (1,10)) | 116 | >>> toList (linspace 5 (1,10)) |
117 | [1.0,3.25,5.5,7.75,10.0]@ | 117 | [1.0,3.25,5.5,7.75,10.0] |
118 | 118 | ||
119 | -} | 119 | -} |
120 | toList :: Storable a => Vector a -> [a] | 120 | toList :: Storable a => Vector a -> [a] |
121 | toList v = safeRead v $ peekArray (dim v) | 121 | toList v = safeRead v $ peekArray (dim v) |
122 | 122 | ||
123 | {- | An alternative to 'fromList' with explicit dimension. The input | 123 | {- | Create a vector from a list of elements and explicit dimension. The input |
124 | list is explicitly truncated if it is too long, so it may safely | 124 | list is explicitly truncated if it is too long, so it may safely |
125 | be used, for instance, with infinite lists. | 125 | be used, for instance, with infinite lists. |
126 | |||
127 | >>> 5 |> [1..] | ||
128 | fromList [1.0,2.0,3.0,4.0,5.0] | ||
129 | |||
126 | -} | 130 | -} |
127 | (|>) :: (Storable a) => Int -> [a] -> Vector a | 131 | (|>) :: (Storable a) => Int -> [a] -> Vector a |
128 | infixl 9 |> | 132 | infixl 9 |> |
@@ -159,8 +163,8 @@ at v n | |||
159 | 163 | ||
160 | {- | takes a number of consecutive elements from a Vector | 164 | {- | takes a number of consecutive elements from a Vector |
161 | 165 | ||
162 | @> subVector 2 3 (fromList [1..10]) | 166 | >>> subVector 2 3 (fromList [1..10]) |
163 | 3 |> [3.0,4.0,5.0]@ | 167 | fromList [3.0,4.0,5.0] |
164 | 168 | ||
165 | -} | 169 | -} |
166 | subVector :: Storable t => Int -- ^ index of the starting element | 170 | subVector :: Storable t => Int -- ^ index of the starting element |
@@ -172,8 +176,8 @@ subVector = Vector.slice | |||
172 | 176 | ||
173 | {- | Reads a vector position: | 177 | {- | Reads a vector position: |
174 | 178 | ||
175 | @> fromList [0..9] \@\> 7 | 179 | >>> fromList [0..9] @> 7 |
176 | 7.0@ | 180 | 7.0 |
177 | 181 | ||
178 | -} | 182 | -} |
179 | (@>) :: Storable t => Vector t -> Int -> t | 183 | (@>) :: Storable t => Vector t -> Int -> t |
@@ -183,8 +187,8 @@ infixl 9 @> | |||
183 | 187 | ||
184 | {- | concatenate a list of vectors | 188 | {- | concatenate a list of vectors |
185 | 189 | ||
186 | @> vjoin [fromList [1..5], constant 1 3] | 190 | >>> vjoin [fromList [1..5::Double], konst 1 3] |
187 | 8 |> [1.0,2.0,3.0,4.0,5.0,1.0,1.0,1.0]@ | 191 | fromList [1.0,2.0,3.0,4.0,5.0,1.0,1.0,1.0] |
188 | 192 | ||
189 | -} | 193 | -} |
190 | vjoin :: Storable t => [Vector t] -> Vector t | 194 | vjoin :: Storable t => [Vector t] -> Vector t |
@@ -205,8 +209,8 @@ vjoin as = unsafePerformIO $ do | |||
205 | 209 | ||
206 | {- | Extract consecutive subvectors of the given sizes. | 210 | {- | Extract consecutive subvectors of the given sizes. |
207 | 211 | ||
208 | @> takesV [3,4] (linspace 10 (1,10)) | 212 | >>> takesV [3,4] (linspace 10 (1,10::Double)) |
209 | [3 |> [1.0,2.0,3.0],4 |> [4.0,5.0,6.0,7.0]]@ | 213 | [fromList [1.0,2.0,3.0],fromList [4.0,5.0,6.0,7.0]] |
210 | 214 | ||
211 | -} | 215 | -} |
212 | takesV :: Storable t => [Int] -> Vector t -> [Vector t] | 216 | takesV :: Storable t => [Int] -> Vector t -> [Vector t] |