Skip to content

Commit acaa0c1

Browse files
committed
fix: host COO -> CSR
1 parent ad9b528 commit acaa0c1

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

src/GraphBLAS-sharp/Objects/Matrix.fs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,12 @@ module Matrix =
9393

9494
member this.ToCSR =
9595
let rowPointers =
96-
let nnzPerRow = Array.zeroCreate this.RowCount
97-
let rowPointers = Array.zeroCreate this.RowCount
96+
let pointers = Array.zeroCreate this.RowCount
9897

99-
Array.iter (fun rowIndex -> nnzPerRow.[rowIndex] <- nnzPerRow.[rowIndex] + 1) this.Rows
98+
Array.countBy id this.Rows
99+
|> Array.iter (fun (index, count) -> pointers.[index] <- count)
100100

101-
for i in 1 .. this.RowCount - 1 do
102-
rowPointers.[i] <- rowPointers.[i - 1] + nnzPerRow.[i - 1]
103-
104-
rowPointers
101+
Array.scan (+) 0 pointers
105102

106103
{ RowCount = this.RowCount
107104
ColumnCount = this.ColumnCount
@@ -128,7 +125,7 @@ module Matrix =
128125
|> List.mapi (fun i x -> (x, i))
129126
|> List.filter (fun pair -> not <| isZero (fst pair)))
130127
|> List.fold
131-
(fun (colPtrs, valueInx) col -> ((colPtrs.Head + col.Length) :: colPtrs), valueInx @ col)
128+
(fun (colPointers, valueInx) col -> ((colPointers.Head + col.Length) :: colPointers), valueInx @ col)
132129
([ 0 ], [])
133130

134131
{ Values =

0 commit comments

Comments
 (0)