Skip to content

Commit 2dcc09b

Browse files
committed
refactor: ClArray.map
1 parent 89b3546 commit 2dcc09b

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

src/GraphBLAS-sharp.Backend/Common/ClArray.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ module ClArray =
324324
clContext.CreateClArrayWithFlag(flag, inputArray.Length)
325325

326326
let ndRange =
327-
Range1D.CreateValid(workGroupSize, inputArray.Length)
327+
Range1D.CreateValid(inputArray.Length, workGroupSize)
328328

329329
let kernel = kernel.GetKernel()
330330

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,34 @@ module Vector =
2828
| Dense -> ClVector.Dense <| zeroCreate processor size
2929

3030
let ofList (clContext: ClContext) workGroupSize flag =
31-
3231
let scatter =
3332
Scatter.runInplace clContext workGroupSize
3433

34+
let zeroCreate = ClArray.zeroCreate clContext workGroupSize flag
35+
3536
let map =
3637
ClArray.map clContext workGroupSize GPUOnly <@ Some @>
3738

3839
fun (processor: MailboxProcessor<_>) format size (elements: (int * 'a) list) ->
39-
let indices, values =
40-
elements
41-
|> Array.ofList
42-
|> Array.sortBy fst
43-
|> Array.unzip
44-
4540
match format with
4641
| Sparse ->
42+
let indices, values =
43+
elements
44+
|> Array.ofList
45+
|> Array.sortBy fst
46+
|> Array.unzip
47+
4748
{ Context = clContext
4849
Indices = clContext.CreateClArrayWithFlag(flag, indices)
4950
Values = clContext.CreateClArrayWithFlag(flag, values)
5051
Size = size }
5152
|> ClVector.Sparse
5253
| Dense ->
54+
let indices, values =
55+
elements
56+
|> Array.ofList
57+
|> Array.unzip
58+
5359
let values =
5460
clContext.CreateClArrayWithFlag(GPUOnly, values)
5561

@@ -58,8 +64,7 @@ module Vector =
5864

5965
let mappedValues = map processor values
6066

61-
let result =
62-
clContext.CreateClArrayWithFlag(flag, size)
67+
let result = zeroCreate processor size
6368

6469
scatter processor indices mappedValues result
6570

0 commit comments

Comments
 (0)