Skip to content

Commit 420e2b8

Browse files
committed
refactor: Helpers
1 parent ab870bd commit 420e2b8

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

tests/GraphBLAS-sharp.Tests/Helpers.fs

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -177,32 +177,18 @@ module HostPrimitives =
177177
|> Array.choose id
178178

179179
let reduceByKey keys value reduceOp =
180-
let zipped = Array.zip keys value
181-
182-
Array.distinct keys
180+
Array.zip keys value
181+
|> Array.groupBy fst
183182
|> Array.map
184-
(fun key ->
185-
// extract elements corresponding to key
186-
(key,
187-
Array.map snd
188-
<| Array.filter ((=) key << fst) zipped))
189-
// reduce elements
190-
|> Array.map (fun (key, values) -> key, Array.reduce reduceOp values)
183+
(fun (key, array) ->
184+
Array.map snd array
185+
|> Array.reduce reduceOp
186+
|> fun value -> key, value)
191187
|> Array.unzip
192188

193189
let scanByKey scan keysAndValues =
194-
// select keys
195-
Array.map fst keysAndValues
196-
// get unique keys
197-
|> Array.distinct
198-
|> Array.map
199-
(fun key ->
200-
// select with certain key
201-
Array.filter (fst >> ((=) key)) keysAndValues
202-
// get values
203-
|> Array.map snd
204-
// scan values and get only values without sum
205-
|> (fst << scan))
190+
Array.groupBy fst keysAndValues
191+
|> Array.map (fun (_, array) -> Array.map snd array |> scan |> fst)
206192
|> Array.concat
207193

208194
module Context =

0 commit comments

Comments
 (0)