Skip to content

Commit 9102d0f

Browse files
committed
refactor: modules in tests
1 parent 7b2ca81 commit 9102d0f

File tree

26 files changed

+1704
-1756
lines changed

26 files changed

+1704
-1756
lines changed
Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace GraphBLAS.FSharp.Tests.Backend.Algorithms
1+
module GraphBLAS.FSharp.Tests.Backend.Algorithms.BFS
22

33
open Expecto
44
open GraphBLAS.FSharp.Backend
@@ -12,55 +12,54 @@ open GraphBLAS.FSharp.Backend.Objects
1212
open GraphBLAS.FSharp.Objects.ClVectorExtensions
1313
open GraphBLAS.FSharp.Objects
1414

15-
module BFS =
16-
let testFixtures (testContext: TestContext) =
17-
[ let config = Utils.undirectedAlgoConfig
18-
let context = testContext.ClContext
19-
let queue = testContext.Queue
20-
let workGroupSize = Utils.defaultWorkGroupSize
15+
let testFixtures (testContext: TestContext) =
16+
[ let config = Utils.undirectedAlgoConfig
17+
let context = testContext.ClContext
18+
let queue = testContext.Queue
19+
let workGroupSize = Utils.defaultWorkGroupSize
2120

22-
let testName =
23-
sprintf "Test on %A" testContext.ClContext
21+
let testName =
22+
sprintf "Test on %A" testContext.ClContext
2423

25-
let bfs =
26-
Algorithms.BFS.singleSource context ArithmeticOperations.intSum ArithmeticOperations.intMul workGroupSize
24+
let bfs =
25+
Algorithms.BFS.singleSource context ArithmeticOperations.intSum ArithmeticOperations.intMul workGroupSize
2726

28-
testPropertyWithConfig config testName
29-
<| fun (matrix: int [,]) ->
27+
testPropertyWithConfig config testName
28+
<| fun (matrix: int [,]) ->
3029

31-
let graph = undirectedFromArray2D matrix 0
30+
let graph = undirectedFromArray2D matrix 0
3231

33-
let largestComponent =
34-
ConnectedComponents.largestComponent graph
32+
let largestComponent =
33+
ConnectedComponents.largestComponent graph
3534

36-
if largestComponent.Length > 0 then
37-
let source = largestComponent.[0]
35+
if largestComponent.Length > 0 then
36+
let source = largestComponent.[0]
3837

39-
let expected =
40-
(snd (BFS.runUndirected graph source))
41-
|> Utils.createArrayFromDictionary (Array2D.length1 matrix) 0
38+
let expected =
39+
(snd (BFS.runUndirected graph source))
40+
|> Utils.createArrayFromDictionary (Array2D.length1 matrix) 0
4241

43-
let matrixHost =
44-
Utils.createMatrixFromArray2D CSR matrix ((=) 0)
42+
let matrixHost =
43+
Utils.createMatrixFromArray2D CSR matrix ((=) 0)
4544

46-
let matrix = matrixHost.ToDevice context
45+
let matrix = matrixHost.ToDevice context
4746

48-
match matrix with
49-
| ClMatrix.CSR mtx ->
50-
let res = bfs queue mtx source |> ClVector.Dense
47+
match matrix with
48+
| ClMatrix.CSR mtx ->
49+
let res = bfs queue mtx source |> ClVector.Dense
5150

52-
let resHost = res.ToHost queue
51+
let resHost = res.ToHost queue
5352

54-
(mtx :> IDeviceMemObject).Dispose queue
55-
res.Dispose queue
53+
(mtx :> IDeviceMemObject).Dispose queue
54+
res.Dispose queue
5655

57-
match resHost with
58-
| Vector.Dense resHost ->
59-
let actual = resHost |> Utils.unwrapOptionArray 0
56+
match resHost with
57+
| Vector.Dense resHost ->
58+
let actual = resHost |> Utils.unwrapOptionArray 0
6059

61-
Expect.sequenceEqual actual expected "Sequences must be equal"
62-
| _ -> failwith "Not implemented"
63-
| _ -> failwith "Not implemented" ]
60+
Expect.sequenceEqual actual expected "Sequences must be equal"
61+
| _ -> failwith "Not implemented"
62+
| _ -> failwith "Not implemented" ]
6463

65-
let tests =
66-
TestCases.gpuTests "Bfs tests" testFixtures
64+
let tests =
65+
TestCases.gpuTests "Bfs tests" testFixtures
Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace GraphBLAS.FSharp.Tests.Backend.Common
1+
module GraphBLAS.FSharp.Tests.Backend.Common.BitonicSort
22

