Skip to content

Commit 40ec02b

Browse files
committed
refactor: Float64 check in tests
1 parent 4e087bd commit 40ec02b

12 files changed

Lines changed: 55 additions & 59 deletions

File tree

tests/GraphBLAS-sharp.Tests/Common/BitonicSort.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,18 @@ let makeTest sort (array: ('n * 'n * 'a) []) =
7373
|> Utils.compareArrays (=) actualVals expectedVals
7474

7575
let testFixtures<'a when 'a: equality> =
76-
let sort =
77-
BitonicSort.sortKeyValuesInplace<int, 'a> context wgSize
78-
79-
makeTest sort
76+
BitonicSort.sortKeyValuesInplace<int, 'a> context wgSize
77+
|> makeTest
8078
|> testPropertyWithConfig config (sprintf "Correctness on %A" typeof<'a>)
8179

8280
let tests =
8381
q.Error.Add(fun e -> failwithf "%A" e)
8482

8583
[ testFixtures<int>
84+
8685
if Utils.isFloat64Available context.ClDevice then
8786
testFixtures<float>
87+
8888
testFixtures<byte>
8989
testFixtures<bool> ]
9090
|> testList "Backend.Common.BitonicSort tests"

tests/GraphBLAS-sharp.Tests/Common/PrefixSum.fs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ let wgSize = 128
1818

1919
let q = defaultContext.Queue
2020

21-
let makeTest scan plus zero isEqual (array: 'a []) =
21+
let makeTest plus zero isEqual scan (array: 'a []) =
2222
if array.Length > 0 then
2323

2424
logger.debug (
@@ -61,10 +61,8 @@ let makeTest scan plus zero isEqual (array: 'a []) =
6161
|> Tests.Utils.compareArrays isEqual actual expected
6262

6363
let testFixtures plus plusQ zero isEqual name =
64-
let scan =
65-
ClArray.prefixSumIncludeInplace plusQ context wgSize
66-
67-
makeTest scan plus zero isEqual
64+
ClArray.prefixSumIncludeInplace plusQ context wgSize
65+
|> makeTest plus zero isEqual
6866
|> testPropertyWithConfig config (sprintf "Correctness on %s" name)
6967

7068
let tests =
@@ -73,12 +71,12 @@ let tests =
7371
[ testFixtures (+) <@ (+) @> 0 (=) "int add"
7472
testFixtures (+) <@ (+) @> 0uy (=) "byte add"
7573
testFixtures max <@ max @> 0 (=) "int max"
76-
testFixtures max <@ max @> 0.0 (=) "float max"
7774
testFixtures max <@ max @> 0uy (=) "byte max"
7875
testFixtures min <@ min @> System.Int32.MaxValue (=) "int min"
7976

8077
if Tests.Utils.isFloat64Available context.ClDevice then
8178
testFixtures min <@ min @> System.Double.MaxValue (=) "float min"
79+
testFixtures max <@ max @> 0.0 (=) "float max"
8280

8381
testFixtures min <@ min @> System.Byte.MaxValue (=) "byte min"
8482
testFixtures (||) <@ (||) @> false (=) "bool logic-or"

tests/GraphBLAS-sharp.Tests/Common/Reduce.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ let tests =
6464
[ testFixtures (+) <@ (+) @> 0 "int add"
6565
testFixtures (+) <@ (+) @> 0uy "byte add"
6666
testFixtures max <@ max @> System.Int32.MinValue "int max"
67-
testFixtures max <@ max @> System.Double.MinValue "float max"
6867
testFixtures max <@ max @> System.Byte.MinValue "byte max"
6968
testFixtures min <@ min @> System.Int32.MaxValue "int min"
7069

7170
if Utils.isFloat64Available context.ClDevice then
71+
testFixtures max <@ max @> System.Double.MinValue "float max"
7272
testFixtures min <@ min @> System.Double.MaxValue "float min"
7373

7474
testFixtures min <@ min @> System.Byte.MaxValue "byte min"

tests/GraphBLAS-sharp.Tests/Common/Replicate.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ let testCases =
3838
q.PostAndReply(fun ch -> Msg.CreateToHostMsg(clActual, actual, ch))
3939

4040
logger.debug (
41-
eventX "Actual is {actual}"
41+
eventX $"Actual is {actual}"
4242
>> setField "actual" (sprintf "%A" actual)
4343
)
4444

tests/GraphBLAS-sharp.Tests/Common/Scatter.fs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ let makeTest scatter (array: (int * 'a) []) (result: 'a []) =
5050
|> Tests.Utils.compareArrays (=) actual expected
5151

5252
let testFixtures<'a when 'a: equality> =
53-
let scatter = Scatter.runInplace<'a> context wgSize
54-
55-
makeTest scatter
53+
Scatter.runInplace<'a> context wgSize
54+
|> makeTest
5655
|> testPropertyWithConfig config (sprintf "Correctness on %A" typeof<'a>)
5756

5857
let tests =

tests/GraphBLAS-sharp.Tests/Common/Sum.fs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ let config = Utils.defaultConfig
1818
let wgSize = 128
1919
let q = defaultContext.Queue
2020

21-
let makeTest sum plus zero (array: 'a []) =
21+
let makeTest plus zero sum (array: 'a []) =
2222
if array.Length > 0 then
2323

2424
logger.debug (
@@ -49,9 +49,8 @@ let makeTest sum plus zero (array: 'a []) =
4949
|> Expect.equal actualSum expectedSum
5050

5151
let testFixtures plus (plusQ: Expr<'a -> 'a -> 'a>) zero name =
52-
let sum = Reduce.sum context wgSize plusQ zero
53-
54-
makeTest sum plus zero
52+
Reduce.sum context wgSize plusQ zero
53+
|> makeTest plus zero
5554
|> testPropertyWithConfig config (sprintf "Correctness on %s" name)
5655

5756
let tests =
@@ -61,12 +60,12 @@ let tests =
6160
[ testFixtures (+) <@ (+) @> 0 "int add"
6261
testFixtures (+) <@ (+) @> 0uy "byte add"
6362
testFixtures max <@ max @> 0 "int max"
64-
testFixtures max <@ max @> 0.0 "float max"
6563
testFixtures max <@ max @> 0uy "byte max"
6664
testFixtures min <@ min @> System.Int32.MaxValue "int min"
6765

6866
if Utils.isFloat64Available context.ClDevice then
6967
testFixtures min <@ min @> System.Double.MaxValue "float min"
68+
testFixtures max <@ max @> 0.0 "float max"
7069

7170
testFixtures min <@ min @> System.Byte.MaxValue "byte min"
7271
testFixtures (||) <@ (||) @> false "bool logic-or"

tests/GraphBLAS-sharp.Tests/Vector/AssignByMask.fs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ let logger = Log.create "Vector.assignByMask.Tests"
1818

1919
let alwaysTrue _ = true
2020

21+
let config = Utils.defaultConfig
22+
2123
let notNane x = not <| Double.IsNaN x
2224

2325
let checkResult isZero isComplemented (actual: Vector<'a>) (vector: 'a []) (mask: 'a []) (value: 'a) =
@@ -95,8 +97,6 @@ let makeTest<'a when 'a: struct and 'a: equality>
9597
| ex -> raise ex
9698

9799
let testFixtures case =
98-
let config = Utils.defaultConfig
99-
100100
let getCorrectnessTestName datatype =
101101
$"Correctness on %s{datatype}, vector: %A{case.Format}"
102102

@@ -146,8 +146,6 @@ let tests =
146146
operationGPUTests "Backend.Vector.assignByMask tests" testFixtures
147147

148148
let testFixturesComplemented case =
149-
let config = Utils.defaultConfig
150-
151149
let getCorrectnessTestName datatype =
152150
$"Correctness on %s{datatype}, vector: %A{case.Format}"
153151

tests/GraphBLAS-sharp.Tests/Vector/Convert.fs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ open Expecto
44
open Expecto.Logging
55
open Expecto.Logging.Message
66
open GraphBLAS.FSharp.Tests
7-
open GraphBLAS.FSharp.Tests
87
open GraphBLAS.FSharp.Backend
98
open TestCases
109
open GraphBLAS.FSharp.Backend.Objects

tests/GraphBLAS-sharp.Tests/Vector/Copy.fs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ open Expecto
44
open Expecto.Logging
55
open GraphBLAS.FSharp.Backend
66
open GraphBLAS.FSharp.Tests
7-
open GraphBLAS.FSharp.Tests
87
open TestCases
98
open GraphBLAS.FSharp.Backend.Objects
109
open GraphBLAS.FSharp.Backend.Vector

tests/GraphBLAS-sharp.Tests/Vector/Map2.fs

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,15 @@ let addTestFixtures case =
100100
|> correctnessGenericTest (=) 0 (+) intAddFun intToDense
101101
|> testPropertyWithConfig config (getCorrectnessTestName case "int" "int" "int")
102102

103-
let floatAddFun =
104-
Vector.map2 context ArithmeticOperations.floatSum wgSize
103+
if Utils.isFloat64Available context.ClDevice then
104+
let floatAddFun =
105+
Vector.map2 context ArithmeticOperations.floatSum wgSize
105106

106-
let floatToDense = Vector.toDense context wgSize
107+
let floatToDense = Vector.toDense context wgSize
107108

108-
case
109-
|> correctnessGenericTest Utils.floatIsEqual 0.0 (+) floatAddFun floatToDense
110-
|> testPropertyWithConfig config (getCorrectnessTestName case "float" "float" "float")
109+
case
110+
|> correctnessGenericTest Utils.floatIsEqual 0.0 (+) floatAddFun floatToDense
111+
|> testPropertyWithConfig config (getCorrectnessTestName case "float" "float" "float")
111112

112113
let boolAddFun =
113114
Vector.map2 context ArithmeticOperations.boolSum wgSize
@@ -144,17 +145,18 @@ let mulTestFixtures case =
144145
|> correctnessGenericTest (=) 0 (*) intMulFun intToDense
145146
|> testPropertyWithConfig config (getCorrectnessTestName case "int" "int" "int")
146147

147-
let floatMulFun =
148-
Vector.map2 context ArithmeticOperations.floatMul wgSize
148+
if Utils.isFloat64Available context.ClDevice then
149+
let floatMulFun =
150+
Vector.map2 context ArithmeticOperations.floatMul wgSize
149151

150-
let floatIsEqual =
151-
fun x y -> abs (x - y) < Accuracy.medium.absolute || x = y
152+
let floatIsEqual =
153+
fun x y -> abs (x - y) < Accuracy.medium.absolute || x = y
152154

153-
let floatToDense = Vector.toDense context wgSize
155+
let floatToDense = Vector.toDense context wgSize
154156

155-
case
156-
|> correctnessGenericTest floatIsEqual 0.0 (*) floatMulFun floatToDense
157-
|> testPropertyWithConfig config (getCorrectnessTestName case "float" "float" "float")
157+
case
158+
|> correctnessGenericTest floatIsEqual 0.0 (*) floatMulFun floatToDense
159+
|> testPropertyWithConfig config (getCorrectnessTestName case "float" "float" "float")
158160

159161
let boolMulFun =
160162
Vector.map2 context ArithmeticOperations.boolMul wgSize
@@ -195,14 +197,15 @@ let addAtLeastOneTestFixtures case =
195197
|> correctnessGenericTest (=) 0 (+) intAddFun toCoo
196198
|> testPropertyWithConfig config (getCorrectnessTestName "int" "int" "int")
197199

198-
let floatToCoo = Vector.toSparse context wgSize
200+
if Utils.isFloat64Available context.ClDevice then
201+
let floatToCoo = Vector.toSparse context wgSize
199202

200-
let floatAddFun =
201-
Vector.map2AtLeastOne context ArithmeticOperations.floatSumAtLeastOne wgSize
203+
let floatAddFun =
204+
Vector.map2AtLeastOne context ArithmeticOperations.floatSumAtLeastOne wgSize
202205

203-
case
204-
|> correctnessGenericTest Utils.floatIsEqual 0.0 (+) floatAddFun floatToCoo
205-
|> testPropertyWithConfig config (getCorrectnessTestName "float" "float" "float")
206+
case
207+
|> correctnessGenericTest Utils.floatIsEqual 0.0 (+) floatAddFun floatToCoo
208+
|> testPropertyWithConfig config (getCorrectnessTestName "float" "float" "float")
206209

207210
let boolToCoo = Vector.toSparse context wgSize
208211

@@ -242,17 +245,18 @@ let mulAtLeastOneTestFixtures case =
242245
|> correctnessGenericTest (=) 0 (*) intMulFun toCoo
243246
|> testPropertyWithConfig config (getCorrectnessTestName "int" "int" "int")
244247

245-
let floatToCoo = Vector.toSparse context wgSize
248+
if Utils.isFloat64Available context.ClDevice then
249+
let floatToCoo = Vector.toSparse context wgSize
246250

247-
let floatMulFun =
248-
Vector.map2AtLeastOne context ArithmeticOperations.floatMulAtLeastOne wgSize
251+
let floatMulFun =
252+
Vector.map2AtLeastOne context ArithmeticOperations.floatMulAtLeastOne wgSize
249253

250-
let fIsEqual =
251-
fun x y -> abs (x - y) < Accuracy.medium.absolute || x = y
254+
let fIsEqual =
255+
fun x y -> abs (x - y) < Accuracy.medium.absolute || x = y
252256

253-
case
254-
|> correctnessGenericTest fIsEqual 0.0 (*) floatMulFun floatToCoo
255-
|> testPropertyWithConfig config (getCorrectnessTestName "float" "float" "float")
257+
case
258+
|> correctnessGenericTest fIsEqual 0.0 (*) floatMulFun floatToCoo
259+
|> testPropertyWithConfig config (getCorrectnessTestName "float" "float" "float")
256260

257261
let boolToCoo = Vector.toSparse context wgSize
258262

0 commit comments

Comments
 (0)