Skip to content

Commit bdf260a

Browse files
committed
refactor: ClArray.copy tests
1 parent 189cf4f commit bdf260a

3 files changed

Lines changed: 37 additions & 58 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ let tests =
7878
if Utils.isFloat64Available context.ClDevice then
7979
testFixtures<float>
8080

81+
testFixtures<float32>
82+
8183
testFixtures<byte>
8284
testFixtures<bool> ]
8385
|> testList "Backend.Common.BitonicSort tests"

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

Lines changed: 31 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,74 +8,51 @@ open GraphBLAS.FSharp.Tests
88
open GraphBLAS.FSharp.Backend.Common
99
open GraphBLAS.FSharp.Backend.Objects.ClContext
1010

11-
let logger = Log.create "Copy.Tests"
11+
let logger = Log.create "ClArray.Copy.Tests"
1212

1313
let context = Context.defaultContext.ClContext
1414

15-
let testCases =
16-
let q = Context.defaultContext.Queue
17-
q.Error.Add(fun e -> failwithf "%A" e)
18-
19-
let getCopyFun copy =
20-
fun (array: array<_>) ->
21-
let wgSize =
22-
[| for i in 0 .. 5 -> pown 2 i |]
23-
|> Array.filter (fun i -> array.Length % i = 0)
24-
|> Array.max
15+
let wgSize = 32
2516

26-
copy wgSize q HostInterop
17+
let q = Context.defaultContext.Queue
2718

28-
let makeTest getCopyFun (array: array<'a>) filterFun =
29-
if array.Length > 0 then
30-
use clArray = context.CreateClArray array
19+
let makeTest<'a when 'a: equality> copyFun (array: array<'a>) = // TODO()
20+
if array.Length > 0 then
21+
use clArray = context.CreateClArray array
3122

32-
let copy = getCopyFun array
23+
let actual =
24+
use clActual: ClArray<'a> = copyFun q HostInterop clArray
3325

34-
let actual =
35-
use clActual: ClArray<'a> = copy clArray
26+
let actual = Array.zeroCreate clActual.Length
27+
q.PostAndReply(fun ch -> Msg.CreateToHostMsg(clActual, actual, ch))
3628

37-
let actual = Array.zeroCreate clActual.Length
38-
q.PostAndReply(fun ch -> Msg.CreateToHostMsg(clActual, actual, ch))
29+
logger.debug (
30+
eventX "Actual is {actual}"
31+
>> setField "actual" $"%A{actual}"
32+
)
3933

40-
logger.debug (
41-
eventX "Actual is {actual}"
42-
>> setField "actual" (sprintf "%A" actual)
43-
)
34+
let expected = array
35+
let actual = actual
4436

45-
let expected = filterFun array
46-
let actual = filterFun actual
37+
"Array should be equals to original"
38+
|> Expect.sequenceEqual actual expected
4739

48-
"Array should be equals to original"
49-
|> Expect.sequenceEqual actual expected
40+
let creatTest<'a when 'a: equality> =
41+
ClArray.copy context wgSize
42+
|> makeTest<'a>
43+
|> testProperty $"Correctness test on random %A{typeof<'a>} arrays"
5044

51-
[ testProperty "Correctness test on random int arrays"
52-
<| (let copy = ClArray.copy context
53-
let getCopyFun = getCopyFun copy
54-
fun (array: array<int>) -> makeTest getCopyFun array id)
55-
56-
testProperty "Correctness test on random bool arrays"
57-
<| (let copy = ClArray.copy context
58-
let getCopyFun = getCopyFun copy
45+
let testCases =
46+
q.Error.Add(fun e -> failwithf "%A" e)
5947

60-
fun (array: array<bool>) -> makeTest getCopyFun array id)
48+
[ creatTest<int>
49+
creatTest<bool>
6150

6251
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
66-
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))
74-
75-
testProperty "Correctness test on random byte arrays"
76-
<| (let copy = ClArray.copy context
77-
let getCopyFun = getCopyFun copy
52+
creatTest<float>
7853

79-
fun (array: array<byte>) -> makeTest getCopyFun array id) ]
54+
creatTest<float32>
55+
creatTest<byte> ]
8056

81-
let tests = testCases |> testList "Array.copy tests"
57+
let tests =
58+
testCases |> testList "ClArray.copy tests"

tests/GraphBLAS-sharp.Tests/Helpers.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ module Generators =
252252
|> genericSparseGenerator false Arb.generate<bool>
253253
|> Arb.fromGen
254254

255-
type PairOfSparseMatrixOAndVectorfCompatibleSize() =
255+
type PairOfSparseMatrixOAndVectorsCompatibleSize() =
256256
static let pairOfMatrixAndVectorOfCompatibleSizeGenerator (valuesGenerator: Gen<'a>) =
257257
gen {
258258
let! nrows, ncols = dimension2DGenerator
@@ -645,7 +645,7 @@ module Generators =
645645
<| Arb.generate<bool>
646646
|> Arb.fromGen
647647

648-
type BufferCompatibleVector() =
648+
type BufferCompatibleArray() =
649649
static let compatibleVector (valuesGenerator: Gen<'a>) =
650650
gen {
651651
let! length = Gen.sized <| fun size -> Gen.choose (1, size)
@@ -767,11 +767,11 @@ module Utils =
767767
[ typeof<Generators.SingleMatrix>
768768
typeof<Generators.PairOfSparseMatricesOfEqualSize>
769769
typeof<Generators.PairOfMatricesOfCompatibleSize>
770-
typeof<Generators.PairOfSparseMatrixOAndVectorfCompatibleSize>
770+
typeof<Generators.PairOfSparseMatrixOAndVectorsCompatibleSize>
771771
typeof<Generators.PairOfSparseVectorAndMatrixOfCompatibleSize>
772772
typeof<Generators.ArrayOfDistinctKeys>
773773
typeof<Generators.ArrayOfAscendingKeys>
774-
typeof<Generators.BufferCompatibleVector>
774+
typeof<Generators.BufferCompatibleArray>
775775
typeof<Generators.PairOfVectorsOfEqualSize> ] }
776776

777777
let floatIsEqual x y =

0 commit comments

Comments
 (0)