diff options
author | Alberto Ruiz <aruiz@um.es> | 2015-05-26 20:17:07 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2015-05-26 20:17:07 +0200 |
commit | 6827aa04b1c21b08875c58d38de5d90195aefb46 (patch) | |
tree | b4919b1a79988e155000c73a588b6d9b4bf112fd /packages/base/src/Data | |
parent | 7df149d9a3381aa609ffc36c9b14d87fdcfa5f20 (diff) |
general sortVector, sortIndex
Diffstat (limited to 'packages/base/src/Data')
-rw-r--r-- | packages/base/src/Data/Packed/Internal/Matrix.hs | 40 | ||||
-rw-r--r-- | packages/base/src/Data/Packed/Numeric.hs | 12 |
2 files changed, 48 insertions, 4 deletions
diff --git a/packages/base/src/Data/Packed/Internal/Matrix.hs b/packages/base/src/Data/Packed/Internal/Matrix.hs index 76d2204..1679ea6 100644 --- a/packages/base/src/Data/Packed/Internal/Matrix.hs +++ b/packages/base/src/Data/Packed/Internal/Matrix.hs | |||
@@ -265,33 +265,44 @@ class (Storable a) => Element a where | |||
265 | transdata = transdataP -- transdata' | 265 | transdata = transdataP -- transdata' |
266 | constantD :: a -> Int -> Vector a | 266 | constantD :: a -> Int -> Vector a |
267 | constantD = constantP -- constant' | 267 | constantD = constantP -- constant' |
268 | extractR :: Matrix a -> CInt -> Idxs -> CInt -> Idxs -> Matrix a | 268 | extractR :: Matrix a -> CInt -> Vector CInt -> CInt -> Vector CInt -> Matrix a |
269 | sortI :: Ord a => Vector a -> Vector CInt | ||
270 | sortV :: Ord a => Vector a -> Vector a | ||
269 | 271 | ||
270 | instance Element Float where | 272 | instance Element Float where |
271 | transdata = transdataAux ctransF | 273 | transdata = transdataAux ctransF |
272 | constantD = constantAux cconstantF | 274 | constantD = constantAux cconstantF |
273 | extractR = extractAux c_extractF | 275 | extractR = extractAux c_extractF |
276 | sortI = sortIdxF | ||
277 | sortV = sortValF | ||
274 | 278 | ||
275 | instance Element Double where | 279 | instance Element Double where |
276 | transdata = transdataAux ctransR | 280 | transdata = transdataAux ctransR |
277 | constantD = constantAux cconstantR | 281 | constantD = constantAux cconstantR |
278 | extractR = extractAux c_extractD | 282 | extractR = extractAux c_extractD |
283 | sortI = sortIdxD | ||
284 | sortV = sortValD | ||
279 | 285 | ||
280 | instance Element (Complex Float) where | 286 | instance Element (Complex Float) where |
281 | transdata = transdataAux ctransQ | 287 | transdata = transdataAux ctransQ |
282 | constantD = constantAux cconstantQ | 288 | constantD = constantAux cconstantQ |
283 | extractR = extractAux c_extractQ | 289 | extractR = extractAux c_extractQ |
290 | sortI = undefined | ||
291 | sortV = undefined | ||
284 | 292 | ||
285 | instance Element (Complex Double) where | 293 | instance Element (Complex Double) where |
286 | transdata = transdataAux ctransC | 294 | transdata = transdataAux ctransC |
287 | constantD = constantAux cconstantC | 295 | constantD = constantAux cconstantC |
288 | extractR = extractAux c_extractC | 296 | extractR = extractAux c_extractC |
297 | sortI = undefined | ||
298 | sortV = undefined | ||
289 | 299 | ||
290 | instance Element (CInt) where | 300 | instance Element (CInt) where |
291 | transdata = transdataAux ctransI | 301 | transdata = transdataAux ctransI |
292 | constantD = constantAux cconstantI | 302 | constantD = constantAux cconstantI |
293 | extractR = extractAux c_extractI | 303 | extractR = extractAux c_extractI |
294 | 304 | sortI = sortIdxI | |
305 | sortV = sortValI | ||
295 | 306 | ||
296 | ------------------------------------------------------------------- | 307 | ------------------------------------------------------------------- |
297 | 308 | ||
@@ -466,3 +477,28 @@ foreign import ccall unsafe "extractQ" c_extractQ | |||
466 | foreign import ccall unsafe "extractI" c_extractI | 477 | foreign import ccall unsafe "extractI" c_extractI |
467 | :: CInt -> CInt -> CInt -> CIdxs (CIdxs (CM CInt (CM CInt (IO CInt)))) | 478 | :: CInt -> CInt -> CInt -> CIdxs (CIdxs (CM CInt (CM CInt (IO CInt)))) |
468 | 479 | ||
480 | -------------------------------------------------------------------------------- | ||
481 | |||
482 | sortG f v = unsafePerformIO $ do | ||
483 | r <- createVector (dim v) | ||
484 | app2 f vec v vec r "sortG" | ||
485 | return r | ||
486 | |||
487 | sortIdxD = sortG c_sort_indexD | ||
488 | sortIdxF = sortG c_sort_indexF | ||
489 | sortIdxI = sortG c_sort_indexI | ||
490 | |||
491 | sortValD = sortG c_sort_valD | ||
492 | sortValF = sortG c_sort_valF | ||
493 | sortValI = sortG c_sort_valI | ||
494 | |||
495 | foreign import ccall unsafe "sort_indexD" c_sort_indexD :: CV Double (CV CInt (IO CInt)) | ||
496 | foreign import ccall unsafe "sort_indexF" c_sort_indexF :: CV Float (CV CInt (IO CInt)) | ||
497 | foreign import ccall unsafe "sort_indexI" c_sort_indexI :: CV CInt (CV CInt (IO CInt)) | ||
498 | |||
499 | foreign import ccall unsafe "sort_valuesD" c_sort_valD :: CV Double (CV Double (IO CInt)) | ||
500 | foreign import ccall unsafe "sort_valuesF" c_sort_valF :: CV Float (CV Float (IO CInt)) | ||
501 | foreign import ccall unsafe "sort_valuesI" c_sort_valI :: CV CInt (CV CInt (IO CInt)) | ||
502 | |||
503 | -------------------------------------------------------------------------------- | ||
504 | |||
diff --git a/packages/base/src/Data/Packed/Numeric.hs b/packages/base/src/Data/Packed/Numeric.hs index 2821eae..cb449a9 100644 --- a/packages/base/src/Data/Packed/Numeric.hs +++ b/packages/base/src/Data/Packed/Numeric.hs | |||
@@ -52,7 +52,7 @@ module Data.Packed.Numeric ( | |||
52 | uniformSample, | 52 | uniformSample, |
53 | meanCov, | 53 | meanCov, |
54 | -- * sorting | 54 | -- * sorting |
55 | sortVector, | 55 | sortVector, sortIndex, |
56 | -- * Element conversion | 56 | -- * Element conversion |
57 | Convert(..), | 57 | Convert(..), |
58 | Complexable(), | 58 | Complexable(), |
@@ -299,6 +299,14 @@ instance Numeric Double | |||
299 | instance Numeric (Complex Double) | 299 | instance Numeric (Complex Double) |
300 | instance Numeric Float | 300 | instance Numeric Float |
301 | instance Numeric (Complex Float) | 301 | instance Numeric (Complex Float) |
302 | instance Numeric CInt | 302 | instance Numeric I |
303 | |||
304 | -------------------------------------------------------------------------------- | ||
305 | |||
306 | sortVector :: (Ord t, Element t) => Vector t -> Vector t | ||
307 | sortVector = sortV | ||
308 | |||
309 | sortIndex :: (Ord t, Element t) => Vector t -> Vector I | ||
310 | sortIndex = sortI | ||
303 | 311 | ||
304 | 312 | ||