Skip to content

Commit 081468f

Browse files
committed
Merge branch 'master' into simple-bfs-benchmark
2 parents b68a2b6 + a67d0b8 commit 081468f

8 files changed

Lines changed: 103 additions & 78 deletions

File tree

paket.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ NUGET
521521
System.Runtime.InteropServices (>= 4.3) - restriction: && (< monoandroid) (< monotouch) (< net45) (>= netstandard1.1) (< netstandard2.0) (< win8) (< wpa81) (< xamarintvos) (< xamarinwatchos)
522522
System.Net.Http (4.3.4) - restriction: || (&& (< net45) (>= net46) (< netstandard1.4) (>= netstandard1.6)) (&& (< net45) (< netstandard1.2) (>= netstandard1.6) (< win8)) (&& (< net45) (< netstandard1.3) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< net45) (< netstandard1.4) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< net45) (< netstandard1.5) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< net45) (>= netstandard1.6) (< netstandard2.0) (< win8) (< wpa81)) (&& (>= netcoreapp5.0) (< netstandard2.0)) (&& (< netstandard1.5) (>= netstandard1.6) (>= uap10.0))
523523
Microsoft.NETCore.Platforms (>= 1.1.1) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.6) (< win8) (< wpa81)) (>= netcoreapp5.0)
524+
Microsoft.Win32.Primitives (>= 4.3) - restriction: && (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.6) (< win8) (< wpa81)
524525
runtime.native.System (>= 4.3) - restriction: && (< monoandroid) (< monotouch) (< net45) (< netcoreapp5.0) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)
525526
runtime.native.System.Net.Http (>= 4.3) - restriction: && (< monoandroid) (< monotouch) (< net45) (< netcoreapp5.0) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)
526527
runtime.native.System.Security.Cryptography.OpenSsl (>= 4.3.2) - restriction: && (< monoandroid) (< monotouch) (< net45) (< netcoreapp5.0) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)
@@ -531,6 +532,7 @@ NUGET
531532
System.Globalization (>= 4.3) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.6) (< win8) (< wpa81)) (>= netcoreapp5.0)
532533
System.Globalization.Extensions (>= 4.3) - restriction: && (< monoandroid) (< monotouch) (< net45) (< netcoreapp5.0) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)
533534
System.IO (>= 4.3) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.1) (< netstandard1.3) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.6) (< win8) (< wpa81)) (>= netcoreapp5.0)
535+
System.IO.Compression (>= 4.3) - restriction: && (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.6) (< win8) (< wpa81)
534536
System.IO.FileSystem (>= 4.3) - restriction: && (< monoandroid) (< monotouch) (< net45) (< netcoreapp5.0) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)
535537
System.Net.Primitives (>= 4.3) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.1) (< netstandard1.3) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.6) (< win8) (< wpa81)) (>= netcoreapp5.0)
536538
System.Resources.ResourceManager (>= 4.3) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.6) (< win8) (< wpa81)) (>= netcoreapp5.0)

src/GraphBLAS-sharp/Abstracts.fs

Lines changed: 50 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,24 @@ type Matrix<'a when 'a : struct and 'a : equality>(nrow: int, ncol: int) =
77
default this.RowCount = nrow
88
default this.ColumnCount = ncol
99

