@@ -119,77 +119,81 @@ module ElementwiseConstructor =
119119 firstResultValues.[ i] <- firstValuesBuffer.[ beginIdx + boundaryX]
120120 isLeftBitMap.[ i] <- 1 @>
121121
122- let private opWriteBothFill ( opAdd : Expr < 'a option -> 'b option -> 'a -> 'a option >) =
123- <@
124- fun gid ( leftValues : ClArray < 'a >) ( rightValues : ClArray < 'b >) ( value : 'a ) ->
125- (% opAdd) ( Some leftValues.[ gid]) ( Some rightValues.[ gid + 1 ]) value
126- @>
127-
128- let private opWriteLeftFill ( opAdd : Expr < 'a option -> 'b option -> 'a -> 'a option >) =
129- <@
130- fun gid ( leftValues : ClArray < 'a >) ( value : 'a ) ->
131- (% opAdd) ( Some leftValues.[ gid]) None value
132- @>
133-
134- let private opWriteRightFill ( opAdd : Expr < 'a option -> 'b option -> 'a -> 'a option >) =
135- <@
136- fun gid ( rightValues : ClArray < 'b >) ( value : 'a ) ->
137- (% opAdd) None ( Some rightValues.[ gid + 1 ]) value
138- @>
139-
140- let private opWriteAtLeastOneBothFill ( opAdd : Expr < AtLeastOne < 'a , 'b > -> 'a -> 'a option >) =
141- <@
142- fun gid ( leftValues : ClArray < 'a >) ( rightValues : ClArray < 'b >) ( value : 'a ) ->
143- (% opAdd) ( Both( leftValues.[ gid], rightValues.[ gid + 1 ])) value
144- @>
145-
146- let private opWriteAtLeastOneLeftFill ( opAdd : Expr < AtLeastOne < 'a , 'b > -> 'a -> 'a option >) =
147- <@
148- fun gid ( leftValues : ClArray < 'a >) ( value : 'a ) ->
149- (% opAdd) ( Left( leftValues.[ gid])) value
150- @>
151-
152- let private opWriteAtLeastOneRightFill ( opAdd : Expr < AtLeastOne < 'a , 'b > -> 'a -> 'a option >) =
153- <@
154- fun gid ( rightValues : ClArray < 'b >) ( value : 'a ) ->
155- (% opAdd) ( Right( rightValues.[ gid])) value
156- @>
157-
158- let private opWriteBoth ( opAdd : Expr < 'a option -> 'b option -> 'c option >) =
159- <@
160- fun gid ( leftValues : ClArray < 'a >) ( rightValues : ClArray < 'b >) ->
161- (% opAdd) ( Some leftValues.[ gid]) ( Some rightValues.[ gid + 1 ])
162- @>
163-
164- let private opWriteLeft ( opAdd : Expr < 'a option -> 'b option -> 'c option >) =
165- <@
166- fun gid ( leftValues : ClArray < 'a >) ->
167- (% opAdd) ( Some leftValues.[ gid]) None
168- @>
169-
170- let private opWriteRight ( opAdd : Expr < 'a option -> 'b option -> 'c option >) =
171- <@
172- fun gid ( rightValues : ClArray < 'b >) ->
173- (% opAdd) None ( Some rightValues.[ gid + 1 ])
174- @>
175-
176- let private opWriteAtLeastOneBoth ( opAdd : Expr < AtLeastOne < 'a , 'b > -> 'c option >) =
177- <@
178- fun gid ( leftValues : ClArray < 'a >) ( rightValues : ClArray < 'b >) ->
179- (% opAdd) ( Both( leftValues.[ gid], rightValues.[ gid + 1 ]))
180- @>
181-
182- let opWriteAtLeastOneLeft ( opAdd : Expr < AtLeastOne < 'a , 'b > -> 'c option >) =
183- <@
184- fun gid ( leftValues : ClArray < 'a >) ->
185- (% opAdd) ( Left( leftValues.[ gid]))
186- @>
187-
188- let opWriteAtLeastOneRight ( opAdd : Expr < AtLeastOne < 'a , 'b > -> 'a option >) =
189- <@
190- fun gid ( rightValues : ClArray < 'b >) ->
191- (% opAdd) ( Right( rightValues.[ gid]))
192- @>
122+ module FillSubVectorRead =
123+ let both ( opAdd : Expr < 'a option -> 'b option -> 'a -> 'a option >) =
124+ <@
125+ fun gid ( leftValues : ClArray < 'a >) ( rightValues : ClArray < 'b >) ( value : 'a ) ->
126+ (% opAdd) ( Some leftValues.[ gid]) ( Some rightValues.[ gid + 1 ]) value
127+ @>
128+
129+ let left ( opAdd : Expr < 'a option -> 'b option -> 'a -> 'a option >) =
130+ <@
131+ fun gid ( leftValues : ClArray < 'a >) ( value : 'a ) ->
132+ (% opAdd) ( Some leftValues.[ gid]) None value
133+ @>
134+
135+ let right ( opAdd : Expr < 'a option -> 'b option -> 'a -> 'a option >) =
136+ <@
137+ fun gid ( rightValues : ClArray < 'b >) ( value : 'a ) ->
138+ (% opAdd) None ( Some rightValues.[ gid + 1 ]) value
139+ @>
140+
141+ module FillSubVectorAtLeasOneRead =
142+ let both ( opAdd : Expr < AtLeastOne < 'a , 'b > -> 'a -> 'a option >) =
143+ <@
144+ fun gid ( leftValues : ClArray < 'a >) ( rightValues : ClArray < 'b >) ( value : 'a ) ->
145+ (% opAdd) ( Both( leftValues.[ gid], rightValues.[ gid + 1 ])) value
146+ @>
147+
148+ let left ( opAdd : Expr < AtLeastOne < 'a , 'b > -> 'a -> 'a option >) =
149+ <@
150+ fun gid ( leftValues : ClArray < 'a >) ( value : 'a ) ->
151+ (% opAdd) ( Left( leftValues.[ gid])) value
152+ @>
153+
154+ let right ( opAdd : Expr < AtLeastOne < 'a , 'b > -> 'a -> 'a option >) =
155+ <@
156+ fun gid ( rightValues : ClArray < 'b >) ( value : 'a ) ->
157+ (% opAdd) ( Right( rightValues.[ gid])) value
158+ @>
159+
160+ module ElementWiseRead =
161+ let both ( opAdd : Expr < 'a option -> 'b option -> 'c option >) =
162+ <@
163+ fun gid ( leftValues : ClArray < 'a >) ( rightValues : ClArray < 'b >) ->
164+ (% opAdd) ( Some leftValues.[ gid]) ( Some rightValues.[ gid + 1 ])
165+ @>
166+
167+ let left ( opAdd : Expr < 'a option -> 'b option -> 'c option >) =
168+ <@
169+ fun gid ( leftValues : ClArray < 'a >) ->
170+ (% opAdd) ( Some leftValues.[ gid]) None
171+ @>
172+
173+ let right ( opAdd : Expr < 'a option -> 'b option -> 'c option >) =
174+ <@
175+ fun gid ( rightValues : ClArray < 'b >) ->
176+ (% opAdd) None ( Some rightValues.[ gid + 1 ])
177+ @>
178+
179+ module ElementWiseAtLeasOneRead =
180+ let both ( opAdd : Expr < AtLeastOne < 'a , 'b > -> 'c option >) =
181+ <@
182+ fun gid ( leftValues : ClArray < 'a >) ( rightValues : ClArray < 'b >) ->
183+ (% opAdd) ( Both( leftValues.[ gid], rightValues.[ gid + 1 ]))
184+ @>
185+
186+ let left ( opAdd : Expr < AtLeastOne < 'a , 'b > -> 'c option >) =
187+ <@
188+ fun gid ( leftValues : ClArray < 'a >) ->
189+ (% opAdd) ( Left( leftValues.[ gid]))
190+ @>
191+
192+ let right ( opAdd : Expr < AtLeastOne < 'a , 'b > -> 'c option >) =
193+ <@
194+ fun gid ( rightValues : ClArray < 'b >) ->
195+ (% opAdd) ( Right( rightValues.[ gid]))
196+ @>
193197
194198 let private both < 'c > =
195199 <@ fun index ( result : 'c option ) ( rawPositionsBuffer : ClArray < int >) ( allValuesBuffer : ClArray < 'c >) ->
@@ -217,9 +221,9 @@ module ElementwiseConstructor =
217221 | None -> rawPositionsBuffer.[ index] <- 0 @>
218222
219223 let private preparePositionsGeneral
220- ( bothWrite : Expr <( int -> ClArray < 'a > -> ClArray < 'b > -> 'c option )>)
221- leftWrite
222- rightWrite
224+ bothRead
225+ leftRead
226+ rightRead
223227 =
224228
225229 <@ fun ( ndRange : Range1D ) length ( allIndices : ClArray < int >) ( leftValues : ClArray < 'a >) ( rightValues : ClArray < 'b >) ( isLeft : ClArray < int >) ( allValues : ClArray < 'c >) ( positions : ClArray < int >) ->
@@ -228,20 +232,20 @@ module ElementwiseConstructor =
228232
229233 if gid < length - 1
230234 && allIndices.[ gid] = allIndices.[ gid + 1 ] then
231- let ( result : 'c option ) = (% bothWrite ) gid leftValues rightValues
235+ let ( result : 'c option ) = (% bothRead ) gid leftValues rightValues
232236
233237 (% both) gid result positions allValues
234238 elif ( gid < length
235239 && gid > 0
236240 && allIndices.[ gid - 1 ] <> allIndices.[ gid])
237241 || gid = 0 then
238242
239- let leftResult = (% leftWrite ) gid leftValues
240- let rightResult = (% rightWrite ) gid rightValues
243+ let leftResult = (% leftRead ) gid leftValues
244+ let rightResult = (% rightRead ) gid rightValues
241245
242246 (% leftRight) gid leftResult rightResult isLeft allValues positions @>
243247
244- let private prepareFillVectorGeneral bothWrite leftWrite rightWrite =
248+ let private prepareFillVectorGeneral bothRead leftRead rightRead =
245249 <@ fun ( ndRange : Range1D ) length ( allIndices : ClArray < int >) ( leftValues : ClArray < 'a >) ( rightValues : ClArray < 'b >) ( value : ClCell < 'a >) ( isLeft : ClArray < int >) ( allValues : ClArray < 'a >) ( positions : ClArray < int >) ->
246250
247251 let gid = ndRange.GlobalID0
@@ -250,22 +254,26 @@ module ElementwiseConstructor =
250254
251255 if gid < length - 1
252256 && allIndices.[ gid] = allIndices.[ gid + 1 ] then
253- let ( result : 'a option ) = (% bothWrite ) gid leftValues rightValues value
257+ let ( result : 'a option ) = (% bothRead ) gid leftValues rightValues value
254258
255259 (% both) gid result positions allValues
256260 elif ( gid < length
257261 && gid > 0
258262 && allIndices.[ gid - 1 ] <> allIndices.[ gid])
259263 || gid = 0 then
260- let leftResult = (% leftWrite ) gid leftValues value
261- let rightResult = (% rightWrite ) gid rightValues value
264+ let leftResult = (% leftRead ) gid leftValues value
265+ let rightResult = (% rightRead ) gid rightValues value
262266
263267 (% leftRight) gid leftResult rightResult isLeft allValues positions @>
264268
265- let preparePositions opAdd = preparePositionsGeneral ( opWriteBoth opAdd) ( opWriteLeft opAdd) ( opWriteRight opAdd)
269+ let preparePositions opAdd =
270+ preparePositionsGeneral ( ElementWiseRead.both opAdd) ( ElementWiseRead.left opAdd) ( ElementWiseRead.right opAdd)
266271
267- let preparePositionsAtLeastOne opAdd = preparePositionsGeneral ( opWriteAtLeastOneBoth opAdd) ( opWriteAtLeastOneLeft opAdd) ( opWriteAtLeastOneRight opAdd)
272+ let preparePositionsAtLeastOne opAdd =
273+ preparePositionsGeneral ( ElementWiseAtLeasOneRead.both opAdd) ( ElementWiseAtLeasOneRead.left opAdd) ( ElementWiseAtLeasOneRead.right opAdd)
268274
269- let prepareFillVector opAdd = prepareFillVectorGeneral ( opWriteBothFill opAdd) ( opWriteLeftFill opAdd) ( opWriteRightFill opAdd)
275+ let prepareFillVector opAdd =
276+ prepareFillVectorGeneral ( FillSubVectorRead.both opAdd) ( FillSubVectorRead.left opAdd) ( FillSubVectorRead.right opAdd)
270277
271- let prepareFillVectorAtLeastOne opAdd = prepareFillVectorGeneral ( opWriteAtLeastOneBothFill opAdd) ( opWriteAtLeastOneLeftFill opAdd) ( opWriteAtLeastOneRightFill opAdd)
278+ let prepareFillVectorAtLeastOne opAdd =
279+ prepareFillVectorGeneral ( FillSubVectorAtLeasOneRead.both opAdd) ( FillSubVectorAtLeasOneRead.left opAdd) ( FillSubVectorAtLeasOneRead.right opAdd)
0 commit comments