Skip to content

Commit dffc3cb

Browse files
committed
add: Predicates.containsNonZero
1 parent 971306e commit dffc3cb

4 files changed

Lines changed: 19 additions & 22 deletions

File tree

src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,7 @@ module BFS =
3333
DenseVector.standardFillSubVectorTo<int, int> clContext workGroupSize
3434

3535
let containsNonZero =
36-
ClArray.exists
37-
clContext
38-
workGroupSize
39-
<@ fun (item: int option) ->
40-
match item with
41-
| Some _ -> true
42-
| _ -> false @>
36+
ClArray.exists clContext workGroupSize Predicates.containsNonZero
4337

4438
fun (queue: MailboxProcessor<Msg>) (matrix: ClCSRMatrix<'a>) (source: int) ->
4539
let vertexCount = matrix.RowCount

src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<Compile Include="Quotes/Mask.fs" />
2424
<Compile Include="Quotes/SubSum.fs" />
2525
<Compile Include="Quotes\PreparePositions.fs" />
26+
<Compile Include="Quotes\Predicates.fs" />
2627
<Compile Include="Common/Scatter.fs" />
2728
<Compile Include="Common/Utils.fs" />
2829
<Compile Include="Common/Sum.fs" />
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace GraphBLAS.FSharp.Backend.Quotes
2+
3+
module Predicates =
4+
let containsNonZero<'a> =
5+
<@ fun (item: 'a option) ->
6+
match item with
7+
| Some _ -> true
8+
| _ -> false @>

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

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ open GraphBLAS.FSharp.Tests.Utils
88
open Context
99
open Brahma.FSharp
1010
open GraphBLAS.FSharp.Backend.Objects
11-
open GraphBLAS.FSharp.Backend.Vector.Dense
11+
open GraphBLAS.FSharp.Backend.Quotes
1212

1313
let logger =
1414
Log.create "Vector.containsNonZero.Tests"
@@ -38,12 +38,6 @@ let correctnessGenericTest<'a when 'a: struct and 'a: equality> isZero containsN
3838
$"The results should be the same, vector : {vector}"
3939
|> Expect.equal result (Array.exists (not << isZero) array)
4040

41-
let predicate<'a when 'a: struct> =
42-
<@ fun (item: 'a option) ->
43-
match item with
44-
| Some _ -> true
45-
| _ -> false @>
46-
4741
let testFixtures =
4842
let config = defaultConfig
4943

@@ -52,42 +46,42 @@ let testFixtures =
5246
let getCorrectnessTestName datatype =
5347
sprintf "Correctness on %s, %A" datatype Dense
5448

55-
[ let containsNonZeroInt = ClArray.exists context wgSize predicate
49+
[ let containsNonZeroInt = ClArray.exists context wgSize Predicates.containsNonZero
5650

5751
correctnessGenericTest<int> ((=) 0) containsNonZeroInt
5852
|> testPropertyWithConfig config (getCorrectnessTestName "int")
5953

60-
let containsNonZeroByte = ClArray.exists context wgSize predicate
54+
let containsNonZeroByte = ClArray.exists context wgSize Predicates.containsNonZero
6155

6256
correctnessGenericTest<byte> ((=) 0uy) containsNonZeroByte
6357
|> testPropertyWithConfig config (getCorrectnessTestName "byte")
6458

65-
let containsNonZeroFloat = ClArray.exists context wgSize predicate
59+
let containsNonZeroFloat = ClArray.exists context wgSize Predicates.containsNonZero
6660

6761
correctnessGenericTest<float> ((=) 0.0) containsNonZeroFloat
6862
|> testPropertyWithConfig config (getCorrectnessTestName "float")
6963

70-
let containsNonZeroBool = ClArray.exists context wgSize predicate
64+
let containsNonZeroBool = ClArray.exists context wgSize Predicates.containsNonZero
7165

7266
correctnessGenericTest<bool> ((=) false) containsNonZeroBool
7367
|> testPropertyWithConfig config (getCorrectnessTestName "bool")
7468

75-
let containsNonZeroInt = ClArray.exists context wgSize predicate
69+
let containsNonZeroInt = ClArray.exists context wgSize Predicates.containsNonZero
7670

7771
correctnessGenericTest<int> ((=) 0) containsNonZeroInt (Array.create 1000 0)
7872
|> testPropertyWithConfig config (getCorrectnessTestName "int zeros")
7973

80-
let containsNonZeroByte = ClArray.exists context wgSize predicate
74+
let containsNonZeroByte = ClArray.exists context wgSize Predicates.containsNonZero
8175

8276
correctnessGenericTest<byte> ((=) 0uy) containsNonZeroByte (Array.create 1000 0uy)
8377
|> testPropertyWithConfig config (getCorrectnessTestName "byte zeros")
8478

85-
let containsNonZeroFloat = ClArray.exists context wgSize predicate
79+
let containsNonZeroFloat = ClArray.exists context wgSize Predicates.containsNonZero
8680

8781
correctnessGenericTest<float> ((=) 0.0) containsNonZeroFloat (Array.create 1000 0.0)
8882
|> testPropertyWithConfig config (getCorrectnessTestName "float zeros")
8983

90-
let containsNonZeroBool = ClArray.exists context wgSize predicate
84+
let containsNonZeroBool = ClArray.exists context wgSize Predicates.containsNonZero
9185

9286
correctnessGenericTest<bool> ((=) false) containsNonZeroBool (Array.create 1000 false)
9387
|> testPropertyWithConfig config (getCorrectnessTestName "bool zeros") ]

0 commit comments

Comments
 (0)