@@ -6,6 +6,7 @@ open Expecto
66open Microsoft.FSharp .Collections
77open GraphBLAS.FSharp .Backend .Objects .ArraysExtensions
88open GraphBLAS.FSharp .Backend .Objects .ClContext
9+ open GraphBLAS.FSharp .Backend .Quotes
910
1011let context = Context.defaultContext.ClContext
1112
@@ -62,3 +63,62 @@ let tests =
6263 createTest< bool> (=) Gather.run
6364 createTest< uint> (=) Gather.run ]
6465 |> testList " Gather"
66+
67+
68+ let makeTestInit isEqual testFun indexMap ( array : ( 'a * 'a ) []) =
69+ if array.Length > 0 then
70+
71+ let positions , values , target =
72+ Array.mapi ( fun index ( first , second ) -> indexMap index, first, second) array
73+ |> Array.unzip3
74+
75+ let clValues =
76+ context.CreateClArrayWithSpecificAllocationMode( DeviceOnly, values)
77+
78+ let clTarget =
79+ context.CreateClArrayWithSpecificAllocationMode( DeviceOnly, target)
80+
81+ testFun processor clValues clTarget
82+
83+ clValues.Free processor
84+
85+ let actual = clTarget.ToHostAndFree processor
86+
87+ check isEqual actual positions values target
88+
89+ let createTestInit < 'a > ( isEqual : 'a -> 'a -> bool ) testFun indexMapQ indexMap =
90+
91+ let testFun = testFun indexMapQ context Utils.defaultWorkGroupSize
92+
93+ makeTestInit isEqual testFun indexMap
94+ |> testPropertyWithConfig Utils.defaultConfig $" test on {typeof<'a>}"
95+
96+ let initTests =
97+
98+ let idTests =
99+ [ createTestInit< int> (=) Gather.runInit Map.id id
100+
101+ if Utils.isFloat64Available context.ClDevice then
102+ createTestInit< float> Utils.floatIsEqual Gather.runInit Map.id id
103+
104+ createTestInit< float32> Utils.float32IsEqual Gather.runInit Map.id id
105+ createTestInit< bool> (=) Gather.runInit Map.id id
106+ createTestInit< uint> (=) Gather.runInit Map.id id]
107+ |> testList " id"
108+
109+ let inc = ((+) 1 )
110+
111+ let incTests =
112+ [ createTestInit< int> (=) Gather.runInit Map.inc inc
113+
114+ if Utils.isFloat64Available context.ClDevice then
115+ createTestInit< float> Utils.floatIsEqual Gather.runInit Map.inc inc
116+
117+ createTestInit< float32> Utils.float32IsEqual Gather.runInit Map.inc inc
118+ createTestInit< bool> (=) Gather.runInit Map.inc inc
119+ createTestInit< uint> (=) Gather.runInit Map.inc inc]
120+ |> testList " inc"
121+
122+ testList " init" [ idTests; incTests]
123+
124+
0 commit comments