Skip to content

Commit 4e01885

Browse files
committed
refactor: Matrix.{MatrixFomat}
1 parent 7c21f51 commit 4e01885

7 files changed

Lines changed: 31 additions & 30 deletions

File tree

benchmarks/GraphBLAS-sharp.Benchmarks/BenchmarksMathNET.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type MathNETBenchmark<'elem when 'elem: struct and 'elem :> System.IEquatable<'e
1818

1919
static member COOMatrixToMathNETSparse matrix =
2020
match matrix with
21-
| MatrixCOO matrix ->
21+
| Matrix.COO matrix ->
2222
Matrix.Build.SparseFromCoordinateFormat(
2323
matrix.RowCount,
2424
matrix.ColumnCount,

benchmarks/GraphBLAS-sharp.Benchmarks/BenchmarksMxm.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ type MxmBenchmarks<'elem when 'elem : struct>(
107107

108108
member this.ReadMask(maskReader) =
109109
match this.ReadMatrix maskReader with
110-
| MatrixCOO m ->
110+
| Matrix.COO m ->
111111
maskHost <-
112112
{ IsComplemented = false
113113
RowCount = m.RowCount

src/GraphBLAS-sharp/IO/MtxReader.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ type MtxReader(pathToFile: string) =
119119
values.[i] <- value)
120120
sortedData
121121

122-
MatrixCOO
122+
Matrix.COO
123123
{ Rows = rows
124124
Columns = cols
125125
Values = values

src/GraphBLAS-sharp/Objects/Matrix.fs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,33 @@ type MatrixFormat =
88
| COO
99
| CSC
1010

11+
[<RequireQualifiedAccess>]
1112
type Matrix<'a when 'a: struct> =
12-
| MatrixCSR of CSRMatrix<'a>
13-
| MatrixCOO of COOMatrix<'a>
14-
| MatrixCSC of CSCMatrix<'a>
13+
| CSR of CSRMatrix<'a>
14+
| COO of COOMatrix<'a>
15+
| CSC of CSCMatrix<'a>
1516

1617
member this.RowCount =
1718
match this with
18-
| MatrixCSR matrix -> matrix.RowCount
19-
| MatrixCOO matrix -> matrix.RowCount
20-
| MatrixCSC matrix -> matrix.RowCount
19+
| CSR matrix -> matrix.RowCount
20+
| COO matrix -> matrix.RowCount
21+
| CSC matrix -> matrix.RowCount
2122

2223
member this.ColumnCount =
2324
match this with
24-
| MatrixCSR matrix -> matrix.ColumnCount
25-
| MatrixCOO matrix -> matrix.ColumnCount
26-
| MatrixCSC matrix -> matrix.ColumnCount
25+
| CSR matrix -> matrix.ColumnCount
26+
| COO matrix -> matrix.ColumnCount
27+
| CSC matrix -> matrix.ColumnCount
2728

2829
member this.NNZCount =
2930
match this with
30-
| MatrixCOO m -> m.Values.Length
31-
| MatrixCSR m -> m.Values.Length
32-
| MatrixCSC m -> m.Values.Length
31+
| COO m -> m.Values.Length
32+
| CSR m -> m.Values.Length
33+
| CSC m -> m.Values.Length
3334

3435
member this.ToBackend(context: ClContext) =
3536
match this with
36-
| MatrixCOO m ->
37+
| COO m ->
3738
let rows = context.CreateClArray m.Rows
3839
let columns = context.CreateClArray m.Columns
3940
let values = context.CreateClArray m.Values
@@ -47,7 +48,7 @@ type Matrix<'a when 'a: struct> =
4748
Values = values }
4849

4950
ClMatrix.COO result
50-
| MatrixCSR m ->
51+
| CSR m ->
5152
let rows = context.CreateClArray m.RowPointers
5253
let columns = context.CreateClArray m.ColumnIndices
5354
let values = context.CreateClArray m.Values
@@ -61,7 +62,7 @@ type Matrix<'a when 'a: struct> =
6162
Values = values }
6263

6364
ClMatrix.CSR result
64-
| MatrixCSC m ->
65+
| CSC m ->
6566
let rows = context.CreateClArray m.RowIndices
6667
let columnPtrs = context.CreateClArray m.ColumnPointers
6768
let values = context.CreateClArray m.Values
@@ -99,7 +100,7 @@ type Matrix<'a when 'a: struct> =
99100
Columns = columns
100101
Values = values }
101102

