Skip to content

Commit 4dd3fb5

Browse files
committed
Fix all admonitions, except semiring closedness
1 parent 081468f commit 4dd3fb5

6 files changed

Lines changed: 37 additions & 27 deletions

File tree

benchmarks/GraphBLAS-sharp.Benchmarks/Config.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type TEPSColumn() =
2525
let (nrows, ncols, nnz) = float matrixInfo.[0], float matrixInfo.[1], float matrixInfo.[2]
2626
let (vertices, edges) = if nrows = ncols then (nrows, nnz) else (ncols, nrows)
2727
sprintf "%f" (edges / meanTime)
28-
| _ -> "file`s format not supported"
28+
| another -> sprintf "%s files not supported" another
2929
member this.GetValue(summary: Summary, benchmarkCase: BenchmarkCase, style: SummaryStyle): string =
3030
(this :> IColumn).GetValue(summary, benchmarkCase)
3131
member this.Id: string = "TEPSColumn"

src/GraphBLAS-sharp/Abstracts.fs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ type Matrix<'a when 'a : struct and 'a : equality>(nrow: int, ncol: int) =
2020

2121
abstract Mxm: Matrix<'b> -> Mask2D option -> Semiring<'a, 'b, 'c> -> Matrix<'c>
2222
abstract Mxv: Vector<'b> -> Mask1D option -> Semiring<'a, 'b, 'c> -> Vector<'c>
23-
abstract EWiseAdd: Matrix<'a> -> Mask2D option -> BinaryOp<'a, 'b, 'c> -> Matrix<'a>
24-
abstract EWiseMult: Matrix<'a> -> Mask2D option -> BinaryOp<'a, 'b, 'c> -> Matrix<'a>
23+
abstract EWiseAdd: Matrix<'b> -> Mask2D option -> Semiring<'a, 'b, 'c> -> Matrix<'c>
24+
abstract EWiseMult: Matrix<'b> -> Mask2D option -> Semiring<'a, 'b, 'c> -> Matrix<'c>
2525
abstract Apply: Mask1D option -> UnaryOp<'a, 'b> -> Matrix<'b>
26-
abstract ReduceIn: Mask1D option -> BinaryOp<'a, 'b, 'c> -> Vector<'a>
27-
abstract ReduceOut: Mask1D option -> BinaryOp<'a, 'b, 'c> -> Vector<'a>
26+
abstract ReduceIn: Mask1D option -> Monoid<'a> -> Vector<'a>
27+
abstract ReduceOut: Mask1D option -> Monoid<'a> -> Vector<'a>
2828
abstract Reduce: Monoid<'a> -> Scalar<'a>
2929
abstract T: Matrix<'a>
3030

31-
static member inline (+) (x: Matrix<'a>, y: Matrix<'a>) = x.EWiseAdd y
32-
static member inline (*) (x: Matrix<'a>, y: Matrix<'a>) = x.EWiseMult y
31+
static member inline (+) (x: Matrix<'a>, y: Matrix<'b>) = x.EWiseAdd y
32+
static member inline (*) (x: Matrix<'a>, y: Matrix<'b>) = x.EWiseMult y
3333
static member inline (@.) (x: Matrix<'a>, y: Matrix<'b>) = x.Mxm y
3434
static member inline (@.) (x: Matrix<'a>, y: Vector<'b>) = x.Mxv y
3535

@@ -48,33 +48,36 @@ and [<AbstractClass>] Vector<'a when 'a : struct and 'a : equality>(length: int)
4848
abstract Fill: Mask1D option -> Scalar<'a> with set
4949

5050
abstract Vxm: Matrix<'b> -> Mask1D option -> Semiring<'a, 'b, 'c> -> Vector<'c>
51-
abstract EWiseAdd: Vector<'a> -> Mask1D option -> BinaryOp<'a, 'b, 'c> -> Vector<'a>
52-
abstract EWiseMult: Vector<'a> -> Mask1D option -> BinaryOp<'a, 'b, 'c> -> Vector<'a>
51+
abstract EWiseAdd: Vector<'b> -> Mask1D option -> Semiring<'a, 'b, 'c> -> Vector<'c>
52+
abstract EWiseMult: Vector<'b> -> Mask1D option -> Semiring<'a, 'b, 'c> -> Vector<'c>
5353
abstract Apply: Mask1D option -> UnaryOp<'a, 'b> -> Vector<'b>
5454
abstract Reduce: Monoid<'a> -> Scalar<'a>
5555