33
open Expecto
44
open Expecto.Logging
@@ -8,79 +8,78 @@ open Brahma.FSharp
88
open GraphBLAS.FSharp.Tests
99
open GraphBLAS.FSharp.Tests.Context
1010

11-
module BitonicSort =
12-
let logger = Log.create "BitonicSort.Tests"
11+
let logger = Log.create "BitonicSort.Tests"
1312

14-
let context = defaultContext.ClContext
13+
let context = defaultContext.ClContext
1514

16-
let config =
17-
{ Utils.defaultConfig with
18-
endSize = 1000000 }
15+
let config =
16+
{ Utils.defaultConfig with
17+
endSize = 1000000 }
1918

20-
let wgSize = Utils.defaultWorkGroupSize
19+
let wgSize = Utils.defaultWorkGroupSize
2120

22-
let q = defaultContext.Queue
21+
let q = defaultContext.Queue
2322

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

28-
logger.debug (
29-
eventX "Initial size is {size}"
30-
>> setField "size" $"%A{array.Length}"
31-
)
27+
logger.debug (
28+
eventX "Initial size is {size}"
29+
>> setField "size" $"%A{array.Length}"
30+
)
3231

33-
let rows, cols, vals = Array.unzip3 array
32+
let rows, cols, vals = Array.unzip3 array
3433

35-
use clRows = context.CreateClArray rows
36-
use clColumns = context.CreateClArray cols
37-
use clValues = context.CreateClArray vals
34+
use clRows = context.CreateClArray rows
35+
use clColumns = context.CreateClArray cols
36+
use clValues = context.CreateClArray vals
3837

39-
let actualRows, actualCols, actualValues =
40-
sort q clRows clColumns clValues
38+
let actualRows, actualCols, actualValues =
39+
sort q clRows clColumns clValues
4140

42-
let rows = Array.zeroCreate<'n> clRows.Length
43-
let columns = Array.zeroCreate<'n> clColumns.Length
44-
let values = Array.zeroCreate<'a> clValues.Length
41+
let rows = Array.zeroCreate<'n> clRows.Length
42+
let columns = Array.zeroCreate<'n> clColumns.Length
43+
let values = Array.zeroCreate<'a> clValues.Length
4544

46-
q.Post(Msg.CreateToHostMsg(clRows, rows))
47-
q.Post(Msg.CreateToHostMsg(clColumns, columns))
45+
q.Post(Msg.CreateToHostMsg(clRows, rows))
46+
q.Post(Msg.CreateToHostMsg(clColumns, columns))
4847

49-
q.PostAndReply(fun ch -> Msg.CreateToHostMsg(clValues, values, ch))
50-
|> ignore
48+
q.PostAndReply(fun ch -> Msg.CreateToHostMsg(clValues, values, ch))
49+
|> ignore
5150

52-
rows, columns, values
51+
rows, columns, values
5352

54-
let expectedRows, expectedCols, expectedValues =
55-
(rows, cols, vals)
56-
|||> Array.zip3
57-
|> Array.sortBy ((<|||) projection)
58-
|> Array.unzip3
53+
let expectedRows, expectedCols, expectedValues =
54+
(rows, cols, vals)
55+
|||> Array.zip3
56+
|> Array.sortBy ((<|||) projection)
57+
|> Array.unzip3
5958

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

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

66-
$"Value arrays should be equal. Actual is \n%A{actualValues}, expected \n%A{expectedValues}, input is \n%A{vals}"
67-
|> Utils.compareArrays (=) actualValues expectedValues
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
6867

69-
let testFixtures<'a when 'a: equality> =
70-
BitonicSort.sortKeyValuesInplace<int, 'a> context wgSize
71-
|> makeTest
72-
|> testPropertyWithConfig config $"Correctness on %A{typeof<'a>}"
68+
let testFixtures<'a when 'a: equality> =
69+
BitonicSort.sortKeyValuesInplace<int, 'a> context wgSize
70+
|> makeTest
71+
|> testPropertyWithConfig config $"Correctness on %A{typeof<'a>}"
7372

74-
let tests =
75-
q.Error.Add(fun e -> failwithf "%A" e)
73+
let tests =
74+
q.Error.Add(fun e -> failwithf "%A" e)
7675

