Skip to content

Commit 898c3d1

Browse files
committed
Fix mtx reader
1 parent beef3f5 commit 898c3d1

5 files changed

Lines changed: 46 additions & 22 deletions

File tree

benchmarks/GraphBLAS-sharp.Benchmarks/BenchmarksBFS.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ type BFSBenchmarks() =
5555
member this.BuildMatrixAndSetSource() =
5656
matrix <-
5757
graphblas {
58-
let matrix = this.InputMatrixReader.ReadMatrixBoolean(fun _ -> true)
58+
let matrix = this.InputMatrixReader.ReadMatrix(fun _ -> true)
5959

6060
return! Matrix.switch CSR matrix
6161
>>= Matrix.synchronizeAndReturn

benchmarks/GraphBLAS-sharp.Benchmarks/BenchmarksQG.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type QGBenchmarks() =
4949

5050
[<GlobalSetup>]
5151
member this.BuildMatrixAndSetSource() =
52-
let matrix = this.InputMatrixReader.ReadMatrixBoolean(fun _ -> true)
52+
let matrix = this.InputMatrixReader.ReadMatrix(fun _ -> true)
5353

5454
match matrix with
5555
| MatrixCSR csr -> failwith "Not implemented"

src/GraphBLAS-sharp/IO/MtxReader.fs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type MtxReader(pathToFile: string) =
4545
Nnz = nnz
4646
|}
4747

48-
member this.ReadMatrixReal() : Matrix<float32> =
48+
member this.ReadMatrixReal(converter: string -> 'a) : Matrix<'a> =
4949
if object <> MtxMatrix then failwith "Object is not matrix"
5050
if field <> Real then failwith "Field is not real"
5151

@@ -73,7 +73,7 @@ type MtxReader(pathToFile: string) =
7373
(fun line ->
7474
let i = int line.[0]
7575
let j = int line.[1]
76-
let v = float32 line.[2]
76+
let v = converter line.[2]
7777
struct(pack i j, v)
7878
)
7979
|> Array.sortBy (fun struct(packedIndex, _) -> packedIndex)
@@ -102,9 +102,9 @@ type MtxReader(pathToFile: string) =
102102
| Coordinate -> matrixFromCoordinateFormat ()
103103
| Array -> failwith "Unsupported matrix format"
104104

105-
member this.ReadMatrixBoolean(converter: string -> bool) : Matrix<bool> =
105+
member this.ReadMatrixBoolean(converter: string -> 'a) : Matrix<'a> =
106106
if object <> MtxMatrix then failwith "Object is not matrix"
107-
// if field <> f then failwith "Field is not mmm"
107+
if field <> Pattern then failwith "Field is not boolean"
108108

109109
use streamReader = new StreamReader(pathToFile)
110110
while streamReader.Peek() = int '%' do
@@ -130,7 +130,7 @@ type MtxReader(pathToFile: string) =
130130
(fun line ->
131131
let i = int line.[0]
132132
let j = int line.[1]
133-
let v = converter line.[2]
133+
let v = converter ""
134134
struct(pack i j, v)
135135
)
136136
|> Array.sortBy (fun struct(packedIndex, _) -> packedIndex)
@@ -159,6 +159,12 @@ type MtxReader(pathToFile: string) =
159159
| Coordinate -> matrixFromCoordinateFormat ()
160160
| Array -> failwith "Unsupported matrix format"
161161

162+
member this.ReadMatrix(converter: string -> 'a) : Matrix<'a> =
163+
match field with
164+
| Real -> this.ReadMatrixReal(converter)
165+
| Pattern -> this.ReadMatrixBoolean(converter)
166+
| _ -> failwith "Not implemented"
167+
162168
and MtxObject =
163169
| MtxMatrix
164170
| MtxVector

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let testCases = [
1717
let expected =
1818
graphblas {
1919
let! matrix =
20-
MtxReader("arc130.mtx").ReadMatrixBoolean(fun _ -> true)
20+
MtxReader("arc130.mtx").ReadMatrixReal(fun _ -> true)
2121
|> Matrix.switch CSR
2222

2323
return!

tests/GraphBLAS-sharp.Tests/Program.fs

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,39 @@ open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
66
open GraphBLAS.FSharp.Backend.Common
77
open Brahma.FSharp.OpenCL.Core
88
open OpenCL.Net
9+
open GraphBLAS.FSharp
10+
open GraphBLAS.FSharp.Algorithms
11+
open GraphBLAS.FSharp.IO
912

10-
[<Tests>]
11-
let allTests =
12-
testList "All tests" [
13-
Backend.PrefixSum.tests
14-
Backend.BitonicSort.tests
15-
Backend.RemoveDuplicates.tests
16-
Matrix.GetTuples.tests
17-
Matrix.Mxv.tests
18-
Matrix.Transpose.tests
19-
Algo.Bfs.tests
20-
]
21-
|> testSequenced
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
2225

2326
[<EntryPoint>]
2427
let main argv =
25-
allTests
26-
|> runTestsWithCLIArgs [] argv
28+
// allTests
29+
// |> runTestsWithCLIArgs [] argv
30+
31+
graphblas {
32+
let! matrix =
33+
MtxReader("arc130.mtx").ReadMatrixReal(fun _ -> true)
34+
|> Matrix.switch CSR
35+
36+
return!
37+
BFS.levelSingleSource matrix 0
38+
>>= Vector.synchronizeAndReturn
39+
}
40+
|> EvalGB.withClContext (OpenCLEvaluationContext())
41+
|> EvalGB.runSync
42+
|> ignore
43+
44+
0

0 commit comments

Comments
 (0)