Skip to content

Commit a38aa20

Browse files
committed
PageRank test case
1 parent 7e914f1 commit a38aa20

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
module GraphBLAS.FSharp.Tests.Backend.Algorithms.PageRank
2+
3+
open Expecto
4+
open GraphBLAS.FSharp
5+
open GraphBLAS.FSharp.Backend.Quotes
6+
open GraphBLAS.FSharp.Tests
7+
open GraphBLAS.FSharp.Tests.Context
8+
open GraphBLAS.FSharp.Objects.ClVectorExtensions
9+
open GraphBLAS.FSharp.Objects
10+
open GraphBLAS.FSharp.Objects.MatrixExtensions
11+
12+
let testFixtures (testContext: TestContext) =
13+
[ let context = testContext.ClContext
14+
let queue = testContext.Queue
15+
let workGroupSize = Utils.defaultWorkGroupSize
16+
17+
let testName =
18+
sprintf "Test on %A" testContext.ClContext
19+
20+
let pageRank =
21+
Algorithms.PageRank.run context workGroupSize
22+
23+
testCase testName
24+
<| fun () ->
25+
26+
let matrix = Array2D.zeroCreate 4 4
27+
28+
matrix.[0, 1] <- 1f
29+
matrix.[0, 2] <- 1f
30+
matrix.[0, 3] <- 1f
31+
matrix.[1, 2] <- 1f
32+
matrix.[1, 3] <- 1f
33+
matrix.[2, 0] <- 1f
34+
matrix.[3, 2] <- 1f
35+
matrix.[3, 0] <- 1f
36+
37+
let matrixHost =
38+
Utils.createMatrixFromArray2D CSR matrix ((=) 0f)
39+
40+
let matrix = matrixHost.ToDevice context
41+
42+
let preparedMatrix =
43+
Algorithms.PageRank.prepareMatrix context workGroupSize queue matrix
44+
45+
let res = pageRank queue preparedMatrix
46+
47+
let resHost = res.ToHost queue
48+
49+
preparedMatrix.Dispose queue
50+
matrix.Dispose queue
51+
res.Dispose queue
52+
53+
let expected =
54+
[| 0.3681506515f
55+
0.1418093443f
56+
0.2879616022f
57+
0.2020783126f |]
58+
59+
match resHost with
60+
| Vector.Dense resHost ->
61+
let actual = resHost |> Utils.unwrapOptionArray 0f
62+
63+
for i in 0 .. actual.Length - 1 do
64+
Expect.isTrue (Utils.float32IsEqual actual.[i] expected.[i]) "Values should be equal"
65+
66+
| _ -> failwith "Not implemented" ]
67+
68+
let tests =
69+
TestCases.gpuTests "Bfs tests" testFixtures

tests/GraphBLAS-sharp.Tests/GraphBLAS-sharp.Tests.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<Compile Include="Backend/QuickGraph/CreateGraph.fs" />
2020
<Compile Include="Backend/Algorithms/BFS.fs" />
2121
<Compile Include="Backend/Algorithms/SSSP.fs" />
22+
<Compile Include="Backend/Algorithms/PageRank.fs" />
2223
<Compile Include="Backend/Common/ClArray/Blit.fs" />
2324
<Compile Include="Backend/Common/ClArray/Choose.fs" />
2425
<Compile Include="Backend/Common/ClArray/ChunkBySize.fs" />

0 commit comments

Comments
 (0)