Skip to content

Commit 3f7c0bf

Browse files
committed
add: spgemm
1 parent 69be680 commit 3f7c0bf

4 files changed

Lines changed: 20 additions & 8 deletions

File tree

src/GraphBLAS-sharp.Backend/Matrix/CSRMatrix/SpGEMM/Expand.fs

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

217217
let reduce (clContext: ClContext) workGroupSize opAdd =
218218

219-
let reduce = Reduce.ByKey2D.segmentSequential clContext workGroupSize opAdd
219+
let reduce = Reduce.ByKey2D.segmentSequentialOption clContext workGroupSize opAdd
220220

221221
let getUniqueBitmap =
222222
ClArray.getUniqueBitmap2LastOccurrence clContext workGroupSize

tests/GraphBLAS-sharp.Tests/Helpers.fs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,26 @@ module HostPrimitives =
233233
if Array2D.length2 leftArray <> Array2D.length1 rightArray then
234234
failwith "Incompatible matrices"
235235

236+
let add left right =
237+
match left, right with
238+
| Some left, Some right ->
239+
add left right
240+
| Some value, None
241+
| None, Some value -> Some value
242+
| _ -> None
243+
236244
Array2D.init
237245
<| Array2D.length1 leftArray
238246
<| Array2D.length2 rightArray
239247
<| fun i j ->
240248
(leftArray.[i, *], rightArray.[*, j])
249+
// multiply and filter
241250
||> Array.map2 mul
242251
|> Array.choose id
243-
|> Array.fold add zero
244-
252+
// add and filter
253+
|> Array.map Some
254+
|> Array.fold add None
255+
|> function | Some value -> value | None -> zero
245256
module Context =
246257
type TestContext =
247258
{ ClContext: ClContext

tests/GraphBLAS-sharp.Tests/Matrix/SpGeMM.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,13 @@ let makeGeneralTest zero isEqual opMul opAdd testFun (leftArray: 'a [,], rightAr
222222
| ex when ex.Message = "InvalidBufferSize" -> ()
223223
| _ -> reraise ()
224224

225-
let createGeneralTest (zero: 'a) isEqual opAddQ opAdd (opMulQ, opMul) testFun =
225+
let createGeneralTest (zero: 'a) isEqual (opAddQ, opAdd) (opMulQ, opMul) testFun =
226226

227227
let testFun = testFun context Utils.defaultWorkGroupSize opAddQ opMulQ
228228

229229
makeGeneralTest zero isEqual opMul opAdd testFun
230-
|> testPropertyWithConfig { config with endSize = 10; maxTest = 1000 } $"test on %A{typeof<'a>}"
230+
|> testPropertyWithConfig config $"test on %A{typeof<'a>}"
231231

232232
let generalTests =
233-
[ createGeneralTest 0 (=) <@ (+) @> (+) ArithmeticOperations.intMul Expand.run ]
233+
[ createGeneralTest 0 (=) ArithmeticOperations.intAdd ArithmeticOperations.intMul Expand.run ]
234234
|> testList "general"

tests/GraphBLAS-sharp.Tests/Program.fs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,11 @@ let allTests =
9595
testList
9696
"All tests"
9797
[ // SpGeMM.expandTests
98-
// SpGeMM.generalTests
98+
SpGeMM.generalTests
9999
// Common.Gather.initTests
100100
// Common.ClArray.Choose.tests2 ]
101-
Common.Reduce.ByKey.testsByKey2DSegmentsSequential ]
101+
// Common.Reduce.ByKey.testsByKey2DSegmentsSequential ]
102+
]
102103
|> testSequenced
103104

104105
[<EntryPoint>]

0 commit comments

Comments
 (0)