Skip to content

Commit ec125c0

Browse files
committed
Change matrix build module
1 parent 1a6a787 commit ec125c0

7 files changed

Lines changed: 59 additions & 81 deletions

File tree

benchmarks/GraphBLAS-sharp.Benchmarks/BenchmarksBFS.fs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ open BenchmarkDotNet.Configs
77
open BenchmarkDotNet.Columns
88
open System.IO
99
open System
10-
open MatrixBackend
1110

1211
[<SimpleJob(targetCount=10)>]
1312
type BFSBenchmark4CSRMatrix() =
@@ -21,7 +20,7 @@ type BFSBenchmark4CSRMatrix() =
2120

2221
[<GlobalSetup>]
2322
member this.BuildMatrix() =
24-
matrix <- Matrix.Build<bool>(this.PathToGraph, CSR)
23+
matrix <- Matrix.fromFile this.PathToGraph CSR
2524
source <- random.Next matrix.RowCount
2625

2726
[<Benchmark>]

benchmarks/GraphBLAS-sharp.Benchmarks/BenchmarksEWiseAdd.fs

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ open System.IO
44
open System.Text.RegularExpressions
55
open GraphBLAS.FSharp
66
open GraphBLAS.FSharp.Predefined
7-
open GraphBLAS.FSharp.MatrixBackend
87
open BenchmarkDotNet.Attributes
98
open BenchmarkDotNet.Configs
109
open BenchmarkDotNet.Columns
@@ -131,14 +130,13 @@ type EWiseAddBenchmarks4Float32() =
131130
Array.blit this.FirstMatrix.Values 0 leftVals 0 this.FirstMatrix.Values.Length
132131

133132
leftCOO <-
134-
Matrix.Build<float32>(
135-
this.FirstMatrix.RowCount,
136-
this.FirstMatrix.ColumnCount,
137-
leftRows,
138-
leftCols,
139-
leftVals,
133+
Matrix.build
134+
this.FirstMatrix.RowCount
135+
this.FirstMatrix.ColumnCount
136+
leftRows
137+
leftCols
138+
leftVals
140139
COO
141-
)
142140

143141
let rightRows = Array.zeroCreate<int> this.SecondMatrix.Rows.Length
144142
let rightCols = Array.zeroCreate<int> this.SecondMatrix.Columns.Length
@@ -148,14 +146,13 @@ type EWiseAddBenchmarks4Float32() =
148146
Array.blit this.SecondMatrix.Values 0 rightVals 0 this.SecondMatrix.Values.Length
149147

150148
rightCOO <-
151-
Matrix.Build<float32>(
152-
this.SecondMatrix.RowCount,
153-
this.SecondMatrix.ColumnCount,
154-
rightRows,
155-
rightCols,
156-
rightVals,
149+
Matrix.build
150+
this.SecondMatrix.RowCount
151+
this.SecondMatrix.ColumnCount
152+
rightRows
153+
rightCols
154+
rightVals
157155
COO
158-
)
159156

160157
[<Benchmark>]
161158
member this.EWiseAdditionCOOFloat32() =
@@ -204,14 +201,13 @@ type EWiseAddBenchmarks4Bool() =
204201
Array.blit this.FirstMatrix.Columns 0 leftCols 0 this.FirstMatrix.Columns.Length
205202

206203
leftCOO <-
207-
Matrix.Build<bool>(
208-
this.FirstMatrix.RowCount,
209-
this.FirstMatrix.ColumnCount,
210-
leftRows,
211-
leftCols,
212-
leftVals,
204+
Matrix.build
205+
this.FirstMatrix.RowCount
206+
this.FirstMatrix.ColumnCount
207+
leftRows
208+
leftCols
209+
leftVals
213210
COO
214-
)
215211

216212
let rightRows = Array.zeroCreate<int> this.SecondMatrix.Rows.Length
217213
let rightCols = Array.zeroCreate<int> this.SecondMatrix.Columns.Length
@@ -220,14 +216,13 @@ type EWiseAddBenchmarks4Bool() =
220216
Array.blit this.SecondMatrix.Columns 0 rightCols 0 this.SecondMatrix.Columns.Length
221217

