diff options
Diffstat (limited to 'packages/base/src')
-rw-r--r-- | packages/base/src/Data/Packed/Internal/Matrix.hs | 40 | ||||
-rw-r--r-- | packages/base/src/Data/Packed/Numeric.hs | 12 | ||||
-rw-r--r-- | packages/base/src/Numeric/Vectorized.hs | 21 |
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 | ||
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 | ||
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 | ||
26 | import Data.Packed.Internal.Common | 28 | import 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 | ||
377 | sortVector v = unsafePerformIO $ do | ||
378 | r <- createVector (dim v) | ||
379 | app2 c_sort_values vec v vec r "sortVector" | ||
380 | return r | ||
381 | |||
382 | foreign import ccall unsafe "sort_values" c_sort_values :: TVV | ||
383 | |||
384 | -------------------------------------------------------------------------------- | ||
385 | |||
386 | roundVector v = unsafePerformIO $ do | 379 | roundVector 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 | ||
395 | range :: Int -> Idxs | 388 | -- | |
389 | -- >>> range 5 | ||
390 | -- fromList [0,1,2,3,4] | ||
391 | -- | ||
392 | range :: Int -> Vector I | ||
396 | range n = unsafePerformIO $ do | 393 | range 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" |