File tree Expand file tree Collapse file tree 1 file changed +8
-22
lines changed
tests/GraphBLAS-sharp.Tests Expand file tree Collapse file tree 1 file changed +8
-22
lines changed Original file line number Diff line number Diff 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
208194module Context =
You can’t perform that action at this time.
0 commit comments