-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Eq / Ord instances should work across all dimensions. (#21)
- Loading branch information
Showing
2 changed files
with
13 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,16 +17,16 @@ module ArrayFire.Orphans where | |
|
||
import Prelude | ||
|
||
import qualified ArrayFire.Arith as A | ||
import qualified ArrayFire.Array as A | ||
import qualified ArrayFire.Data as A | ||
import qualified ArrayFire.Arith as A | ||
import qualified ArrayFire.Array as A | ||
import qualified ArrayFire.Algorithm as A | ||
import qualified ArrayFire.Data as A | ||
import ArrayFire.Types | ||
import ArrayFire.Util | ||
import Foreign.C | ||
|
||
instance (AFType a, Eq a) => Eq (Array a) where | ||
x == y = toEnum . fromIntegral $ A.getScalar @CBool @a $! A.eq x y | ||
x /= y = toEnum . fromIntegral $ A.getScalar @CBool @a $! A.neq x y | ||
x == y = A.allTrueAll (A.eqBatched x y False) == (1.0,0.0) | ||
x /= y = A.allTrueAll (A.neqBatched x y False) == (0.0,0.0) | ||
|
||
instance (Num a, AFType a) => Num (Array a) where | ||
x + y = A.add x y | ||
|
@@ -40,10 +40,10 @@ instance (Num a, AFType a) => Num (Array a) where | |
fromInteger = A.scalar . fromIntegral | ||
|
||
instance (Ord a, AFType a) => Ord (Array a) where | ||
x < y = toEnum . fromIntegral $ A.getScalar @CBool @a (A.lt x y) | ||
x > y = toEnum . fromIntegral $ A.getScalar @CBool @a (A.gt x y) | ||
x <= y = toEnum . fromIntegral $ A.getScalar @CBool @a (A.le x y) | ||
x >= y = toEnum . fromIntegral $ A.getScalar @CBool @a (A.ge x y) | ||
x < y = A.allTrueAll (A.ltBatched x y False) == (1.0,0.0) | ||
x > y = A.allTrueAll (A.gtBatched x y False) == (1.0,0.0) | ||
x <= y = A.allTrueAll (A.leBatched x y False) == (1.0,0.0) | ||
x >= y = A.allTrueAll (A.geBatched x y False) == (1.0,0.0) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
dmjio
Author
Member
|
||
|
||
instance Show (Array a) where | ||
show = arrayString | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@dmjio This will give very weird behaviour to the
compare
function. What will the result ofcompare (vector @Int 2 [1,-1]) (vector @Int 2 [-1,1])
be:LT
,EQ
, orGT
? I think Arrays should have noOrd
instance.