Skip to content

Commit d74458c

Browse files
committed
Change bfs matrix type to int; add mxv test on WrappedInt
1 parent 898c3d1 commit d74458c

10 files changed

Lines changed: 6211258 additions & 36 deletions

File tree

src/GraphBLAS-sharp/Algorithms/BFS.fs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ open GraphBLAS.FSharp.Predefined
44
open GraphBLAS.FSharp
55

66
module BFS =
7-
let levelSingleSource (matrix: Matrix<bool>) (source: int) = graphblas {
7+
let levelSingleSource (matrix: Matrix<int>) (source: int) = graphblas {
88
let vertexCount = Matrix.rowCount matrix
99
let! levels = Vector.zeroCreate vertexCount // v
10-
let! frontier = Vector.ofList vertexCount [source, true] // q[s] = true
11-
10+
let! frontier = Vector.ofList vertexCount [source, 1] // q[s] = true
1211
let! transposed = Matrix.transpose matrix // A'
1312

1413
let mutable currentLevel = 0
@@ -22,14 +21,14 @@ module BFS =
2221
do! Vector.fillSubVector levels frontierMask currentLevelScalar // v[q] = d
2322

2423
let! levelsComplemented = Vector.complemented levels
25-
do! Matrix.mxvWithMask AnyAll.bool levelsComplemented transposed frontier // q[!v] = (A' ||.&& q)' = q' ||.&& A -- replace + comp
24+
do! Matrix.mxvWithMask AddMult.int levelsComplemented transposed frontier // q[!v] = (A' ||.&& q)' = q' ||.&& A -- replace + comp
2625
>>= Vector.assignVector frontier
2726

2827
let! succ =
29-
Vector.reduce AnyAll.bool frontier
28+
Vector.reduce AddMult.int frontier
3029
>>= Scalar.exportValue
3130

32-
break' <- not succ
31+
break' <- succ = 0
3332

3433
return levels
3534
}

src/GraphBLAS-sharp/Algorithms/ShortestPath.fs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ open Brahma.FSharp.OpenCL.WorkflowBuilder.Basic
66
open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
77

88
module ShortestPath =
9+
// FIXME Unsupported call: min
910
let singleSource (matrix: Matrix<float>) (source: int) = graphblas {
1011
let vertexCount = Matrix.rowCount matrix
1112
let! distance = Vector.ofList vertexCount [source, 0.]
1213

14+
let! transposed = Matrix.transpose matrix // A'
15+
1316
// TODO terminate earlier if we reach a fixed point
1417
for _ = 1 to vertexCount - 1 do
15-
do! Matrix.vxm MinAdd.float distance matrix
18+
do! Matrix.mxv MinAdd.float transposed distance
1619
>>= Vector.assignVector distance
1720

1821
return distance

src/GraphBLAS-sharp/Backend/CSRMatrix/Convert.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ module internal rec Convert =
1919
else
2020
let! compressedRows = compressRows matrix.RowCount matrix.Rows
2121
let! cols = Copy.copyArray matrix.Columns
22-
let! vals = Copy.copyArray matrix.Values
22+
// FIXME copy broken
23+
let vals = matrix.Values
2324

2425
return {
2526
RowCount = matrix.RowCount

tests/GraphBLAS-sharp.Tests/AlgorithmsTests/BfsTests.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ open GraphBLAS.FSharp.Algorithms
1313
let logger = Log.create "Bfs.Tests"
1414

1515
let testCases = [
16-
ftestCase "" <| fun () ->
16+
testCase "" <| fun () ->
1717
let expected =
1818
graphblas {
1919
let! matrix =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
4-
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
4+
<TargetFrameworks>netcoreapp3.1;net461</TargetFrameworks>
55
</PropertyGroup>
66
<ItemGroup>
77
<ProjectReference Include="../../src/GraphBLAS-sharp/GraphBLAS-sharp.fsproj" />

tests/GraphBLAS-sharp.Tests/Helpers.fs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@ module Extensions =
1919
let (ClosedBinaryOp f) = this
2020
QuotationEvaluator.Evaluate f
2121

22+
module CustomDatatypes =
23+
[<Struct>]
24+
type WrappedInt = { InnerValue: int }
25+
with
26+
static member (+) (x: WrappedInt, y: WrappedInt) = { InnerValue = x.InnerValue + y.InnerValue }
27+
static member (*) (x: WrappedInt, y: WrappedInt) = { InnerValue = x.InnerValue * y.InnerValue }
28+
29+
let addMultSemiringOnWrappedInt: Semiring<WrappedInt> =
30+
{
31+
PlusMonoid = {
32+
AssociativeOp = ClosedBinaryOp <@ (+) @>
33+
Identity = { InnerValue = 0 }
34+
}
35+
36+
TimesSemigroup = { AssociativeOp = ClosedBinaryOp <@ (*) @> }
37+
}
38+
2239
module Generators =
2340
let logger = Log.create "Generators"
2441

@@ -185,6 +202,13 @@ module Generators =
185202
|> genericSparseGenerator false Arb.generate<bool>
186203
|> Arb.fromGen
187204

205+
static member WrappedInt() =
206+
pairOfMatrixAndVectorOfCompatibleSizeGenerator
207+
|> genericSparseGenerator
208+
CustomDatatypes.addMultSemiringOnWrappedInt.PlusMonoid.Identity
209+
Arb.generate<CustomDatatypes.WrappedInt>
210+
|> Arb.fromGen
211+
188212
type PairOfSparseVectorAndMatrixOfCompatibleSize() =
189213
static let pairOfVectorAndMatrixOfCompatibleSizeGenerator (valuesGenerator: Gen<'a>) = gen {
190214
let! (nrows, ncols) = dimension2DGenerator

tests/GraphBLAS-sharp.Tests/MatrixOperationsTests/MxvTests.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ let testFixtures case = [
216216

217217
"Values of actual and expected vectors should be the same"
218218
|> Expect.sequenceEqual actual.Values expected.Values
219+
220+
case
221+
|> correctnessGenericTest<CustomDatatypes.WrappedInt> CustomDatatypes.addMultSemiringOnWrappedInt (=)
222+
|> ftestPropertyWithConfig config (getCorrectnessTestName "WrappedInt")
219223
]
220224

221225
let tests =

tests/GraphBLAS-sharp.Tests/Program.fs

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,36 @@ open GraphBLAS.FSharp
1010
open GraphBLAS.FSharp.Algorithms
1111
open GraphBLAS.FSharp.IO
1212

13-
// [<Tests>]
14-
// let allTests =
15-
// testList "All tests" [
16-
// Backend.PrefixSum.tests
17-
// Backend.BitonicSort.tests
18-
// Backend.RemoveDuplicates.tests
19-
// Matrix.GetTuples.tests
20-
// Matrix.Mxv.tests
21-
// Matrix.Transpose.tests
22-
// Algo.Bfs.tests
23-
// ]
24-
// |> testSequenced
13+
[<Tests>]
14+
let allTests =
15+
testList "All tests" [
16+
Backend.PrefixSum.tests
17+
Backend.BitonicSort.tests
18+
Backend.RemoveDuplicates.tests
19+
Matrix.EWiseAdd.tests
20+
Matrix.GetTuples.tests
21+
Matrix.Mxv.tests
22+
Matrix.Transpose.tests
23+
Algo.Bfs.tests
24+
]
25+
|> testSequenced
2526

2627
[<EntryPoint>]
2728
let main argv =
28-
// allTests
29-
// |> runTestsWithCLIArgs [] argv
29+
allTests
30+
|> runTestsWithCLIArgs [] argv
3031

31-
graphblas {
32-
let! matrix =
33-
MtxReader("arc130.mtx").ReadMatrixReal(fun _ -> true)
34-
|> Matrix.switch CSR
32+
// graphblas {
33+
// let! matrix =
34+
// MtxReader("arc130.mtx").ReadMatrix(fun _ -> 1)
35+
// |> Matrix.switch CSR
3536

36-
return!
37-
BFS.levelSingleSource matrix 0
38-
>>= Vector.synchronizeAndReturn
39-
}
40-
|> EvalGB.withClContext (OpenCLEvaluationContext())
41-
|> EvalGB.runSync
42-
|> ignore
37+
// return!
38+
// BFS.levelSingleSource matrix 0
39+
// >>= Vector.synchronizeAndReturn
40+
// }
41+
// |> EvalGB.withClContext (OpenCLEvaluationContext())
42+
// |> EvalGB.runSync
43+
// |> printfn "%A"
4344

44-
0
45+
// 0

0 commit comments

Comments
 (0)