Skip to content

Commit 4e087bd

Browse files
committed
add test float64 check, refacotr: Utils qualified
1 parent b7112a6 commit 4e087bd

28 files changed

Lines changed: 252 additions & 238 deletions

File tree

src/GraphBLAS-sharp.Backend/Common/Utils.fs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
namespace GraphBLAS.FSharp.Backend.Common
22

3-
open Brahma.FSharp
4-
53
module internal Utils =
64
let defaultWorkGroupSize = 32
75

src/GraphBLAS-sharp.Backend/Matrix/Common.fs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,3 @@ module Common =
5151
valuesScatter processor positions allValues resultValues
5252

5353
resultRows, resultColumns, resultValues, resultLength
54-
55-

src/GraphBLAS-sharp.Backend/Predefined/PrefixSum.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace GraphBLAS.FSharp.Backend.Predefined
22

33
open Brahma.FSharp
44
open GraphBLAS.FSharp.Backend.Common
5+
56
module internal PrefixSum =
67
let standardExcludeInplace (clContext: ClContext) workGroupSize =
78

src/GraphBLAS-sharp.Backend/Quotes/Convert.fs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,3 @@ module Convert =
2323
match rightItem with
2424
| Some _ -> (%op) leftItem None
2525
| None -> (%op) leftItem (Some value) @>
26-

src/GraphBLAS-sharp.Backend/Quotes/SubSum.fs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,3 @@ module SubSum =
3535
sumGeneral<'a> <| sequentialAccess<'a> opAdd
3636

3737
let treeSum<'a> opAdd = sumGeneral<'a> <| treeAccess<'a> opAdd
38-

src/GraphBLAS-sharp/Objects/VectorExtensions.fs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,3 @@ module ClVectorExtensions =
2222
Values = values
2323
Size = this.Size }
2424
| ClVector.Dense vector -> Vector.Dense <| vector.ToHost q
25-

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ open Expecto.Logging
55
open Expecto.Logging.Message
66
open GraphBLAS.FSharp.Backend.Common
77
open Brahma.FSharp
8-
open GraphBLAS.FSharp.Tests.Utils
8+
open GraphBLAS.FSharp.Tests
99
open GraphBLAS.FSharp.Tests.Context
1010

1111
let logger = Log.create "BitonicSort.Tests"
1212

1313
let context = defaultContext.ClContext
14-
let config = { defaultConfig with endSize = 1000000 }
14+
15+
let config =
16+
{ Utils.defaultConfig with
17+
endSize = 1000000 }
1518

1619
let wgSize = 32
1720
let q = defaultContext.Queue
@@ -53,21 +56,21 @@ let makeTest sort (array: ('n * 'n * 'a) []) =
5356
|> Array.unzip3
5457

5558
(sprintf "Row arrays should be equal. Actual is \n%A, expected \n%A, input is \n%A" actualRows expectedRows rows)
56-
|> compareArrays (=) actualRows expectedRows
59+
|> Utils.compareArrays (=) actualRows expectedRows
5760

5861
(sprintf
5962
"Column arrays should be equal. Actual is \n%A, expected \n%A, input is \n%A"
6063
actualCols
6164
expectedCols
6265
cols)
63-
|> compareArrays (=) actualCols expectedCols
66+
|> Utils.compareArrays (=) actualCols expectedCols
6467

6568
(sprintf
6669
"Value arrays should be equal. Actual is \n%A, expected \n%A, input is \n%A"
6770
actualVals
6871
expectedVals
6972
vals)
70-
|> compareArrays (=) actualVals expectedVals
73+
|> Utils.compareArrays (=) actualVals expectedVals
7174

7275
let testFixtures<'a when 'a: equality> =
7376
let sort =
@@ -80,7 +83,8 @@ let tests =
8083
q.Error.Add(fun e -> failwithf "%A" e)
8184

8285
[ testFixtures<int>
83-
testFixtures<float>
86+
if Utils.isFloat64Available context.ClDevice then
87+
testFixtures<float>
8488
testFixtures<byte>
8589
testFixtures<bool> ]
8690
|> testList "Backend.Common.BitonicSort tests"

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,17 @@ let testCases =
5959

6060
fun (array: array<bool>) -> makeTest getCopyFun array id)
6161

62-
testProperty "Correctness test on random float arrays"
63-
<| (let copy = ClArray.copy context
64-
let getCopyFun = getCopyFun copy
62+
if Utils.isFloat64Available context.ClDevice then
63+
testProperty "Correctness test on random float arrays"
64+
<| (let copy = ClArray.copy context
65+
let getCopyFun = getCopyFun copy
6566

66-
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.IsNaN >> not)))
6768

