@@ -3,7 +3,6 @@ namespace GraphBLAS.FSharp
33open Brahma.OpenCL
44open Brahma.FSharp .OpenCL .Core
55open Brahma.FSharp .OpenCL .Extensions
6- open GlobalContext
76open Helpers
87open FSharp.Quotations .Evaluator
98open Brahma.FSharp .OpenCL .WorkflowBuilder .Basic
@@ -85,6 +84,7 @@ type CSRMatrix<'a when 'a : struct and 'a : equality>(csrTuples: CSRFormat<'a>)
8584
8685 // Not Implemented
8786 new ( rows: int[], columns: int[], values: 'a[]) = CSRMatrix( CSRFormat.CreateEmpty())
87+ new ( pathToMatrix: string) = CSRMatrix( CSRFormat.CreateEmpty())
8888
8989 member this.Values = csrTuples.Values
9090 member this.Columns = csrTuples.ColumnIndices
@@ -128,6 +128,27 @@ and COOMatrix<'a when 'a : struct and 'a : equality>(rowCount: int, columnCount:
128128 inherit Matrix< 'a>( rowCount, columnCount)
129129
130130 let mutable rows , columns , values = rows, columns, values
131+
132+ new ( array: 'a[,], isZero: 'a -> bool) =
133+ let ( rows , cols , vals ) =
134+ array
135+ |> Seq.cast< 'a>
136+ |> Seq.mapi ( fun idx v -> ( idx / Array2D.length2 array, idx % Array2D.length2 array, v))
137+ |> Seq.filter ( fun ( i , j , v ) -> not <| isZero v)
138+ |> Array.ofSeq
139+ |> Array.unzip3
140+
141+ COOMatrix( Array2D.length1 array, Array2D.length2 array, rows, cols, vals)
142+
143+ override this.ToString () =
144+ [
145+ sprintf " COO Matrix %i x%i \n " rowCount columnCount
146+ sprintf " RowIndices: %A \n " rows
147+ sprintf " ColumnIndices: %A \n " columns
148+ sprintf " Values: %A \n " values
149+ ]
150+ |> String.concat " "
151+
131152 member this.Rows with get() = rows
132153 member this.Columns with get() = columns
133154 member this.Values with get() = values
@@ -138,23 +159,25 @@ and COOMatrix<'a when 'a : struct and 'a : equality>(rowCount: int, columnCount:
138159 override this.Resize a b = failwith " Not Implemented"
139160 override this.GetNNZ () = failwith " Not Implemented"
140161
141- override this.GetTuples () =
142- opencl {
143- return {| Rows = this.Rows; Columns = this.Columns; Values = this.Values |}
162+ override this.GetTuples () = opencl {
163+ return {
164+ RowIndices = this.Rows
165+ ColumnIndices = this.Columns
166+ Values = this.Values
144167 }
168+ }
145169
146170 override this.GetMask (? isComplemented : bool ) =
147171 let isComplemented = defaultArg isComplemented false
148172 failwith " Not Implemented"
149173
150- override this.ToHost () =
151- opencl {
152- let! _ = ToHost this.Rows
153- let! _ = ToHost this.Columns
154- let! _ = ToHost this.Values
174+ override this.ToHost () = opencl {
175+ let! _ = ToHost this.Rows
176+ let! _ = ToHost this.Columns
177+ let! _ = ToHost this.Values
155178
156- return upcast this
157- }
179+ return upcast this
180+ }
158181
159182 override this.Extract ( mask : Mask2D option ) : OpenCLEvaluation < Matrix < 'a >> = failwith " Not Implemented"
160183 override this.Extract ( colMask : Mask1D option * int ) : OpenCLEvaluation < Vector < 'a >> = failwith " Not Implemented"
0 commit comments