10-
abstract Item: Mask2D -> Matrix<'a> with get, set
11-
abstract Item: Mask1D * int -> Vector<'a> with get, set
12-
abstract Item: int * Mask1D -> Vector<'a> with get, set
10+
abstract Mask: Mask2D option
11+
abstract Complemented: Mask2D option
12+
13+
abstract Item: Mask2D option -> Matrix<'a> with get, set
14+
abstract Item: Mask1D option * int -> Vector<'a> with get, set
15+
abstract Item: int * Mask1D option -> Vector<'a> with get, set
1316
abstract Item: int * int -> Scalar<'a> with get, set
14-
abstract Fill: Mask2D -> Scalar<'a> with set
15-
abstract Fill: Mask1D * int -> Scalar<'a> with set
16-
abstract Fill: int * Mask1D -> Scalar<'a> with set
17-
18-
abstract Mxm: Matrix<'b> -> Mask2D -> Semiring<'a, 'b, 'c> -> Matrix<'c>
19-
abstract Mxv: Vector<'b> -> Mask1D -> Semiring<'a, 'b, 'c> -> Vector<'c>
20-
abstract EWiseAdd: Matrix<'a> -> Mask2D -> BinaryOp<'a, 'b, 'c> -> Matrix<'a>
21-
abstract EWiseMult: Matrix<'a> -> Mask2D -> BinaryOp<'a, 'b, 'c> -> Matrix<'a>
22-
abstract Apply: Mask1D -> UnaryOp<'a, 'b> -> Matrix<'b>
23-
abstract ReduceIn: Mask1D -> BinaryOp<'a, 'b, 'c> -> Vector<'a>
24-
abstract ReduceOut: Mask1D -> BinaryOp<'a, 'b, 'c> -> Vector<'a>
17+
abstract Fill: Mask2D option -> Scalar<'a> with set
18+
abstract Fill: Mask1D option * int -> Scalar<'a> with set
19+
abstract Fill: int * Mask1D option -> Scalar<'a> with set
20+
21+
abstract Mxm: Matrix<'b> -> Mask2D option -> Semiring<'a, 'b, 'c> -> Matrix<'c>
22+
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>
25+
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>
2528
abstract Reduce: Monoid<'a> -> Scalar<'a>
2629
abstract T: Matrix<'a>
2730

@@ -30,36 +33,48 @@ type Matrix<'a when 'a : struct and 'a : equality>(nrow: int, ncol: int) =
3033
static member inline (@.) (x: Matrix<'a>, y: Matrix<'b>) = x.Mxm y
3134
static member inline (@.) (x: Matrix<'a>, y: Vector<'b>) = x.Mxv y
3235

33-
and [<AbstractClass>] Vector<'a when 'a : struct and 'a : equality>(size: int) =
34-
abstract Size: int
35-
default this.Size = size
36+
and [<AbstractClass>] Vector<'a when 'a : struct and 'a : equality>(length: int) =
37+
abstract Length: int
38+
default this.Length = length
3639

3740
abstract AsArray: 'a[]
3841
abstract Clear: unit -> unit
3942

40-
abstract Item: Mask1D -> Vector<'a> with get, set
43+
abstract Mask: Mask1D option
44+
abstract Complemented: Mask1D option
45+
46+
abstract Item: Mask1D option -> Vector<'a> with get, set
4147
abstract Item: int -> Scalar<'a> with get, set
42-
abstract Fill: Mask1D -> Scalar<'a> with set
48+
abstract Fill: Mask1D option -> Scalar<'a> with set
4349

44-
abstract Vxm: Matrix<'b> -> Mask1D -> Semiring<'a, 'b, 'c> -> Vector<'c>
45-
abstract EWiseAdd: Vector<'a> -> Mask1D -> BinaryOp<'a, 'b, 'c> -> Vector<'a>
46-
abstract EWiseMult: Vector<'a> -> Mask1D -> BinaryOp<'a, 'b, 'c> -> Vector<'a>
47-
abstract Apply: Mask1D -> UnaryOp<'a, 'b> -> Vector<'b>
50+
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>
53+
abstract Apply: Mask1D option -> UnaryOp<'a, 'b> -> Vector<'b>
4854
abstract Reduce: Monoid<'a> -> Scalar<'a>
4955

5056
static member inline (+) (x: Vector<'a>, y: Vector<'a>) = x.EWiseAdd y
5157
static member inline (*) (x: Vector<'a>, y: Vector<'a>) = x.EWiseMult y
5258
static member inline (@.) (x: Vector<'a>, y: Matrix<'b>) = x.Vxm y
5359