77-
[ testFixtures<int>
76+
[ testFixtures<int>
7877

79-
if Utils.isFloat64Available context.ClDevice then
80-
testFixtures<float>
78+
if Utils.isFloat64Available context.ClDevice then
79+
testFixtures<float>
8180

82-
testFixtures<float32>
81+
testFixtures<float32>
8382

84-
testFixtures<byte>
85-
testFixtures<bool> ]
86-
|> testList "Backend.Common.BitonicSort tests"
83+
testFixtures<byte>
84+
testFixtures<bool> ]
85+
|> testList "Backend.Common.BitonicSort tests"
Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace GraphBLAS.FSharp.Tests.Backend.Common.ClArray
1+
module GraphBLAS.FSharp.Tests.Backend.Common.ClArray.Choose
22

33
open GraphBLAS.FSharp.Backend.Common
44
open Expecto
@@ -8,51 +8,50 @@ open GraphBLAS.FSharp.Backend.Objects.ClContext
88
open Brahma.FSharp
99
open GraphBLAS.FSharp.Backend.Quotes
1010

11-
module Choose =
12-
let workGroupSize = Utils.defaultWorkGroupSize
11+
let workGroupSize = Utils.defaultWorkGroupSize
1312

14-
let config = Utils.defaultConfig
13+
let config = Utils.defaultConfig
1514

16-
let makeTest<'a, 'b> testContext choose mapFun isEqual (array: 'a []) =
17-
if array.Length > 0 then
18-
let context = testContext.ClContext
19-
let q = testContext.Queue
15+
let makeTest<'a, 'b> testContext choose mapFun isEqual (array: 'a []) =
16+
if array.Length > 0 then
17+
let context = testContext.ClContext
18+
let q = testContext.Queue
2019

21-
let clArray =
22-
context.CreateClArrayWithSpecificAllocationMode(DeviceOnly, array)
20+
let clArray =
21+
context.CreateClArrayWithSpecificAllocationMode(DeviceOnly, array)
2322

24-
let (clResult: ClArray<'b>) = choose q HostInterop clArray
23+
let (clResult: ClArray<'b>) = choose q HostInterop clArray
2524

26-
let hostResult = Array.zeroCreate clResult.Length
25+
let hostResult = Array.zeroCreate clResult.Length
2726

28-
q.PostAndReply(fun ch -> Msg.CreateToHostMsg(clResult, hostResult, ch))
29-
|> ignore
27+
q.PostAndReply(fun ch -> Msg.CreateToHostMsg(clResult, hostResult, ch))
28+
|> ignore
3029

31-
let expectedResult = Array.choose mapFun array
30+
let expectedResult = Array.choose mapFun array
3231

33-
"Result should be the same"
34-
|> Utils.compareArrays isEqual hostResult expectedResult
32+
"Result should be the same"
33+
|> Utils.compareArrays isEqual hostResult expectedResult
3534

36-
let createTest<'a, 'b> testContext mapFun mapFunQ isEqual =
37-
let context = testContext.ClContext
35+
let createTest<'a, 'b> testContext mapFun mapFunQ isEqual =
36+
let context = testContext.ClContext
3837

39-
let choose =
40-
ClArray.choose context workGroupSize mapFunQ
38+
let choose =
39+
ClArray.choose context workGroupSize mapFunQ
4140

42-
makeTest<'a, 'b> testContext choose mapFun isEqual
43-
|> testPropertyWithConfig config $"Correctness on %A{typeof<'a>} -> %A{typeof<'b>}"
41+
makeTest<'a, 'b> testContext choose mapFun isEqual
42+
|> testPropertyWithConfig config $"Correctness on %A{typeof<'a>} -> %A{typeof<'b>}"
4443

45-
let testFixtures testContext =
46-
let device = testContext.ClContext.ClDevice
44+
let testFixtures testContext =
45+
let device = testContext.ClContext.ClDevice
4746

48-
[ createTest<int option, int> testContext id Map.id (=)
49-
createTest<byte option, byte> testContext id Map.id (=)
50-
createTest<bool option, bool> testContext id Map.id (=)
47+
[ createTest<int option, int> testContext id Map.id (=)
48+
createTest<byte option, byte> testContext id Map.id (=)
49+
createTest<bool option, bool> testContext id Map.id (=)
5150

52-
if Utils.isFloat64Available device then
53-
createTest<float option, float> testContext id Map.id Utils.floatIsEqual
51+
if Utils.isFloat64Available device then
52+
createTest<float option, float> testContext id Map.id Utils.floatIsEqual
5453

55-
createTest<float32 option, float32> testContext id Map.id Utils.float32IsEqual ]
54+
createTest<float32 option, float32> testContext id Map.id Utils.float32IsEqual ]
5655

57-
let tests =
58-
TestCases.gpuTests "ClArray.choose id tests" testFixtures
56+
let tests =
57+
TestCases.gpuTests "ClArray.choose id tests" testFixtures

0 commit comments

Comments
 (0)