Skip to content

Commit 6d38305

Browse files
committed
Update Sparse Array documentation.
1 parent bb5100f commit 6d38305

File tree

3 files changed

+281
-21
lines changed

3 files changed

+281
-21
lines changed

src/ArrayFire/Data.hs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ join (fromIntegral -> n) arr1 arr2 = op2 arr1 arr2 (\p a b -> af_join p n a b)
324324
-- | Join many Arrays together along a specified dimension
325325
--
326326
-- *FIX ME*
327+
--
327328
-- >>> joinMany 0 [1,2,3]
328329
-- ArrayFire Array
329330
-- [3 1 1 1]
@@ -370,6 +371,7 @@ tile _ _ = error "impossible"
370371
-- | Reorders an Array according to newly specified dimensions
371372
--
372373
-- *FIX ME*
374+
--
373375
-- >>> reorder @Double (scalar 22.0) [5,5]
374376
-- ArrayFire Array
375377
-- [5 5 1 1]
@@ -511,23 +513,59 @@ upper a (fromIntegral . fromEnum -> b) =
511513
--
512514
select
513515
:: Array CBool
516+
-- ^ is the conditional array
514517
-> Array a
518+
-- ^ is the array containing elements from the true part of the condition
515519
-> Array a
520+
-- ^ is the array containing elements from the false part of the condition
516521
-> Array a
522+
-- ^ is the output containing elements of a when cond is true else elements from b
517523
select a b c = op3 a b c af_select
518524

525+
-- | Selects elements from two arrays based on the values of a binary conditional array.
526+
--
527+
-- <http://arrayfire.org/docs/group__data__func__select.htm#gab6886120d0bac4717276910e468bbe88>
528+
--
529+
-- >>> cond = vector @CBool 5 [1,0,1,0,1]
530+
-- >>> arr1 = vector @Double 5 (repeat 1)
531+
-- >>> x = 99
532+
-- >>> selectScalarR cond x arr1
533+
-- ArrayFire Array
534+
-- [5 1 1 1]
535+
-- 1.0000 99.0000 1.0000 99.0000 1.0000
536+
--
519537
selectScalarR
520-
:: Array a
538+
:: Array CBool
539+
-- ^ is the conditional array
521540
-> Array a
541+
-- ^ is the array containing elements from the true part of the condition
522542
-> Double
543+
-- ^ is a scalar assigned to out when cond is false
523544
-> Array a
545+
-- ^ the output containing elements of a when cond is true else elements from b
524546
selectScalarR a b c = op2 a b (\p w x -> af_select_scalar_r p w x c)
525547

548+
-- | Selects elements from two arrays based on the values of a binary conditional array.
549+
--
550+
-- [ArrayFire Docs](http://arrayfire.org/docs/group__data__func__select.htm#ga0ccdc05779f88cab5095bce987c2da9d)
551+
--
552+
-- >>> cond = vector @CBool 5 [1,0,1,0,1]
553+
-- >>> arr1 = vector @Double 5 (repeat 1)
554+
-- >>> x = 99
555+
-- >>> selectScalarL cond x arr1
556+
-- ArrayFire Array
557+
-- [5 1 1 1]
558+
-- 99.0000 1.0000 99.0000 1.0000 99.0000
559+
--
526560
selectScalarL
527-
:: Array a
561+
:: Array CBool
562+
-- ^ the conditional array
528563
-> Double
564+
-- ^ a scalar assigned to out when cond is true
529565
-> Array a
566+
-- ^ the array containing elements from the false part of the condition
530567
-> Array a
568+
-- ^ is the output containing elements of a when cond is true else elements from b
531569
selectScalarL a n b = op2 a b (\p w x -> af_select_scalar_l p w n x)
532570

533571
-- af_err af_replace(af_array a, const af_array cond, const af_array b);

src/ArrayFire/FFI.hs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import ArrayFire.Internal.Types
2222

2323
import Control.Exception
2424
import Control.Monad
25+
import Data.Int
2526
import Foreign.ForeignPtr
2627
import Foreign.Storable
2728
import Foreign.Ptr
@@ -48,6 +49,25 @@ op3 (Array fptr1) (Array fptr2) (Array fptr3) op =
4849
fptr <- newForeignPtr af_release_array_finalizer ptr
4950
pure (Array fptr)
5051

52+
op3Int
53+
:: Array a
54+
-> Array Int32
55+
-> Array Int32
56+
-> (Ptr AFArray -> AFArray -> AFArray -> AFArray -> IO AFErr)
57+
-> Array a
58+
{-# NOINLINE op3Int #-}
59+
op3Int (Array fptr1) (Array fptr2) (Array fptr3) op =
60+
unsafePerformIO $ do
61+
withForeignPtr fptr1 $ \ptr1 ->
62+
withForeignPtr fptr2 $ \ptr2 -> do
63+
withForeignPtr fptr3 $ \ptr3 -> do
64+
ptr <-
65+
alloca $ \ptrInput -> do
66+
throwAFError =<< op ptrInput ptr1 ptr2 ptr3
67+
peek ptrInput
68+
fptr <- newForeignPtr af_release_array_finalizer ptr
69+
pure (Array fptr)
70+
5171
op2
5272
:: Array b
5373
-> Array a

0 commit comments

Comments
 (0)