54-
and Mask1D = {
55-
Indices: int list
56-
Size: int
57-
IsComplemented: bool
58-
}
59-
60-
and Mask2D = {
61-
Indices: (int * int) list
62-
RowCount: int
63-
ColumnCount: int
64-
IsComplemented: bool
65-
}
60+
and Mask1D(indices: int[], length: int, isComplemented: bool) =
61+
member this.IsComplemented = isComplemented
62+
63+
member this.Indices = indices
64+
member this.Length = length
65+
66+
member this.Item
67+
with get (idx: int) : bool =
68+
this.Indices |> Array.exists ( ( = ) idx) |> ( <> ) this.IsComplemented
69+
70+
and Mask2D(indices: (int * int)[], rowCount: int, columnCount: int, isComplemented: bool) =
71+
member this.IsComplemented = isComplemented
72+
73+
member this.Rows = indices |> Array.unzip |> fst
74+
member this.Columns = indices |> Array.unzip |> snd
75+
member this.RowCount = rowCount
76+
member this.ColumnCount = columnCount
77+
78+
member this.Item
79+
with get (rowIdx: int, colIdx: int) : bool =
80+
Array.zip this.Rows this.Columns |> Array.exists ( ( = ) (rowIdx, colIdx)) |> ( <> ) this.IsComplemented

src/GraphBLAS-sharp/Algorithms/BFS.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ module BFS =
1414

1515
let mutable currentLevel = 1
1616
while !> (frontier.Reduce BooleanMonoid.any) && currentLevel < vertexCount do
17-
levels.Fill(Mask1D.regular frontier) <- Scalar currentLevel
17+
levels.Fill(frontier.Mask) <- Scalar currentLevel
1818
frontier.Clear()
19-
frontier.[Mask1D.complemented levels] <- (frontier @. matrix) (Mask1D.complemented levels) BooleanSemiring.anyAll
19+
frontier.[levels.Complemented] <- (frontier @. matrix) levels.Complemented BooleanSemiring.anyAll
2020
currentLevel <- currentLevel + 1
2121

2222
upcast levels

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.[Mask1D.none] <- (distance @. matrix) Mask1D.none FloatSemiring.addMult
13+
distance.[None] <- (distance @. matrix) None FloatSemiring.addMult
1414

1515
upcast distance

src/GraphBLAS-sharp/GraphBLAS-sharp.fsproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
<Compile Include="Implementations.fs" />
2020
<Compile Include="Matrix.fs" />
2121
<Compile Include="Vector.fs" />
22-
<Compile Include="Masks.fs" />
2322
<Compile Include="Predefined/Float.fs" />
2423
<Compile Include="Predefined/Integer.fs" />
2524
<Compile Include="Predefined/Boolean.fs" />

src/GraphBLAS-sharp/Implementations.fs

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type CSRMatrix<'a when 'a : struct and 'a : equality>(csrTuples: CSRFormat<'a>)
3232
let spMV (vector: Vector<'a>) (mask: Mask1D) (semiring: Semiring<'a>) : Vector<'a> =
3333
let csrMatrixRowCount = rowCount
3434
let csrMatrixColumnCount = columnCount
35-
let vectorLength = vector.Size
35+
let vectorLength = vector.Length
3636
if csrMatrixColumnCount <> vectorLength then
3737
invalidArg
3838
"vector"
@@ -80,24 +80,27 @@ type CSRMatrix<'a when 'a : struct and 'a : equality>(csrTuples: CSRFormat<'a>)
8080
member this.Columns = csrTuples.Columns
8181
member this.RowPointers = csrTuples.RowPointers
8282