102-
MatrixCOO result
103+
COO result
103104
| ClMatrix.CSR m ->
104105
let rows = Array.zeroCreate m.RowPointers.Length
105106
let columns = Array.zeroCreate m.Columns.Length
@@ -121,7 +122,7 @@ type Matrix<'a when 'a: struct> =
121122
ColumnIndices = columns
122123
Values = values }
123124

124-
MatrixCSR result
125+
CSR result
125126
| ClMatrix.CSC m ->
126127
let rows = Array.zeroCreate m.Rows.Length
127128
let columns = Array.zeroCreate m.ColumnPointers.Length
@@ -143,7 +144,7 @@ type Matrix<'a when 'a: struct> =
143144
ColumnPointers = columns
144145
Values = values }
145146

146-
MatrixCSC result
147+
CSC result
147148

148149
and CSRMatrix<'a> =
149150
{ RowCount: int
@@ -221,7 +222,7 @@ and CSRMatrix<'a> =
221222
rowPointers
222223

223224
match matrix with
224-
| MatrixCOO m ->
225+
| Matrix.COO m ->
225226
let rowPointers =
226227
context.CreateClArray(
227228
rowIndices2rowPointers m.Rows m.RowCount,
@@ -289,7 +290,7 @@ and COOMatrix<'a> =
289290

290291
static member ToBackend (context: ClContext) matrix =
291292
match matrix with
292-
| MatrixCOO m ->
293+
| Matrix.COO m ->
293294
let rows =
294295
context.CreateClArray(
295296
m.Rows,

tests/GraphBLAS-sharp.Tests/Helpers.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,9 +661,9 @@ module Utils =
661661

662662
let createMatrixFromArray2D matrixCase array isZero =
663663
match matrixCase with
664-
| CSR -> MatrixCSR <| CSRMatrix.FromArray2D(array, isZero)
665-
| COO -> MatrixCOO <| COOMatrix.FromArray2D(array, isZero)
666-
| CSC -> MatrixCSC <| CSCMatrix.FromArray2D(array, isZero)
664+
| CSR -> Matrix.CSR <| CSRMatrix.FromArray2D(array, isZero)
665+
| COO -> Matrix.COO <| COOMatrix.FromArray2D(array, isZero)
666+
| CSC -> Matrix.CSC <| CSCMatrix.FromArray2D(array, isZero)
667667

668668
let createVectorFromArray vectorCase array isZero =
669669
match vectorCase with

tests/GraphBLAS-sharp.Tests/Matrix/Elementwise.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ let checkResult isEqual op zero (baseMtx1: 'a [,]) (baseMtx2: 'a [,]) (actual: M
3232
let actual2D = Array2D.create rows columns zero
3333

3434
match actual with
35-
| MatrixCOO actual ->
35+
| Matrix.COO actual ->
3636
for i in 0 .. actual.Rows.Length - 1 do
3737
if isEqual zero actual.Values.[i] then
3838
failwith "Resulting zeroes should be filtered."

tests/GraphBLAS-sharp.Tests/Matrix/Transpose.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ let wgSize = 32
1616

1717
let checkResult areEqual zero actual (expected2D: 'a [,]) =
1818
match actual with
19-
| MatrixCOO actual ->
19+
| Matrix.COO actual ->
2020
let expected =
2121
COOMatrix.FromArray2D(expected2D, areEqual zero)
2222

@@ -34,7 +34,7 @@ let checkResult areEqual zero actual (expected2D: 'a [,]) =
3434

3535
"Value arrays should be equal"
3636
|> compareArrays areEqual actual.Values expected.Values
37-
| MatrixCSR actual ->
37+
| Matrix.CSR actual ->
3838
let expected =
3939
CSRMatrix.FromArray2D(expected2D, areEqual zero)
4040

@@ -52,7 +52,7 @@ let checkResult areEqual zero actual (expected2D: 'a [,]) =
5252

5353
"Value arrays should be equal"
5454
|> compareArrays areEqual actual.Values expected.Values
55-
| MatrixCSC actual ->
55+
| Matrix.CSC actual ->
5656
let expected =
5757
CSCMatrix.FromArray2D(expected2D, areEqual zero)
5858

0 commit comments

Comments
 (0)