summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Internal
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Data/Packed/Internal')
-rw-r--r--lib/Data/Packed/Internal/Matrix.hs23
-rw-r--r--lib/Data/Packed/Internal/Vector.hs26
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)
139fromList [1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0]
140
141-}
139flatten :: Element t => Matrix t -> Vector t 142flatten :: Element t => Matrix t -> Vector t
140flatten = xdat . cmat 143flatten = xdat . cmat
141 144
145{-
142type Mt t s = Int -> Int -> Ptr t -> s 146type Mt t s = Int -> Int -> Ptr t -> s
143-- not yet admitted by my haddock version 147
144-- infixr 6 ::> 148infixr 6 ::>
145-- type t ::> s = Mt t s 149type t ::> s = Mt t s
150-}
146 151
147-- | the inverse of 'Data.Packed.Matrix.fromLists' 152-- | the inverse of 'Data.Packed.Matrix.fromLists'
148toLists :: (Element t) => Matrix t -> [[t]] 153toLists :: (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@
208where r is the desired number of rows.) 213where 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-}
217reshape :: Storable t => Int -> Vector t -> Matrix t 222reshape :: 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-}
120toList :: Storable a => Vector a -> [a] 120toList :: Storable a => Vector a -> [a]
121toList v = safeRead v $ peekArray (dim v) 121toList 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..]
128fromList [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
128infixl 9 |> 132infixl 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])
1633 |> [3.0,4.0,5.0]@ 167fromList [3.0,4.0,5.0]
164 168
165-} 169-}
166subVector :: Storable t => Int -- ^ index of the starting element 170subVector :: 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
1767.0@ 1807.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]
1878 |> [1.0,2.0,3.0,4.0,5.0,1.0,1.0,1.0]@ 191fromList [1.0,2.0,3.0,4.0,5.0,1.0,1.0,1.0]
188 192
189-} 193-}
190vjoin :: Storable t => [Vector t] -> Vector t 194vjoin :: 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-}
212takesV :: Storable t => [Int] -> Vector t -> [Vector t] 216takesV :: Storable t => [Int] -> Vector t -> [Vector t]