83+
override this.Mask = failwith "Not implemented"
84+
override this.Complemented = failwith "Not implemented"
85+
8386
override this.Item
84-
with get (mask: Mask2D) : Matrix<'a> = failwith "Not Implemented"
85-
and set (mask: Mask2D) (value: Matrix<'a>) = failwith "Not Implemented"
87+
with get (mask: Mask2D option) : Matrix<'a> = failwith "Not Implemented"
88+
and set (mask: Mask2D option) (value: Matrix<'a>) = failwith "Not Implemented"
8689
override this.Item
87-
with get (vectorMask: Mask1D, colIdx: int) : Vector<'a> = failwith "Not Implemented"
88-
and set (vectorMask: Mask1D, colIdx: int) (value: Vector<'a>) = failwith "Not Implemented"
90+
with get (vectorMask: Mask1D option, colIdx: int) : Vector<'a> = failwith "Not Implemented"
91+
and set (vectorMask: Mask1D option, colIdx: int) (value: Vector<'a>) = failwith "Not Implemented"
8992
override this.Item
90-
with get (rowIdx: int, vectorMask: Mask1D) : Vector<'a> = failwith "Not Implemented"
91-
and set (rowIdx: int, vectorMask: Mask1D) (value: Vector<'a>) = failwith "Not Implemented"
93+
with get (rowIdx: int, vectorMask: Mask1D option) : Vector<'a> = failwith "Not Implemented"
94+
and set (rowIdx: int, vectorMask: Mask1D option) (value: Vector<'a>) = failwith "Not Implemented"
9295
override this.Item
9396
with get (rowIdx: int, colIdx: int) : Scalar<'a> = failwith "Not Implemented"
9497
and set (rowIdx: int, colIdx: int) (value: Scalar<'a>) = failwith "Not Implemented"
9598
override this.Fill
96-
with set (mask: Mask2D) (value: Scalar<'a>) = failwith "Not Implemented"
99+
with set (mask: Mask2D option) (value: Scalar<'a>) = failwith "Not Implemented"
97100
override this.Fill
98-
with set (vectorMask: Mask1D, colIdx: int) (value: Scalar<'a>) = failwith "Not Implemented"
101+
with set (vectorMask: Mask1D option, colIdx: int) (value: Scalar<'a>) = failwith "Not Implemented"
99102
override this.Fill
100-
with set (rowIdx: int, vectorMask: Mask1D) (value: Scalar<'a>) = failwith "Not Implemented"
103+
with set (rowIdx: int, vectorMask: Mask1D option) (value: Scalar<'a>) = failwith "Not Implemented"
101104

102105
override this.Mxm a b c = failwith "Not Implemented"
103106
override this.Mxv a b c = failwith "Not Implemented"
@@ -115,18 +118,21 @@ and SparseVector<'a when 'a : struct and 'a : equality>(size: int, listOfNonzero
115118
member this.AsList: (int * 'a) list = listOfNonzeroes
116119

117120
override this.AsArray = failwith "Not Implemented"
118-
override this.Clear () = failwith "Not Implemented"
121+
override this.Clear() = failwith "Not Implemented"
122+
123+
override this.Mask = failwith "Not implemented"
124+
override this.Complemented = failwith "Not implemented"
119125

120126
override this.Item
121-
with get (mask: Mask1D) : Vector<'a> = failwith "Not Implemented"
122-
and set (mask: Mask1D) (value: Vector<'a>) = failwith "Not Implemented"
127+
with get (mask: Mask1D option) : Vector<'a> = failwith "Not Implemented"
128+
and set (mask: Mask1D option) (value: Vector<'a>) = failwith "Not Implemented"
123129
override this.Item
124130
with get (idx: int) : Scalar<'a> = failwith "Not Implemented"
125131
and set (idx: int) (value: Scalar<'a>) = failwith "Not Implemented"
126132
override this.Fill
127-
with set (mask: Mask1D) (value: Scalar<'a>) = failwith "Not Implemented"
133+
with set (mask: Mask1D option) (value: Scalar<'a>) = failwith "Not Implemented"
128134

129-
override this.Vxm (matrix: Matrix<'b>) (mask: Mask1D) (semiring: Semiring<'a, 'b, 'c>) : Vector<'c> = failwith "Not Implemented"
135+
override this.Vxm (matrix: Matrix<'b>) (mask: Mask1D option) (semiring: Semiring<'a, 'b, 'c>) : Vector<'c> = failwith "Not Implemented"
130136
override this.EWiseAdd a b c = failwith "Not Implemented"
131137
override this.EWiseMult a b c = failwith "Not Implemented"
132138
override this.Apply a b = failwith "Not Implemented"
@@ -135,24 +141,40 @@ and SparseVector<'a when 'a : struct and 'a : equality>(size: int, listOfNonzero
135141
and DenseVector<'a when 'a : struct and 'a : equality>(vector: 'a[], monoid: Monoid<'a>) =
136142
inherit Vector<'a>(vector.Length)
137143

138-
override this.AsArray = vector
139-
override this.Clear () = failwith "Not Implemented"
144+
// Not Implemented
145+
new(monoid: Monoid<'a>) = DenseVector(Array.zeroCreate<'a> 0, monoid)
146+
// Not Implemented
147+
new(listOfIndices: int list, monoid: Monoid<'a>) = DenseVector(Array.zeroCreate<'a> 0, monoid)
148+
149+
member this.Monoid = monoid
150+
member this.Values = vector
151+
152+
override this.AsArray = failwith "Not Implemented"
153+
override this.Clear() = failwith "Not Implemented"
154+
155+
override this.Mask =
156+
let indices =
157+
[| for i in 0 .. this.Length - 1 do
158+
if this.Values.[i] <> this.Monoid.Zero then yield i |]
159+
Some <| Mask1D(indices, this.Length, false)
160+
161+
override this.Complemented =
162+
let indices =
163+
[| for i in 0 .. this.Length - 1 do
164+
if this.Values.[i] <> this.Monoid.Zero then yield i |]
165+
Some <| Mask1D(indices, this.Length, true)
140166

141167
override this.Item
142-
with get (mask: Mask1D) : Vector<'a> = failwith "Not Implemented"
143-
and set (mask: Mask1D) (value: Vector<'a>) = failwith "Not Implemented"
168+
with get (mask: Mask1D option) : Vector<'a> = failwith "Not Implemented"
169+
and set (mask: Mask1D option) (value: Vector<'a>) = failwith "Not Implemented"
144170
override this.Item
145171
with get (idx: int) : Scalar<'a> = failwith "Not Implemented"
146172
and set (idx: int) (value: Scalar<'a>) = failwith "Not Implemented"
147173
override this.Fill
148-
with set (mask: Mask1D) (value: Scalar<'a>) = failwith "Not Implemented"
174+
with set (mask: Mask1D option) (value: Scalar<'a>) = failwith "Not Implemented"
149175

150176
override this.Vxm a b c = failwith "Not Implemented"
151177
override this.EWiseAdd a b c = failwith "Not Implemented"
152178
override this.EWiseMult a b c = failwith "Not Implemented"
153179
override this.Apply a b = failwith "Not Implemented"
154-
override this.Reduce (monoid: Monoid<'a>) =
155-
vector
156-
|> Array.reduce (QuotationEvaluator.Evaluate !> monoid.Append)
157-
|> Scalar
158-
180+
override this.Reduce (monoid: Monoid<'a>) = failwith "Not Implemented"

src/GraphBLAS-sharp/Masks.fs

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/GraphBLAS-sharp.Tests/OperationsTests/VxmTests.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ module VxmTests =
9595
| VectorType.Sparse -> (fun length -> Vector.ZeroSparse(length))
9696
| _ -> failwith "Not Implemented"
9797

98-
let mask : Mask1D =
98+
let mask : Mask1D option =
9999
match case.MaskCase with
100100
| MaskType.None -> failwith "Not Implemented"
101101
| _ -> failwith "Not Implemented"

0 commit comments

Comments
 (0)