222218
rightCOO <-
223-
Matrix.Build<bool>(
224-
this.SecondMatrix.RowCount,
225-
this.SecondMatrix.ColumnCount,
226-
rightRows,
227-
rightCols,
228-
rightVals,
219+
Matrix.build
220+
this.SecondMatrix.RowCount
221+
this.SecondMatrix.ColumnCount
222+
rightRows
223+
rightCols
224+
rightVals
229225
COO
230-
)
231226

232227
[<Benchmark>]
233228
member this.EWiseAdditionCOOBool() =

src/GraphBLAS-sharp/GlobalContext.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@ module GlobalContext =
99
| COO
1010
| Dense
1111

12+
type VectorBackendFormat =
13+
| Sparse
14+
| Dense
15+
1216
let mutable oclContext = OpenCLEvaluationContext()
1317
let mutable matrixBackendFormat = CSR

src/GraphBLAS-sharp/Implementations.fs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,24 @@ open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
1111
open Toolbox
1212

1313
type COOFormat<'a> = {
14+
RowCount: int
15+
ColumnCount: int
1416
Rows: int[]
1517
Columns: int[]
1618
Values: 'a[]
17-
RowCount: int
18-
ColumnCount: int
1919
}
2020

2121
type CSRFormat<'a> = {
22-
Values: 'a[]
23-
Columns: int[]
24-
RowPointers: int[]
2522
ColumnCount: int
23+
RowPointers: int[]
24+
ColumnIndices: int[]
25+
Values: 'a[]
2626
}
2727
with
2828
static member CreateEmpty<'a>() = {
29-
Values = Array.zeroCreate<'a> 0
30-
Columns = Array.zeroCreate<int> 0
3129
RowPointers = Array.zeroCreate<int> 0
30+
ColumnIndices = Array.zeroCreate<int> 0
31+
Values = Array.zeroCreate<'a> 0
3232
ColumnCount = 0
3333
}
3434

@@ -74,7 +74,7 @@ type CSRMatrix<'a when 'a : struct and 'a : equality>(csrTuples: CSRFormat<'a>)
7474
ndRange
7575
resultVector
7676
csrTuples.Values
77-
csrTuples.Columns
77+
csrTuples.ColumnIndices
7878
csrTuples.RowPointers
7979
vector.Values
8080

