Skip to content

Commit 655fe67

Browse files
committed
refactor: list instead array in LIL
1 parent efa50f4 commit 655fe67

8 files changed

Lines changed: 15 additions & 17 deletions

File tree

src/GraphBLAS-sharp.Backend/Matrix/CSR/Matrix.fs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,15 @@ module Matrix =
149149
fun (processor: MailboxProcessor<_>) allocationMode (matrix: ClMatrix.CSR<'a>) ->
150150
runLazy processor allocationMode matrix
151151
|> Seq.map (fun lazyValue -> lazyValue.Value)
152-
|> Seq.toArray
153152

154153
let toLIL (clContext: ClContext) workGroupSize =
155154

156155
let byRows = byRows clContext workGroupSize
157156

158157
fun (processor: MailboxProcessor<_>) allocationMode (matrix: ClMatrix.CSR<'a>) ->
159-
let rows = byRows processor allocationMode matrix
158+
let rows =
159+
byRows processor allocationMode matrix
160+
|> Seq.toList
160161

161162
{ Context = clContext
162163
RowCount = matrix.RowCount

src/GraphBLAS-sharp.Backend/Matrix/LIL/Matrix.fs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,20 @@ module Matrix =
1616

1717
let rowsPointers =
1818
matrix.Rows
19-
|> Array.map
19+
|> List.map
2020
(function
2121
| None -> 0
2222
| Some vector -> vector.Values.Length)
23+
|> List.toArray
2324
// prefix sum
2425
|> Array.scan (+) 0
2526
|> fun pointers -> clContext.CreateClArrayWithSpecificAllocationMode(allocationMode, pointers)
2627

2728
let valuesByRows, columnsIndicesByRows =
2829
matrix.Rows
29-
|> Array.choose id
30-
|> Array.map (fun vector -> vector.Values, vector.Indices)
31-
|> Array.unzip
30+
|> List.choose id
31+
|> List.map (fun vector -> vector.Values, vector.Indices)
32+
|> List.unzip
3233

3334
let values =
3435
concatValues processor allocationMode valuesByRows

src/GraphBLAS-sharp.Backend/Matrix/Matrix.fs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ module Matrix =
4646
Values = copyData processor allocationMode m.Values }
4747
| ClMatrix.LIL matrix ->
4848
matrix.Rows
49-
|> Array.map (
50-
Option.bind
51-
<| (Some << (vectorCopy processor allocationMode))
52-
)
49+
|> List.map (Option.map (vectorCopy processor allocationMode))
5350
|> fun rows ->
5451
{ Context = clContext
5552
RowCount = matrix.RowCount

src/GraphBLAS-sharp.Backend/Matrix/SpGeMM/Expand.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ module Expand =
310310

311311
result)
312312
lazyRow.Value)
313-
|> Seq.toArray
313+
|> Seq.toList
314314
|> fun rows ->
315315
rightMatrixRowsLengths.Free processor
316316

src/GraphBLAS-sharp.Backend/Objects/Matrix.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ module ClMatrix =
8686
{ Context: ClContext
8787
RowCount: int
8888
ColumnCount: int
89-
Rows: ClVector.Sparse<'elem> option []
89+
Rows: ClVector.Sparse<'elem> option list
9090
NNZ: int }
9191

9292
interface IDeviceMemObject with

src/GraphBLAS-sharp/Objects/Matrix.fs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ module Matrix =
155155
type LIL<'a when 'a: struct> =
156156
{ RowCount: int
157157
ColumnCount: int
158-
Rows: Vector.Sparse<'a> option []
158+
Rows: Vector.Sparse<'a> option list
159159
NNZ: int }
160160

161161
static member FromArray2D(array: 'a [,], isZero: 'a -> bool) =
@@ -172,7 +172,6 @@ module Matrix =
172172
Some vector
173173
else
174174
None ]
175-
|> Array.ofList
176175

177176
{ RowCount = Array2D.length1 array
178177
ColumnCount = Array2D.length2 array
@@ -183,7 +182,7 @@ module Matrix =
183182

184183
let rows =
185184
this.Rows
186-
|> Array.map (Option.bind (fun vector -> Some <| vector.ToDevice(context)))
185+
|> List.map (Option.map (fun vector -> vector.ToDevice(context)))
187186

188187
{ Context = context
189188
RowCount = this.RowCount

src/GraphBLAS-sharp/Objects/MatrixExtensions.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module MatrixExtensions =
3636
ColumnCount = m.ColumnCount
3737
Rows =
3838
m.Rows
39-
|> Array.map (Option.bind (fun row -> Some <| row.ToHost q))
39+
|> List.map (Option.map (fun row -> row.ToHost q))
4040
NNZ = m.NNZ }
4141
|> Matrix.LIL
4242

tests/GraphBLAS-sharp.Tests/Helpers.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ module Utils =
137137
"Rows count must be the same"
138138
|> Expect.equal actual.RowCount expected.RowCount
139139

140-
Array.iter2
140+
List.iter2
141141
(fun actualRow expected ->
142142
match actualRow, expected with
143143
| Some actualVector, Some expectedVector -> compareSparseVectors isEqual actualVector expectedVector

0 commit comments

Comments
 (0)