Skip to content

Commit 2e0dfe8

Browse files
committed
Add impl of Matrix.tuples for COOMatrix
1 parent 048949c commit 2e0dfe8

6 files changed

Lines changed: 69 additions & 40 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace GraphBLAS.FSharp.Backend.COOMatrix
2+
3+
open Brahma.FSharp.OpenCL.WorkflowBuilder.Basic
4+
open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
5+
open GraphBLAS.FSharp
6+
7+
module internal GetTuples =
8+
let from (matrix: COOMatrix<'a>) = opencl {
9+
return {
10+
RowIndices = matrix.Rows
11+
ColumnIndices = matrix.Columns
12+
Values = matrix.Values
13+
}
14+
}

src/GraphBLAS-sharp/GraphBLAS-sharp.fsproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@
1414
<Compile Include="AlgebraicStructures.fs" />
1515
<Compile Include="GraphblasEvaluation.fs" />
1616
<Compile Include="Objects/Matrix.fs" />
17+
<Compile Include="Objects\MatrixTuples.fs" />
1718
<Compile Include="Objects/Vector.fs" />
19+
<Compile Include="Objects\VectorTuples.fs" />
1820
<Compile Include="Objects/Scalar.fs" />
1921
<Compile Include="Objects/Masks.fs" />
2022
<Compile Include="Backend/Common/Utils.fs" />
2123
<Compile Include="Backend/Common/Scan.fs" />
24+
<Compile Include="Backend\COOMatrix\GetTuples.fs" />
2225
<Compile Include="Backend/COOMatrix/EWiseAdd.fs" />
2326
<Compile Include="Methods/Matrix.fs" />
2427
<Compile Include="Methods/Vector.fs" />
@@ -36,4 +39,4 @@
3639
</Content>
3740
</ItemGroup>
3841
<Import Project="..\..\.paket\Paket.Restore.targets" />
39-
</Project>
42+
</Project>

src/GraphBLAS-sharp/Methods/Matrix.fs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,6 @@ namespace GraphBLAS.FSharp
33
open Brahma.FSharp.OpenCL.WorkflowBuilder.Basic
44
open GraphBLAS.FSharp.Backend
55

6-
type MatrixTuples<'a> =
7-
{
8-
RowIndices: int[]
9-
ColumnIndices: int[]
10-
Values: 'a[]
11-
}
12-
13-
// ждём тайпклассов чтобы можно было вызывать synchronize для всех объектов,
14-
// для которых он реализован, не привязывая реализацию к классу (как стратегия)
15-
module MatrixTuples =
16-
let synchronize (matrixTuples: MatrixTuples<'a>) =
17-
opencl {
18-
let! _ = ToHost matrixTuples.RowIndices
19-
let! _ = ToHost matrixTuples.ColumnIndices
20-
let! _ = ToHost matrixTuples.Values
21-
return ()
22-
}
23-
|> EvalGB.fromCl
24-
256
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
267
module Matrix =
278

@@ -54,7 +35,15 @@ module Matrix =
5435
let copy (matrix: Matrix<'a>) : GraphblasEvaluation<Matrix<'a>> = failwith "Not Implemented yet"
5536
let resize (rowCount: int) (columnCount: int) (matrix: Matrix<'a>) : GraphblasEvaluation<Matrix<'a>> = failwith "Not Implemented yet"
5637
let nnz (matrix: Matrix<'a>) : GraphblasEvaluation<int> = failwith "Not Implemented yet"
57-
let tuples (matrix: Matrix<'a>) : GraphblasEvaluation<MatrixTuples<'a>> = failwith "Not Implemented yet"
38+
39+
let tuples (matrix: Matrix<'a>) : GraphblasEvaluation<MatrixTuples<'a>> =
40+
let matrixTuples =
41+
match matrix with
42+
| MatrixCOO coo -> COOMatrix.GetTuples.from coo
43+
| _ -> failwith "Not Implemented"
44+
45+
graphblas { return! EvalGB.fromCl matrixTuples }
46+
5847
let mask (matrix: Matrix<'a>) : GraphblasEvaluation<Mask2D> = failwith "Not Implemented yet"
5948
let complemented (matrix: Matrix<'a>) : GraphblasEvaluation<Mask2D> = failwith "Not Implemented yet"
6049
let synchronize (matrix: Matrix<'a>) : GraphblasEvaluation<unit> = failwith "Not Implemented yet"

src/GraphBLAS-sharp/Methods/Vector.fs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,5 @@
11
namespace GraphBLAS.FSharp
22

3-
open Brahma.FSharp.OpenCL.WorkflowBuilder.Basic
4-
open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
5-
open GraphBLAS.FSharp.Backend
6-
7-
type VectorTuples<'a> =
8-
{
9-
Indices: int[]
10-
Values: 'a[]
11-
}
12-
13-
module VectorTuples =
14-
let synchronize (vectorTuples: VectorTuples<'a>) =
15-
opencl {
16-
let! _ = ToHost vectorTuples.Indices
17-
let! _ = ToHost vectorTuples.Values
18-
return ()
19-
}
20-
|> EvalGB.fromCl
21-
223
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
234
module Vector =
245

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace GraphBLAS.FSharp
2+
3+
open Brahma.FSharp.OpenCL.WorkflowBuilder.Basic
4+
open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
5+
6+
type MatrixTuples<'a> =
7+
{
8+
RowIndices: int[]
9+
ColumnIndices: int[]
10+
Values: 'a[]
11+
}
12+
13+
// ждём тайпклассов чтобы можно было вызывать synchronize для всех объектов,
14+
// для которых он реализован, не привязывая реализацию к классу (как стратегия)
15+
module MatrixTuples =
16+
let synchronize (matrixTuples: MatrixTuples<'a>) =
17+
opencl {
18+
let! _ = ToHost matrixTuples.RowIndices
19+
let! _ = ToHost matrixTuples.ColumnIndices
20+
let! _ = ToHost matrixTuples.Values
21+
return ()
22+
}
23+
|> EvalGB.fromCl
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace GraphBLAS.FSharp
2+
3+
open Brahma.FSharp.OpenCL.WorkflowBuilder.Basic
4+
open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
5+
6+
type VectorTuples<'a> =
7+
{
8+
Indices: int[]
9+
Values: 'a[]
10+
}
11+
12+
module VectorTuples =
13+
let synchronize (vectorTuples: VectorTuples<'a>) =
14+
opencl {
15+
let! _ = ToHost vectorTuples.Indices
16+
let! _ = ToHost vectorTuples.Values
17+
return ()
18+
}
19+
|> EvalGB.fromCl

0 commit comments

Comments
 (0)