Skip to content

Commit 3abdc9e

Browse files
committed
add: float32 tests in Matrix
1 parent d93681d commit 3abdc9e

3 files changed

Lines changed: 63 additions & 10 deletions

File tree

tests/GraphBLAS-sharp.Tests/Helpers.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,8 @@ module Utils =
778778
abs (x - y) < Accuracy.medium.absolute
779779
|| x.Equals y
780780

781+
let float32IsEqual x y = abs (x - y) < 0.01f || x.Equals y
782+
781783
let vectorToDenseVector =
782784
function
783785
| Vector.Dense vector -> vector

tests/GraphBLAS-sharp.Tests/Matrix/Map2.fs

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,18 @@ let testFixturesEWiseAdd case =
126126
let floatToCOO = Matrix.toCOO context wgSize
127127

128128
case
129-
|> correctnessGenericTest 0.0 (+) floatAdd floatToCOO (fun x y -> abs (x - y) < Accuracy.medium.absolute) q
129+
|> correctnessGenericTest 0.0 (+) floatAdd floatToCOO Utils.floatIsEqual q
130130
|> testPropertyWithConfig config (getCorrectnessTestName "float")
131131

132+
let float32Add =
133+
Matrix.map2 context ArithmeticOperations.float32Sum wgSize
134+
135+
let float32ToCOO = Matrix.toCOO context wgSize
136+
137+
case
138+
|> correctnessGenericTest 0.0f (+) float32Add float32ToCOO Utils.float32IsEqual q
139+
|> testPropertyWithConfig config (getCorrectnessTestName "float32")
140+
132141
let byteAdd =
133142
Matrix.map2 context ArithmeticOperations.byteSum wgSize
134143

@@ -174,9 +183,18 @@ let testFixturesEWiseAddAtLeastOne case =
174183
let floatToCOO = Matrix.toCOO context wgSize
175184

176185
case
177-
|> correctnessGenericTest 0.0 (+) floatAdd floatToCOO (fun x y -> abs (x - y) < Accuracy.medium.absolute) q
186+
|> correctnessGenericTest 0.0 (+) floatAdd floatToCOO Utils.floatIsEqual q
178187
|> testPropertyWithConfig config (getCorrectnessTestName "float")
179188

189+
let float32Add =
190+
Matrix.map2AtLeastOne context ArithmeticOperations.float32SumAtLeastOne wgSize
191+
192+
let float32ToCOO = Matrix.toCOO context wgSize
193+
194+
case
195+
|> correctnessGenericTest 0.0f (+) float32Add float32ToCOO Utils.float32IsEqual q
196+
|> testPropertyWithConfig config (getCorrectnessTestName "float32")
197+
180198
let byteAdd =
181199
Matrix.map2AtLeastOne context ArithmeticOperations.byteSumAtLeastOne wgSize
182200

@@ -222,9 +240,27 @@ let testFixturesEWiseAddAtLeastOneToCOO case =
222240
let floatToCOO = Matrix.toCOO context wgSize
223241

224242
case
225-
|> correctnessGenericTest 0.0 (+) floatAdd floatToCOO (fun x y -> abs (x - y) < Accuracy.medium.absolute) q
243+
|> correctnessGenericTest 0.0 (+) floatAdd floatToCOO Utils.floatIsEqual q
226244
|> testPropertyWithConfig config (getCorrectnessTestName "float")
227245

246+
let float32Add =
247+
Matrix.map2AtLeastOneToCOO context ArithmeticOperations.float32SumAtLeastOne wgSize
248+
249+
let floatToCOO = Matrix.toCOO context wgSize
250+
251+
case
252+
|> correctnessGenericTest 0.0f (+) float32Add floatToCOO Utils.float32IsEqual q
253+
|> testPropertyWithConfig config (getCorrectnessTestName "float32")
254+
255+
let float32Add =
256+
Matrix.map2AtLeastOneToCOO context ArithmeticOperations.float32SumAtLeastOne wgSize
257+
258+
let floatToCOO = Matrix.toCOO context wgSize
259+
260+
case
261+
|> correctnessGenericTest 0.0f (+) float32Add floatToCOO Utils.float32IsEqual q
262+
|> testPropertyWithConfig config (getCorrectnessTestName "float32")
263+
228264
let byteAdd =
229265
Matrix.map2AtLeastOneToCOO context ArithmeticOperations.byteSumAtLeastOne wgSize
230266

@@ -270,9 +306,18 @@ let testFixturesEWiseMulAtLeastOne case =
270306
let floatToCOO = Matrix.toCOO context wgSize
271307

272308
case
273-
|> correctnessGenericTest 0.0 (*) floatAdd floatToCOO (fun x y -> abs (x - y) < Accuracy.medium.absolute) q
309+
|> correctnessGenericTest 0.0 (*) floatAdd floatToCOO Utils.floatIsEqual q
274310
|> testPropertyWithConfig config (getCorrectnessTestName "float")
275311

312+
let float32Add =
313+
Matrix.map2AtLeastOne context ArithmeticOperations.float32MulAtLeastOne wgSize
314+
315+
let floatToCOO = Matrix.toCOO context wgSize
316+
317+
case
318+
|> correctnessGenericTest 0.0f (*) float32Add floatToCOO Utils.float32IsEqual q
319+
|> testPropertyWithConfig config (getCorrectnessTestName "float32")
320+
276321
let byteAdd =
277322
Matrix.map2AtLeastOne context ArithmeticOperations.byteMulAtLeastOne wgSize
278323

tests/GraphBLAS-sharp.Tests/Matrix/Transpose.fs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,6 @@ let testFixtures case =
127127
let getCorrectnessTestName datatype =
128128
sprintf "Correctness on %s, %A, %A" datatype case.Format case.TestContext
129129

130-
let areEqualFloat x y =
131-
System.Double.IsNaN x && System.Double.IsNaN y
132-
|| x = y
133-
134130
let context = case.TestContext.ClContext
135131
let q = case.TestContext.Queue
136132
q.Error.Add(fun e -> failwithf "%A" e)
@@ -149,15 +145,25 @@ let testFixtures case =
149145
let transposeFun = Matrix.transpose context wgSize
150146

151147
case
152-
|> makeTestRegular context q transposeFun areEqualFloat 0.0
148+
|> makeTestRegular context q transposeFun Utils.floatIsEqual 0.0
153149
|> testPropertyWithConfig config (getCorrectnessTestName "float")
154150

155151
case
156-
|> makeTestTwiceTranspose context q transposeFun areEqualFloat 0.0
152+
|> makeTestTwiceTranspose context q transposeFun Utils.floatIsEqual 0.0
157153
|> testPropertyWithConfig config (getCorrectnessTestName "float (twice transpose)")
158154

159155
let transposeFun = Matrix.transpose context wgSize
160156

157+
case
158+
|> makeTestRegular context q transposeFun Utils.float32IsEqual 0.0f
159+
|> testPropertyWithConfig config (getCorrectnessTestName "float32")
160+
161+
case
162+
|> makeTestTwiceTranspose context q transposeFun Utils.float32IsEqual 0.0f
163+
|> testPropertyWithConfig config (getCorrectnessTestName "float32 (twice transpose)")
164+
165+
let transposeFun = Matrix.transpose context wgSize
166+
161167
case
162168
|> makeTestRegular context q transposeFun (=) 0uy
163169
|> testPropertyWithConfig config (getCorrectnessTestName "byte")

0 commit comments

Comments
 (0)