11namespace GraphBLAS.FSharp
22
33open Brahma.FSharp .OpenCL .WorkflowBuilder .Evaluation
4+ open Brahma.FSharp .OpenCL .WorkflowBuilder .Basic
5+
6+ type MatrixTuples < 'a when 'a : struct and 'a : equality > = {
7+ RowIndices: int []
8+ ColumnIndices: int []
9+ Values: 'a []
10+ }
11+ with
12+ member this.ToHost () = opencl {
13+ let! rows = ToHost this.RowIndices
14+ let! cols = ToHost this.ColumnIndices
15+ let! vals = ToHost this.Values
16+
17+ return {
18+ RowIndices = rows
19+ ColumnIndices = cols
20+ Values = vals
21+ }
22+ }
423
524[<AbstractClass>]
625type Matrix < 'a when 'a : struct and 'a : equality >( nrow : int , ncol : int ) =
@@ -13,7 +32,7 @@ type Matrix<'a when 'a : struct and 'a : equality>(nrow: int, ncol: int) =
1332 abstract Copy: unit -> OpenCLEvaluation < Matrix < 'a >>
1433 abstract Resize: int -> int -> OpenCLEvaluation < Matrix < 'a >>
1534 abstract GetNNZ: unit -> OpenCLEvaluation < int >
16- abstract GetTuples: unit -> OpenCLEvaluation <{| Rows : int []; Columns : int []; Values : 'a [] |} >
35+ abstract GetTuples: unit -> OpenCLEvaluation < MatrixTuples < 'a > >
1736 abstract GetMask: ? isComplemented : bool -> OpenCLEvaluation < Mask2D option >
1837 abstract ToHost: unit -> OpenCLEvaluation < Matrix < 'a >>
1938
@@ -41,11 +60,6 @@ type Matrix<'a when 'a : struct and 'a : equality>(nrow: int, ncol: int) =
4160 abstract Transpose: unit -> OpenCLEvaluation < Matrix < 'a >>
4261 abstract Kronecker: Matrix < 'a > -> Mask2D option -> Semiring < 'a > -> OpenCLEvaluation < Matrix < 'a >>
4362
44- static member inline (+) ( x : Matrix < 'a >, y : Matrix < 'a >) = x.EWiseAdd y
45- static member inline (*) ( x : Matrix < 'a >, y : Matrix < 'a >) = x.EWiseMult y
46- static member inline (@.) ( x : Matrix < 'a >, y : Matrix < 'a >) = x.Mxm y
47- static member inline (@.) ( x : Matrix < 'a >, y : Vector < 'a >) = x.Mxv y
48-
4963and [<AbstractClass>] Vector < 'a when 'a : struct and 'a : equality >( size : int ) =
5064 abstract Size: int
5165 default this.Size = size
@@ -71,10 +85,6 @@ and [<AbstractClass>] Vector<'a when 'a : struct and 'a : equality>(size: int) =
7185 abstract Prune: Mask1D option -> UnaryOp < 'a , bool > -> OpenCLEvaluation < Vector < 'a >>
7286 abstract Reduce: Monoid < 'a > -> OpenCLEvaluation < Scalar < 'a >>
7387
74- static member inline (+) ( x : Vector < 'a >, y : Vector < 'a >) = x.EWiseAdd y
75- static member inline (*) ( x : Vector < 'a >, y : Vector < 'a >) = x.EWiseMult y
76- static member inline (@.) ( x : Vector < 'a >, y : Matrix < 'a >) = x.Vxm y
77-
7888and Mask1D ( indices : int [], size : int , isComplemented : bool ) =
7989 member this.Indices = indices
8090 member this.Size = size
@@ -86,3 +96,25 @@ and Mask2D(rowIndices: int[], columnIndices: int[], rowCount: int, columnCount:
8696 member this.RowCount = rowCount
8797 member this.ColumnCount = columnCount
8898 member this.IsComplemented = isComplemented
99+
100+ type COOFormat < 'a > = {
101+ RowCount: int
102+ ColumnCount: int
103+ Rows: int []
104+ Columns: int []
105+ Values: 'a []
106+ }
107+
108+ type CSRFormat < 'a > = {
109+ ColumnCount: int
110+ RowPointers: int []
111+ ColumnIndices: int []
112+ Values: 'a []
113+ }
114+ with
115+ static member CreateEmpty < 'a >() = {
116+ RowPointers = Array.zeroCreate< int> 0
117+ ColumnIndices = Array.zeroCreate< int> 0
118+ Values = Array.zeroCreate< 'a> 0
119+ ColumnCount = 0
120+ }
0 commit comments