Skip to content

Commit b91f69b

Browse files
dmjioclaude
andcommitted
feat: Add eval function and use it in Eq instance to flush JIT queue
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 147fbff commit b91f69b

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎src/ArrayFire/Array.hs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,18 @@ getDataRefCount
306306
getDataRefCount =
307307
fromIntegral . (`infoFromArray` af_get_data_ref_count)
308308

309+
-- | Force evaluation of a lazily-deferred 'Array', flushing any pending
310+
-- computation in the JIT queue and returning the same array.
311+
--
312+
-- >>> eval (vector @Double 10 [1..])
313+
-- ArrayFire Array
314+
-- ...
315+
--
316+
eval :: AFType a => Array a -> Array a
317+
eval arr@(Array fptr) = unsafePerformIO . mask_ $
318+
withForeignPtr fptr (throwAFError <=< af_eval) >> pure arr
319+
{-# NOINLINE eval #-}
320+
309321
-- | Should manual evaluation occur
310322
--
311323
-- >>> setManualEvalFlag True

‎src/ArrayFire/Orphans.hs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ instance NFData (Array a) where
3838
-- negation of '==', which keeps the two operators consistent by construction.
3939
instance (AFType a, Eq a) => Eq (Array a) where
4040
x == y = A.getDims x == A.getDims y
41-
&& A.allTrueAll (A.eqBatched x y False) == 1.0
41+
&& A.allTrueAll (A.eqBatched (A.eval x) (A.eval y) False) == 1.0
4242

4343
x /= y = A.getDims x /= A.getDims y
44-
|| A.anyTrueAll (A.neqBatched x y False) /= 0.0
44+
|| A.anyTrueAll (A.neqBatched (A.eval x) (A.eval y) False) /= 0.0
4545

4646

4747
-- | Elementwise 'Num' instance for 'Array'.

0 commit comments

Comments
 (0)