@@ -87,7 +87,7 @@ type CSRMatrix<'a when 'a : struct and 'a : equality>(csrTuples: CSRFormat<'a>)
8787
new(rows: int[], columns: int[], values: 'a[]) = CSRMatrix(CSRFormat.CreateEmpty())
8888

8989
member this.Values = csrTuples.Values
90-
member this.Columns = csrTuples.Columns
90+
member this.Columns = csrTuples.ColumnIndices
9191
member this.RowPointers = csrTuples.RowPointers
9292

9393
override this.Clear () = failwith "Not Implemented"

src/GraphBLAS-sharp/Matrix.fs

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,23 @@
11
namespace GraphBLAS.FSharp
22

3-
module MatrixBackend =
4-
type Matrix<'a when 'a : struct and 'a : equality> with
5-
static member Build(denseMatrix: 'T[,], zero: 'T, matrixType: MatrixBackendFormat) : Matrix<'T> =
6-
failwith "Not Implemented"
7-
8-
static member Build(rowCount: int, columnCount: int, rows: int[], columns: int[], values: 'T[], matrixType: MatrixBackendFormat) : Matrix<'T> =
9-
match matrixType with
10-
| CSR -> upcast CSRMatrix(rows, columns, values)
11-
| COO -> upcast COOMatrix(rowCount, columnCount, rows, columns, values)
12-
| _ -> failwith "Not Implemented"
13-
14-
static member Build(pathToMatrix: string, matrixType: MatrixBackendFormat) : Matrix<'T> =
15-
failwith "Not Implemented"
16-
17-
static member Build(rowCount: int, columnCount: int, initializer: int -> int -> 'T, matrixType: MatrixBackendFormat) : Matrix<'T> =
18-
failwith "Not Implemented"
19-
20-
static member ZeroCreate(rowCount: int, columnCount: int, matrixType: MatrixBackendFormat) : Matrix<'T> =
21-
failwith "Not Implemented"
22-
23-
[<AutoOpen>]
24-
module MatrixExtensions =
25-
open MatrixBackend
26-
type Matrix<'a when 'a : struct and 'a : equality> with
27-
static member Build(denseMatrix: 'T[,], zero: 'T) : Matrix<'T> =
28-
Matrix.Build(denseMatrix, zero, matrixBackendFormat)
3+
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
4+
module Matrix =
5+
let toSeq (matrix: Matrix<'a>) = failwith "Not Implemented"
296

30-
static member Build(rowCount: int, columnCount: int, rows: int[], columns: int[], values: 'T[]) : Matrix<'T> =
31-
Matrix.Build(rowCount, columnCount, rows, columns, values)
7+
let build (rowCount: int) (columnCount: int) (rows: int[]) (columns: int[]) (values: 'a[]) (matrixType: MatrixBackendFormat) : Matrix<'a> =
8+
match matrixType with
9+
| CSR -> upcast CSRMatrix(rows, columns, values)
10+
| COO -> upcast COOMatrix(rowCount, columnCount, rows, columns, values)
11+
| _ -> failwith "Not Implemented"
3212

33-
static member Build(pathToMatrix: string) : Matrix<'T> =
34-
Matrix.Build(pathToMatrix, matrixBackendFormat)
13+
let ofArray2D (array: 'a[,]) (zero: 'a) (matrixType: MatrixBackendFormat) : Matrix<'a> =
14+
failwith "Not Implemented yet"
3515

36-
static member Build(rowCount: int, columnCount: int, initializer: int -> int -> 'T) : Matrix<'T> =
37-
Matrix.Build(rowCount, columnCount, initializer, matrixBackendFormat)
16+
let fromFile (pathToMatrix: string) (matrixType: MatrixBackendFormat) : Matrix<'a> =
17+
failwith "Not Implemented yet"
3818

39-
static member ZeroCreate(rowCount: int, columnCount: int) : Matrix<'T> =
40-
Matrix.ZeroCreate(rowCount, columnCount)
19+
let init (rowCount: int) (columnCount: int) (initializer: int -> int -> 'a) (matrixType: MatrixBackendFormat) : Matrix<'a> =
20+
failwith "Not Implemented yet"
4121

42-
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
43-
module Matrix =
44-
let toSeq (matrix: Matrix<'a>) = failwith "Not Implemented"
22+
let zeroCreate (rowCount: int) (columnCount: int) (matrixType: MatrixBackendFormat) : Matrix<'a> =
23+
failwith "Not Implemented yet"

src/GraphBLAS-sharp/Vector.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ module VectorExtensions =
2727
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
2828
module Vector =
2929
let toSeq (vector: Vector<'a>) = failwith "Not Implemented"
30+
31+
let ofArray (denseVector: 'a[]) (zero: 'a) (vectorFormat : VectorBackendFormat) : Vector<'a> =
32+
failwith "Not Implemented"

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ type MatrixMultiplicationPair =
5454
|> Arb.fromGen
5555

5656
module VxmTests =
57-
open MatrixBackend
58-
5957
let config = {
6058
FsCheckConfig.defaultConfig with
6159
arbitrary = [ typeof<MatrixMultiplicationPair> ]
@@ -104,7 +102,7 @@ module VxmTests =
104102
[
105103
testPropertyWithConfig config "Dimensional mismatch should raise an exception" <|
106104
fun matrixRowCount matrixColumnCount vectorSize ->
107-
let emptyMatrix = Matrix.ZeroCreate(matrixRowCount, matrixColumnCount, matrixBackend)
105+
let emptyMatrix = Matrix.zeroCreate matrixRowCount matrixColumnCount matrixBackend
108106
let emptyVector = zeroVectorConstructor vectorSize
109107

110108
Expect.throwsT<System.ArgumentException>
@@ -119,7 +117,7 @@ module VxmTests =
119117

120118
testPropertyWithConfig config "Operation should have correct semantic" <|
121119
fun (denseMatrix: float[,]) (denseVector: float[]) ->
122-
let matrix = Matrix.Build(denseMatrix, 0., matrixBackend)
120+
let matrix = Matrix.ofArray2D denseMatrix 0. matrixBackend
123121
let vector = vectorConstructor denseVector
124122
let result =
125123
opencl {

0 commit comments

Comments
 (0)