summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2015-05-26 20:17:07 +0200
committerAlberto Ruiz <aruiz@um.es>2015-05-26 20:17:07 +0200
commit6827aa04b1c21b08875c58d38de5d90195aefb46 (patch)
treeb4919b1a79988e155000c73a588b6d9b4bf112fd /packages
parent7df149d9a3381aa609ffc36c9b14d87fdcfa5f20 (diff)
general sortVector, sortIndex
Diffstat (limited to 'packages')
-rw-r--r--packages/base/src/Data/Packed/Internal/Matrix.hs40
-rw-r--r--packages/base/src/Data/Packed/Numeric.hs12
-rw-r--r--packages/base/src/Numeric/Vectorized.hs21
3 files changed, 57 insertions, 16 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
270instance Element Float where 272instance 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
275instance Element Double where 279instance 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
280instance Element (Complex Float) where 286instance 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
285instance Element (Complex Double) where 293instance 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
290instance Element (CInt) where 300instance 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
466foreign import ccall unsafe "extractI" c_extractI 477foreign 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
482sortG f v = unsafePerformIO $ do
483 r <- createVector (dim v)
484 app2 f vec v vec r "sortG"
485 return r
486
487sortIdxD = sortG c_sort_indexD
488sortIdxF = sortG c_sort_indexF
489sortIdxI = sortG c_sort_indexI
490
491sortValD = sortG c_sort_valD
492sortValF = sortG c_sort_valF
493sortValI = sortG c_sort_valI
494
495foreign import ccall unsafe "sort_indexD" c_sort_indexD :: CV Double (CV CInt (IO CInt))
496foreign import ccall unsafe "sort_indexF" c_sort_indexF :: CV Float (CV CInt (IO CInt))
497foreign import ccall unsafe "sort_indexI" c_sort_indexI :: CV CInt (CV CInt (IO CInt))
498
499foreign import ccall unsafe "sort_valuesD" c_sort_valD :: CV Double (CV Double (IO CInt))
500foreign import ccall unsafe "sort_valuesF" c_sort_valF :: CV Float (CV Float (IO CInt))
501foreign 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
299instance Numeric (Complex Double) 299instance Numeric (Complex Double)
300instance Numeric Float 300instance Numeric Float
301instance Numeric (Complex Float) 301instance Numeric (Complex Float)
302instance Numeric CInt 302instance Numeric I
303
304--------------------------------------------------------------------------------
305
306sortVector :: (Ord t, Element t) => Vector t -> Vector t
307sortVector = sortV
308
309sortIndex :: (Ord t, Element t) => Vector t -> Vector I
310sortIndex = sortI
303 311
304 312
diff --git a/packages/base/src/Numeric/Vectorized.hs b/packages/base/src/Numeric/Vectorized.hs
index d0ff562..589cb49 100644
--- a/packages/base/src/Numeric/Vectorized.hs
+++ b/packages/base/src/Numeric/Vectorized.hs
@@ -19,8 +19,10 @@ module Numeric.Vectorized (
19 FunCodeVV(..), vectorZipR, vectorZipC, vectorZipF, vectorZipQ, vectorZipI, 19 FunCodeVV(..), vectorZipR, vectorZipC, vectorZipF, vectorZipQ, vectorZipI,
20 vectorScan, saveMatrix, 20 vectorScan, saveMatrix,
21 Seed, RandDist(..), randomVector, 21 Seed, RandDist(..), randomVector,
22 sortVector, roundVector, 22 roundVector,
23 range 23 range,
24-- compareD, compareF, compareI,
25-- chooseD, chooseF, chooseI
24) where 26) where
25 27
26import Data.Packed.Internal.Common 28import Data.Packed.Internal.Common
@@ -374,15 +376,6 @@ foreign import ccall unsafe "random_vector" c_random_vector :: CInt -> CInt -> T
374 376
375-------------------------------------------------------------------------------- 377--------------------------------------------------------------------------------
376 378
377sortVector v = unsafePerformIO $ do
378 r <- createVector (dim v)
379 app2 c_sort_values vec v vec r "sortVector"
380 return r
381
382foreign import ccall unsafe "sort_values" c_sort_values :: TVV
383
384--------------------------------------------------------------------------------
385
386roundVector v = unsafePerformIO $ do 379roundVector v = unsafePerformIO $ do
387 r <- createVector (dim v) 380 r <- createVector (dim v)
388 app2 c_round_vector vec v vec r "roundVector" 381 app2 c_round_vector vec v vec r "roundVector"
@@ -392,7 +385,11 @@ foreign import ccall unsafe "round_vector" c_round_vector :: TVV
392 385
393-------------------------------------------------------------------------------- 386--------------------------------------------------------------------------------
394 387
395range :: Int -> Idxs 388-- |
389-- >>> range 5
390-- fromList [0,1,2,3,4]
391--
392range :: Int -> Vector I
396range n = unsafePerformIO $ do 393range n = unsafePerformIO $ do
397 r <- createVector n 394 r <- createVector n
398 app1 c_range_vector vec r "range" 395 app1 c_range_vector vec r "range"