Skip to content

Commit 858cd82

Browse files
committed
Constants for test
1 parent 1ed601c commit 858cd82

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

tests/GraphBLAS-sharp.Tests/Backend/Algorithms/PageRank.fs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ open GraphBLAS.FSharp.Tests.Context
77
open GraphBLAS.FSharp.Objects.ClVectorExtensions
88
open GraphBLAS.FSharp.Objects
99

10-
let private alpha = 0.85f
11-
let private accuracy = 0.00001f
10+
let private accuracy = float32 Accuracy.low.absolute
1211

1312
let prepareNaive (matrix: float32 [,]) =
1413
let result = Array2D.copy matrix
@@ -23,7 +22,7 @@ let prepareNaive (matrix: float32 [,]) =
2322
(fun r c v ->
2423
result.[r, c] <-
2524
if v <> 0f then
26-
alpha / outDegrees.[r]
25+
Backend.Algorithms.PageRank.alpha / outDegrees.[r]
2726
else
2827
0f)
2928
matrix
@@ -47,7 +46,10 @@ let pageRankNaive (matrix: float32 [,]) =
4746
Array.create rowCount (1f / (float32 rowCount))
4847

4948
let mutable error = accuracy + 1f
50-
let addConst = (1f - alpha) / (float32 rowCount)
49+
50+
let addConst =
51+
(1f - Backend.Algorithms.PageRank.alpha)
52+
/ (float32 rowCount)
5153

5254
while (error > accuracy) do
5355
for r in 0 .. rowCount - 1 do
@@ -109,7 +111,7 @@ let testFixtures (testContext: TestContext) =
109111

110112
for i in 0 .. actual.Length - 1 do
111113
Expect.isTrue
112-
((abs (actual.[i] - expected.[i])) < accuracy)
114+
(Utils.float32IsEqualLowAccuracy actual.[i] expected.[i])
113115
(sprintf "Values should be equal. Expected %A, actual %A" expected.[i] actual.[i])
114116

115117
| _ -> failwith "Not implemented" ]

tests/GraphBLAS-sharp.Tests/Helpers.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ module Utils =
3838
float (abs (x - y)) < Accuracy.medium.absolute
3939
|| x.Equals y
4040

41+
let inline float32IsEqualLowAccuracy x y =
42+
float (abs (x - y)) < Accuracy.low.absolute
43+
|| x.Equals y
44+
4145
let vectorToDenseVector =
4246
function
4347
| Vector.Dense vector -> vector

0 commit comments

Comments
 (0)