@@ -2,12 +2,14 @@ module GraphBLAS.FSharp.Tests.Backend.Matrix.Merge
22
33open Brahma.FSharp
44open Expecto
5+ open GraphBLAS.FSharp .Test
56open Microsoft.FSharp .Collections
67open GraphBLAS.FSharp .Backend
78open GraphBLAS.FSharp .Tests
89open GraphBLAS.FSharp .Tests .Backend
910open GraphBLAS.FSharp .Objects
1011open GraphBLAS.FSharp .Objects .ArraysExtensions
12+ open GraphBLAS.FSharp .Objects .MatrixExtensions
1113
1214let context = Context.defaultContext.ClContext
1315
@@ -108,6 +110,52 @@ let testsCOO =
108110 createTestCOO (=) false ]
109111 |> testList " COO"
110112
113+ let makeTestCOODisjoint isEqual zero testFun ( leftArray : 'a [,], rightArray : 'a [,]) =
114+
115+ let leftMatrix =
116+ Matrix.COO.FromArray2D( leftArray, isEqual zero)
117+
118+ let rightMatrix =
119+ Matrix.COO.FromArray2D( rightArray, isEqual zero)
120+
121+ if leftMatrix.NNZ > 0 && rightMatrix.NNZ > 0 then
122+
123+ let clLeftMatrix = leftMatrix.ToDevice context
124+ let clRightMatrix = rightMatrix.ToDevice context
125+
126+ let actual : ClMatrix.COO < 'a > = testFun processor clLeftMatrix clRightMatrix
127+ let actual = actual.ToHostAndFree processor
128+
129+ clLeftMatrix.Dispose processor
130+ clRightMatrix.Dispose processor
131+
132+ rightArray
133+ |> Array2D.iteri ( fun row column value -> leftArray.[ row, column] <- value)
134+
135+ let expected = Matrix.COO.FromArray2D( leftArray, isEqual zero)
136+
137+ Utils.compareCOOMatrix isEqual actual expected
138+
139+ let createTestCOODisjoint isEqual ( zero : 'a ) =
140+ let configDisjoint =
141+ { Utils.defaultConfig with
142+ endSize = 10
143+ arbitrary = [ typeof< Generators.PairOfDisjointMatricesOfTheSameSize> ]}
144+
145+ Matrix.COO.Merge.runDisjoint context Utils.defaultWorkGroupSize
146+ |> makeTestCOODisjoint isEqual zero
147+ |> testPropertyWithConfig configDisjoint $" test on {typeof<'a>}"
148+
149+ let testsCOODisjoint =
150+ [ createTestCOODisjoint (=) 0
151+
152+ if Utils.isFloat64Available context.ClDevice then
153+ createTestCOODisjoint (=) 0.0
154+
155+ createTestCOODisjoint (=) 0.0 f
156+ createTestCOODisjoint (=) false ]
157+ |> testList " COO Disjoint"
158+
111159let makeTestCSR isEqual zero testFun ( leftArray : 'a [,], rightArray : 'a [,]) =
112160 let leftMatrix =
113161 Matrix.CSR.FromArray2D( leftArray, isEqual zero)
@@ -173,4 +221,4 @@ let testsCSR =
173221 |> testList " CSR"
174222
175223let allTests =
176- [ testsCSR; testsCOO ] |> testList " Merge"
224+ [ testsCSR; testsCOO; testsCOODisjoint ] |> testList " Merge"
0 commit comments