56-
static member inline (+) (x: Vector<'a>, y: Vector<'a>) = x.EWiseAdd y
57-
static member inline (*) (x: Vector<'a>, y: Vector<'a>) = x.EWiseMult y
56+
static member inline (+) (x: Vector<'a>, y: Vector<'b>) = x.EWiseAdd y
57+
static member inline (*) (x: Vector<'a>, y: Vector<'b>) = x.EWiseMult y
5858
static member inline (@.) (x: Vector<'a>, y: Matrix<'b>) = x.Vxm y
5959

6060
and Mask1D(indices: int[], length: int, isComplemented: bool) =
61-
member this.IsComplemented = isComplemented
62-
6361
member this.Indices = indices
6462
member this.Length = length
63+
member this.IsComplemented = isComplemented
6564

6665
member this.Item
6766
with get (idx: int) : bool =
68-
this.Indices |> Array.exists ( ( = ) idx) |> ( <> ) this.IsComplemented
67+
this.Indices
68+
|> Array.exists ((=) idx)
69+
|> (<>) this.IsComplemented
6970

7071
and Mask2D(indices: (int * int)[], rowCount: int, columnCount: int, isComplemented: bool) =
71-
member this.IsComplemented = isComplemented
72-
7372
member this.Rows = indices |> Array.unzip |> fst
7473
member this.Columns = indices |> Array.unzip |> snd
7574
member this.RowCount = rowCount
7675
member this.ColumnCount = columnCount
76+
member this.IsComplemented = isComplemented
7777

7878
member this.Item
7979
with get (rowIdx: int, colIdx: int) : bool =
80-
Array.zip this.Rows this.Columns |> Array.exists ( ( = ) (rowIdx, colIdx)) |> ( <> ) this.IsComplemented
80+
(this.Rows, this.Columns)
81+
||> Array.zip
82+
|> Array.exists ((=) (rowIdx, colIdx))
83+
|> (<>) this.IsComplemented

src/GraphBLAS-sharp/Algorithms/BFS.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ module BFS =
2525
// let vertexCount = matrix.RowCount
2626
// let parents = SparseVector(vertexCount, [source, -1])
2727

28-
// let id = DenseVector(Array.init vertexCount id, IntegerMonoid.plus)
28+
// let id = DenseVector(Array.init vertexCount id, IntegerMonoid.add)
2929
// let frontier = SparseVector(vertexCount, [source, source])
3030

3131
// for _ in 1 .. vertexCount - 1 do
32-
// frontier.[Mask1D.complemented parents] <- (frontier .@ matrix) (Mask1D.complemented parents) IntegerSemiring.minFirst
33-
// parents.[Mask1D.regular frontier] <- frontier
34-
// frontier.[Mask1D.regular frontier] <- id
32+
// frontier.[parents.Complemented] <- (frontier @. matrix) parents.Complemented IntegerSemiring.minFirst
33+
// parents.[frontier.Mask] <- frontier
34+
// frontier.[frontier.Mask] <- id
3535

3636
// upcast parents

src/GraphBLAS-sharp/Algorithms/SSSP.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ module SSSP =
1010
let distance = SparseVector(vertexCount, [source, 0.])
1111

1212
for _ in 1 .. vertexCount - 1 do
13-
distance.[None] <- (distance @. matrix) None FloatSemiring.addMult
13+
distance.[None] <- (distance @. matrix) None FloatSemiring.minAdd
1414

1515
upcast distance

src/GraphBLAS-sharp/Algorithms/TriangleCounting.fs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ open GraphBLAS.FSharp
55

66
[<AutoOpen>]
77
module TriangleCounting =
8-
// нужна проекция в инт
9-
// let sandiaTriangleCount (lowerTriangular: Matrix<bool>) =
10-
// let c = (lowerTriangular .@ lowerTriangular.T) (Mask2D.regular lowerTriangular) BooleanSemiring.anyAll
11-
// c.Reduce BooleanMonoid.any
12-
()
8+
let sandiaTriangleCount (lowerTriangular: Matrix<bool>) =
9+
let bool2int = function
10+
| true -> 1
11+
| false -> 0
12+
let convertedMatrix = lowerTriangular.Apply None (UnaryOp <@ bool2int @>)
13+
let result = (convertedMatrix @. convertedMatrix.T) lowerTriangular.Mask IntegerSemiring.addMult
14+
result.Reduce IntegerMonoid.add

src/GraphBLAS-sharp/Predefined/Integer.fs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ module IntegerMonoid =
1414
}
1515

1616
module IntegerSemiring =
17+
let addMult: Semiring<int> = {
18+
PlusMonoid = IntegerMonoid.add
19+
Times = BinaryOp <@ ( * ) @>
20+
}
21+
1722
let minFirst<'b> : Semiring<int, 'b, int> = {
1823
PlusMonoid = IntegerMonoid.min
1924
Times = BinaryOp <@ fun x y -> x @>

0 commit comments

Comments
 (0)