Skip to content

Commit 189cf4f

Browse files
committed
add: Common float32 tests
1 parent 44bf93a commit 189cf4f

11 files changed

Lines changed: 75 additions & 47 deletions

File tree

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

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,65 +17,58 @@ let config =
1717
endSize = 1000000 }
1818

1919
let wgSize = 32
20+
2021
let q = defaultContext.Queue
2122

2223
let makeTest sort (array: ('n * 'n * 'a) []) =
2324
if array.Length > 0 then
24-
let projection (row: 'n) (col: 'n) (v: 'a) = row, col
25+
let projection (row: 'n) (col: 'n) (_: 'a) = row, col
2526

2627
logger.debug (
2728
eventX "Initial size is {size}"
28-
>> setField "size" (sprintf "%A" array.Length)
29+
>> setField "size" $"%A{array.Length}"
2930
)
3031

3132
let rows, cols, vals = Array.unzip3 array
3233

3334
use clRows = context.CreateClArray rows
34-
use clCols = context.CreateClArray cols
35-
use clVals = context.CreateClArray vals
35+
use clColumns = context.CreateClArray cols
36+
use clValues = context.CreateClArray vals
3637

37-
let actualRows, actualCols, actualVals =
38-
sort q clRows clCols clVals
38+
let actualRows, actualCols, actualValues =
39+
sort q clRows clColumns clValues
3940

4041
let rows = Array.zeroCreate<'n> clRows.Length
41-
let cols = Array.zeroCreate<'n> clCols.Length
42-
let vals = Array.zeroCreate<'a> clVals.Length
42+
let columns = Array.zeroCreate<'n> clColumns.Length
43+
let values = Array.zeroCreate<'a> clValues.Length
4344

4445
q.Post(Msg.CreateToHostMsg(clRows, rows))
45-
q.Post(Msg.CreateToHostMsg(clCols, cols))
46+
q.Post(Msg.CreateToHostMsg(clColumns, columns))
4647

47-
q.PostAndReply(fun ch -> Msg.CreateToHostMsg(clVals, vals, ch))
48+
q.PostAndReply(fun ch -> Msg.CreateToHostMsg(clValues, values, ch))
4849
|> ignore
4950

50-
rows, cols, vals
51+
rows, columns, values
5152

52-
let expectedRows, expectedCols, expectedVals =
53+
let expectedRows, expectedCols, expectedValues =
5354
(rows, cols, vals)
5455
|||> Array.zip3
5556
|> Array.sortBy ((<|||) projection)
5657
|> Array.unzip3
5758

58-
(sprintf "Row arrays should be equal. Actual is \n%A, expected \n%A, input is \n%A" actualRows expectedRows rows)
59+
$"Row arrays should be equal. Actual is \n%A{actualRows}, expected \n%A{expectedRows}, input is \n%A{rows}"
5960
|> Utils.compareArrays (=) actualRows expectedRows
6061

61-
(sprintf
62-
"Column arrays should be equal. Actual is \n%A, expected \n%A, input is \n%A"
63-
actualCols
64-
expectedCols
65-
cols)
62+
$"Column arrays should be equal. Actual is \n%A{actualCols}, expected \n%A{expectedCols}, input is \n%A{cols}"
6663
|> Utils.compareArrays (=) actualCols expectedCols
6764

68-
(sprintf
69-
"Value arrays should be equal. Actual is \n%A, expected \n%A, input is \n%A"
70-
actualVals
71-
expectedVals
72-
vals)
73-
|> Utils.compareArrays (=) actualVals expectedVals
65+
$"Value arrays should be equal. Actual is \n%A{actualValues}, expected \n%A{expectedValues}, input is \n%A{vals}"
66+
|> Utils.compareArrays (=) actualValues expectedValues
7467

7568
let testFixtures<'a when 'a: equality> =
7669
BitonicSort.sortKeyValuesInplace<int, 'a> context wgSize
7770
|> makeTest
78-
|> testPropertyWithConfig config (sprintf "Correctness on %A" typeof<'a>)
71+
|> testPropertyWithConfig config $"Correctness on %A{typeof<'a>}"
7972

8073
let tests =
8174
q.Error.Add(fun e -> failwithf "%A" e)

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,13 @@ let testCases =
6464
<| (let copy = ClArray.copy context
6565
let getCopyFun = getCopyFun copy
6666

67-
fun (array: array<float>) -> makeTest getCopyFun array (Array.filter (System.Double.IsNaN >> not)))
67+
fun (array: array<float>) -> makeTest getCopyFun array (Array.filter System.Double.IsNormal))
68+
69+
testProperty "Correctness test on random float32 arrays"
70+
<| (let copy = ClArray.copy context
71+
let getCopyFun = getCopyFun copy
72+
73+
fun (array: array<float32>) -> makeTest getCopyFun array (Array.filter System.Single.IsNormal))
6874

6975
testProperty "Correctness test on random byte arrays"
7076
<| (let copy = ClArray.copy context

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ let context = defaultContext.ClContext
1616

1717
let q = defaultContext.Queue
1818

19+
let config = Utils.defaultConfig
20+
21+
let wgSize = 32
22+
1923
let correctnessGenericTest<'a when 'a: struct and 'a: equality> isZero exists (array: 'a []) =
2024

2125
if array.Length > 0 then
@@ -41,9 +45,6 @@ let correctnessGenericTest<'a when 'a: struct and 'a: equality> isZero exists (a
4145
|> Expect.equal result (Array.exists (not << isZero) array)
4246

4347
let testFixtures =
44-
let config = Utils.defaultConfig
45-
46-
let wgSize = 32
4748

4849
let getCorrectnessTestName datatype =
4950
sprintf "Correctness on %s, %A" datatype Dense
@@ -76,6 +77,15 @@ let testFixtures =
7677
correctnessGenericTest<float> ((=) 0.0) exists (Array.create 1000 0.0)
7778
|> testPropertyWithConfig config (getCorrectnessTestName "float zeros")
7879

80+
let exists =
81+
ClArray.exists context wgSize Predicates.isSome
82+
83+
correctnessGenericTest<float32> ((=) 0.0f) exists
84+
|> testPropertyWithConfig config (getCorrectnessTestName "float32")
85+
86+
correctnessGenericTest<float32> ((=) 0.0f) exists (Array.create 1000 0.0f)
87+
|> testPropertyWithConfig config (getCorrectnessTestName "float32 zeros")
88+
7989
let exists =
8090
ClArray.exists context wgSize Predicates.isSome
8191

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ let tests =
7878
testFixtures min <@ min @> System.Double.MaxValue (=) "float min"
7979
testFixtures max <@ max @> 0.0 (=) "float max"
8080

81+
testFixtures min <@ min @> System.Single.MaxValue (=) "float32 min"
82+
testFixtures max <@ max @> 0.0f (=) "float32 max"
83+
8184
testFixtures min <@ min @> System.Byte.MaxValue (=) "byte min"
8285
testFixtures (||) <@ (||) @> false (=) "bool logic-or"
8386
testFixtures (&&) <@ (&&) @> true (=) "bool logic-and" ]

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ let tests =
7171
testFixtures max <@ max @> System.Double.MinValue "float max"
7272
testFixtures min <@ min @> System.Double.MaxValue "float min"
7373

74+
testFixtures max <@ max @> System.Single.MinValue "float32 max"
75+
testFixtures min <@ min @> System.Single.MaxValue "float32 min"
76+
7477
testFixtures min <@ min @> System.Byte.MaxValue "byte min"
7578
testFixtures (||) <@ (||) @> false "bool logic-or"
7679
testFixtures (&&) <@ (&&) @> true "bool logic-and" ]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ let testCases =
6060

6161
logger.debug (
6262
eventX "Actual is {actual}"
63-
>> setField "actual" (sprintf "%A" actual)
63+
>> setField "actual" $"%A{actual}"
6464
)
6565

6666
let expected = Seq.distinct array |> Array.ofSeq

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ let testCases =
3939

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

4545
let expected =
@@ -50,7 +50,7 @@ let testCases =
5050

5151
let actual = filterFun actual
5252

53-
sprintf "Array should contains %i copies of the original one" i
53+
$"Array should contains %i{i} copies of the original one"
5454
|> Expect.sequenceEqual actual expected
5555

5656
[ testProperty "Correctness test on random int arrays"
@@ -69,7 +69,13 @@ let testCases =
6969
<| (let replicate = ClArray.replicate context
7070
let getReplicateFun = getReplicateFun replicate
7171

72-
fun (array: array<float>) -> makeTest getReplicateFun array (Array.filter (System.Double.IsNaN >> not)))
72+
fun (array: array<float>) -> makeTest getReplicateFun array (Array.filter System.Double.IsNormal))
73+
74+
testProperty "Correctness test on random float32 arrays"
75+
<| (let replicate = ClArray.replicate context
76+
let getReplicateFun = getReplicateFun replicate
77+
78+
fun (array: array<float32>) -> makeTest getReplicateFun array (Array.filter System.Single.IsNormal))
7379

7480
testProperty "Correctness test on random byte arrays"
7581
<| (let replicate = ClArray.replicate context

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,27 @@ let makeTest scatter (array: (int * 'a) []) (result: 'a []) =
3535
if 0 <= i && i < expected.Length then
3636
expected.[i] <- u
3737

38-
let positions, vals = Array.unzip array
38+
let positions, values = Array.unzip array
3939

4040
let actual =
4141
use clPositions = context.CreateClArray positions
42-
use clVals = context.CreateClArray vals
42+
use clValues = context.CreateClArray values
4343
use clResult = context.CreateClArray result
4444

45-
scatter q clPositions clVals clResult
45+
scatter q clPositions clValues clResult
4646

4747
q.PostAndReply(fun ch -> Msg.CreateToHostMsg(clResult, Array.zeroCreate result.Length, ch))
4848

49-
(sprintf "Arrays should be equal. Actual is \n%A, expected \n%A" actual expected)
49+
$"Arrays should be equal. Actual is \n%A{actual}, expected \n%A{expected}"
5050
|> Tests.Utils.compareArrays (=) actual expected
5151

5252
let testFixtures<'a when 'a: equality> =
5353
Scatter.runInplace<'a> context wgSize
5454
|> makeTest
55-
|> testPropertyWithConfig config (sprintf "Correctness on %A" typeof<'a>)
55+
|> testPropertyWithConfig config $"Correctness on %A{typeof<'a>}"
5656

5757
let tests =
58-
q.Error.Add(fun e -> failwithf "%A" e)
58+
q.Error.Add(fun e -> failwithf $"%A{e}")
5959

6060
[ testFixtures<int>
6161
testFixtures<byte>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ let tests =
6767
testFixtures min <@ min @> System.Double.MaxValue "float min"
6868
testFixtures max <@ max @> 0.0 "float max"
6969

70+
testFixtures min <@ min @> System.Single.MaxValue "float32 min"
71+
testFixtures max <@ max @> 0.0f "float32 max"
72+
7073
testFixtures min <@ min @> System.Byte.MaxValue "byte min"
7174
testFixtures (||) <@ (||) @> false "bool logic-or"
7275
testFixtures (&&) <@ (&&) @> true "bool logic-and" ]

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ let testFixtures isComplemented case =
122122
|> testPropertyWithConfig config (getCorrectnessTestName "float")
123123

124124
let float32Fill =
125-
Vector.assignByMaskComplemented context Mask.assign wgSize
125+
Vector.assignByMaskComplemented context Mask.assign wgSize
126126

127127
let float32ToCoo = Vector.toDense context wgSize
128128

@@ -149,7 +149,9 @@ let testFixtures isComplemented case =
149149
|> testPropertyWithConfig config (getCorrectnessTestName "bool") ]
150150

151151
let tests =
152-
operationGPUTests "Backend.Vector.assignByMask tests" <| testFixtures false
152+
operationGPUTests "Backend.Vector.assignByMask tests"
153+
<| testFixtures false
153154

154155
let complementedTests =
155-
operationGPUTests "Backend.Vector.assignByMaskComplemented tests" <| testFixtures true
156+
operationGPUTests "Backend.Vector.assignByMaskComplemented tests"
157+
<| testFixtures true

0 commit comments

Comments
 (0)