6869
testProperty "Correctness test on random byte arrays"
6970
<| (let copy = ClArray.copy context
7071
let getCopyFun = getCopyFun copy
7172

72-
fun (array: array<byte>) -> makeTest getCopyFun array id)
73-
74-
]
73+
fun (array: array<byte>) -> makeTest getCopyFun array id) ]
7574

7675
let tests = testCases |> testList "Array.copy tests"

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ open Expecto
44
open Expecto.Logging
55
open GraphBLAS.FSharp.Backend.Common
66
open GraphBLAS.FSharp.Tests
7-
open GraphBLAS.FSharp.Tests.Utils
87
open Context
98
open Brahma.FSharp
109
open GraphBLAS.FSharp.Backend.Objects
@@ -20,7 +19,8 @@ let q = defaultContext.Queue
2019
let correctnessGenericTest<'a when 'a: struct and 'a: equality> isZero exists (array: 'a []) =
2120

2221
if array.Length > 0 then
23-
let vector = createVectorFromArray Dense array isZero
22+
let vector =
23+
Utils.createVectorFromArray Dense array isZero
2424

2525
let result =
2626
match vector.ToDevice context with
@@ -41,7 +41,7 @@ let correctnessGenericTest<'a when 'a: struct and 'a: equality> isZero exists (a
4141
|> Expect.equal result (Array.exists (not << isZero) array)
4242

4343
let testFixtures =
44-
let config = defaultConfig
44+
let config = Utils.defaultConfig
4545

4646
let wgSize = 32
4747

@@ -66,14 +66,15 @@ let testFixtures =
6666
correctnessGenericTest<byte> ((=) 0uy) exists (Array.create 1000 0uy)
6767
|> testPropertyWithConfig config (getCorrectnessTestName "byte zeros")
6868

69-
let exists =
70-
ClArray.exists context wgSize Predicates.isSome
69+
if Utils.isFloat64Available context.ClDevice then
70+
let exists =
71+
ClArray.exists context wgSize Predicates.isSome
7172

72-
correctnessGenericTest<float> ((=) 0.0) exists
73-
|> testPropertyWithConfig config (getCorrectnessTestName "float")
73+
correctnessGenericTest<float> ((=) 0.0) exists
74+
|> testPropertyWithConfig config (getCorrectnessTestName "float")
7475

75-
correctnessGenericTest<float> ((=) 0.0) exists (Array.create 1000 0.0)
76-
|> testPropertyWithConfig config (getCorrectnessTestName "float zeros")
76+
correctnessGenericTest<float> ((=) 0.0) exists (Array.create 1000 0.0)
77+
|> testPropertyWithConfig config (getCorrectnessTestName "float zeros")
7778

7879
let exists =
7980
ClArray.exists context wgSize Predicates.isSome

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ open Expecto.Logging.Message
66
open Brahma.FSharp
77
open GraphBLAS.FSharp.Backend.Common
88
open GraphBLAS.FSharp.Tests.Context
9-
open GraphBLAS.FSharp.Tests.Utils
9+
open GraphBLAS.FSharp
1010

1111
let logger = Log.create "ClArray.PrefixSum.Tests"
1212

1313
let context = defaultContext.ClContext
1414

15-
let config = defaultConfig
15+
let config = Tests.Utils.defaultConfig
1616

1717
let wgSize = 128
1818

@@ -58,7 +58,7 @@ let makeTest scan plus zero isEqual (array: 'a []) =
5858
|> Expect.equal actualSum expectedSum
5959

6060
"Arrays should be the same"
61-
|> compareArrays isEqual actual expected
61+
|> Tests.Utils.compareArrays isEqual actual expected
6262

6363
let testFixtures plus plusQ zero isEqual name =
6464
let scan =
@@ -76,7 +76,10 @@ let tests =
7676
testFixtures max <@ max @> 0.0 (=) "float max"
7777
testFixtures max <@ max @> 0uy (=) "byte max"
7878
testFixtures min <@ min @> System.Int32.MaxValue (=) "int min"
79-
testFixtures min <@ min @> System.Double.MaxValue (=) "float min"
79+
80+
if Tests.Utils.isFloat64Available context.ClDevice then
81+
testFixtures min <@ min @> System.Double.MaxValue (=) "float min"
82+
8083
testFixtures min <@ min @> System.Byte.MaxValue (=) "byte min"
8184
testFixtures (||) <@ (||) @> false (=) "bool logic-or"
8285
testFixtures (&&) <@ (&&) @> true (=) "bool logic-and" ]

0 commit comments

Comments
 (0)