@@ -173,9 +173,10 @@ and COOMatrix<'a when 'a : struct and 'a : equality>(rowCount: int, columnCount:
173173
174174 //It is useful to consider that the first array is longer than the second one
175175 let firstRows , firstColumns , firstValues , secondRows , secondColumns , secondValues , plus =
176- if this.Rows.Length > matrix.Rows.Length
177- then this.Rows, this.Columns, this.Values, matrix.Rows, matrix.Columns, matrix.Values, append
178- else matrix.Rows, matrix.Columns, matrix.Values, this.Rows, this.Columns, this.Values, <@ fun x y -> (% append) y x @>
176+ if this.Rows.Length > matrix.Rows.Length then
177+ this.Rows, this.Columns, this.Values, matrix.Rows, matrix.Columns, matrix.Values, append
178+ else
179+ matrix.Rows, matrix.Columns, matrix.Values, this.Rows, this.Columns, this.Values, <@ fun x y -> (% append) y x @>
179180
180181 let filterThroughMask =
181182 opencl {
@@ -205,38 +206,25 @@ and COOMatrix<'a when 'a : struct and 'a : equality>(rowCount: int, columnCount:
205206
206207 let i = ndRange.GlobalID0
207208
208- let f n =
209- if 0 > n + 1 - shortSide
210- then 0
211- else n + 1 - shortSide
209+ let f n = if 0 > n + 1 - shortSide then 0 else n + 1 - shortSide
212210 let mutable leftEdge = f i
213- // if 0 > i + 1 - shortSide
214- // then 0
215- // else i + 1 - shortSide
216-
217- let g n =
218- if n > longSide - 1
219- then longSide - 1
220- else n
211+ // if 0 > i + 1 - shortSide then 0 else i + 1 - shortSide
212+
213+ let g n = if n > longSide - 1 then longSide - 1 else n
221214 let mutable rightEdge = g i
222- // if i > longSide - 1
223- // then longSide - 1
224- // else i
215+ // if i > longSide - 1 then longSide - 1 else i
225216
226217 while leftEdge <= rightEdge do
227218 let middleIdx = ( leftEdge + rightEdge) / 2
228219 let firstRow , firstColumn = firstRowsBuffer.[ middleIdx], firstColumnsBuffer.[ middleIdx]
229220 let secondRow , secondColumn = secondRowsBuffer.[ i - middleIdx], secondColumnsBuffer.[ i - middleIdx]
230- if firstRow < secondRow || firstRow = secondRow && firstColumn < secondColumn
231- then leftEdge <- middleIdx + 1
232- else rightEdge <- middleIdx - 1
221+ if firstRow < secondRow || firstRow = secondRow && firstColumn < secondColumn then leftEdge <- middleIdx + 1 else rightEdge <- middleIdx - 1
233222
234223 let boundaryX , boundaryY = rightEdge, i - leftEdge
235224 let firstRow , firstColumn = firstRowsBuffer.[ boundaryX], firstColumnsBuffer.[ boundaryX]
236225 let secondRow , secondColumn = secondRowsBuffer.[ boundaryY], secondColumnsBuffer.[ boundaryY]
237226
238- if boundaryX < 0 || boundaryY >= 0 && ( firstRow < secondRow || firstRow = secondRow && firstColumn < secondColumn)
239- then
227+ if boundaryX < 0 || boundaryY >= 0 && ( firstRow < secondRow || firstRow = secondRow && firstColumn < secondColumn) then
240228 allRowsBuffer.[ i] <- secondRowsBuffer.[ boundaryY]
241229 allColumnsBuffer.[ i] <- secondColumnsBuffer.[ boundaryY]
242230 allValuesBuffer.[ i] <- secondValuesBuffer.[ boundaryY]
@@ -276,8 +264,7 @@ and COOMatrix<'a when 'a : struct and 'a : equality>(rowCount: int, columnCount:
276264
277265 let i = ndRange.GlobalID0
278266
279- if allRowsBuffer.[ i] = allRowsBuffer.[ i + 1 ] && allColumnsBuffer.[ i] = allColumnsBuffer.[ i + 1 ]
280- then
267+ if allRowsBuffer.[ i] = allRowsBuffer.[ i + 1 ] && allColumnsBuffer.[ i] = allColumnsBuffer.[ i + 1 ] then
281268 auxiliaryArrayBuffer.[ i + 1 ] <- 0
282269 allValuesBuffer.[ i] <- (% plus) allValuesBuffer.[ i] allValuesBuffer.[ i + 1 ]
283270 @>
@@ -295,29 +282,6 @@ and COOMatrix<'a when 'a : struct and 'a : equality>(rowCount: int, columnCount:
295282 do ! RunCommand fillAuxiliaryArray binder
296283 }
297284
298- let dropExplicitZeroes =
299- <@
300- fun ( ndRange : _1D )
301- ( allValuesBuffer : 'a [])
302- ( auxiliaryArrayBuffer : int []) ->
303-
304- let i = ndRange.GlobalID0
305-
306- if allValuesBuffer.[ i] = zero
307- then auxiliaryArrayBuffer.[ i] <- 0
308- @>
309-
310- let dropExplicitZeroes =
311- opencl {
312- let binder kernelP =
313- let ndRange = _ 1D( allValues.Length)
314- kernelP
315- ndRange
316- allValues
317- auxiliaryArray
318- do ! RunCommand dropExplicitZeroes binder
319- }
320-
321285 let createUnion =
322286 <@
323287 fun ( ndRange : _1D )
@@ -332,8 +296,7 @@ and COOMatrix<'a when 'a : struct and 'a : equality>(rowCount: int, columnCount:
332296
333297 let i = ndRange.GlobalID0
334298
335- if auxiliaryArrayBuffer.[ i] = 1
336- then
299+ if auxiliaryArrayBuffer.[ i] = 1 then
337300 let index = prefixSumArrayBuffer.[ i] - 1
338301
339302 resultRowsBuffer.[ index] <- allRowsBuffer.[ i]
@@ -347,7 +310,7 @@ and COOMatrix<'a when 'a : struct and 'a : equality>(rowCount: int, columnCount:
347310
348311 let createUnion =
349312 opencl {
350- let! prefixSumArray = Toolbox.PrefixSum auxiliaryArray
313+ let! prefixSumArray = Toolbox.prefixSum auxiliaryArray
351314 let binder kernelP =
352315 let ndRange = _ 1D( auxiliaryArray.Length)
353316 kernelP
@@ -367,7 +330,7 @@ and COOMatrix<'a when 'a : struct and 'a : equality>(rowCount: int, columnCount:
367330 do ! createSortedConcatenation
368331 do ! filterThroughMask
369332 do ! fillAuxiliaryArray
370- do ! dropExplicitZeroes
333+ do ! Toolbox.EWiseAdd. dropExplicitZeroes zero allValues auxiliaryArray
371334 do ! createUnion
372335
373336 return upcast COOMatrix< 'a>( this.RowCount, this.ColumnCount, resultRows, resultColumns, resultValues)
@@ -455,9 +418,10 @@ and SparseVector<'a when 'a : struct and 'a : equality>(size: int, indices: int[
455418
456419 //It is useful to consider that the first array is longer than the second one
457420 let firstIndices , firstValues , secondIndices , secondValues , plus =
458- if this.Indices.Length > vector.Indices.Length
459- then this.Indices, this.Values, vector.Indices, vector.Values, append
460- else vector.Indices, vector.Values, this.Indices, this.Values, <@ fun x y -> (% append) y x @>
421+ if this.Indices.Length > vector.Indices.Length then
422+ this.Indices, this.Values, vector.Indices, vector.Values, append
423+ else
424+ vector.Indices, vector.Values, this.Indices, this.Values, <@ fun x y -> (% append) y x @>
461425
462426 let filterThroughMask =
463427 opencl {
@@ -483,34 +447,21 @@ and SparseVector<'a when 'a : struct and 'a : equality>(size: int, indices: int[
483447
484448 let i = ndRange.GlobalID0
485449
486- let f n =
487- if 0 > n + 1 - shortSide
488- then 0
489- else n + 1 - shortSide
450+ let f n = if 0 > n + 1 - shortSide then 0 else n + 1 - shortSide
490451 let mutable leftEdge = f i
491- // if 0 > i + 1 - shortSide
492- // then 0
493- // else i + 1 - shortSide
494-
495- let g n =
496- if n > longSide - 1
497- then longSide - 1
498- else n
452+ // if 0 > i + 1 - shortSide then 0 else i + 1 - shortSide
453+
454+ let g n = if n > longSide - 1 then longSide - 1 else n
499455 let mutable rightEdge = g i
500- // if i > longSide - 1
501- // then longSide - 1
502- // else i
456+ // if i > longSide - 1 then longSide - 1 else i
503457
504458 while leftEdge <= rightEdge do
505459 let middleIdx = ( leftEdge + rightEdge) / 2
506- if firstIndicesBuffer.[ middleIdx] < secondIndicesBuffer.[ i - middleIdx]
507- then leftEdge <- middleIdx + 1
508- else rightEdge <- middleIdx - 1
460+ if firstIndicesBuffer.[ middleIdx] < secondIndicesBuffer.[ i - middleIdx] then leftEdge <- middleIdx + 1 else rightEdge <- middleIdx - 1
509461
510462 let boundaryX , boundaryY = rightEdge, i - leftEdge
511463
512- if boundaryX < 0 || boundaryY >= 0 && firstIndicesBuffer.[ boundaryX] < secondIndicesBuffer.[ boundaryY]
513- then
464+ if boundaryX < 0 || boundaryY >= 0 && firstIndicesBuffer.[ boundaryX] < secondIndicesBuffer.[ boundaryY] then
514465 allIndicesBuffer.[ i] <- secondIndicesBuffer.[ boundaryY]
515466 allValuesBuffer.[ i] <- secondValuesBuffer.[ boundaryY]
516467 else
@@ -544,8 +495,7 @@ and SparseVector<'a when 'a : struct and 'a : equality>(size: int, indices: int[
544495
545496 let i = ndRange.GlobalID0
546497
547- if allIndicesBuffer.[ i] = allIndicesBuffer.[ i + 1 ]
548- then
498+ if allIndicesBuffer.[ i] = allIndicesBuffer.[ i + 1 ] then
549499 auxiliaryArrayBuffer.[ i + 1 ] <- 0
550500 allValuesBuffer.[ i] <- (% plus) allValuesBuffer.[ i] allValuesBuffer.[ i + 1 ]
551501 @>
@@ -562,29 +512,6 @@ and SparseVector<'a when 'a : struct and 'a : equality>(size: int, indices: int[
562512 do ! RunCommand fillAuxiliaryArray binder
563513 }
564514
565- let dropExplicitZeroes =
566- <@
567- fun ( ndRange : _1D )
568- ( allValuesBuffer : 'a [])
569- ( auxiliaryArrayBuffer : int []) ->
570-
571- let i = ndRange.GlobalID0
572-
573- if allValuesBuffer.[ i] = zero
574- then auxiliaryArrayBuffer.[ i] <- 0
575- @>
576-
577- let dropExplicitZeroes =
578- opencl {
579- let binder kernelP =
580- let ndRange = _ 1D( allValues.Length)
581- kernelP
582- ndRange
583- allValues
584- auxiliaryArray
585- do ! RunCommand dropExplicitZeroes binder
586- }
587-
588515 let createUnion =
589516 <@
590517 fun ( ndRange : _1D )
@@ -597,8 +524,7 @@ and SparseVector<'a when 'a : struct and 'a : equality>(size: int, indices: int[
597524
598525 let i = ndRange.GlobalID0
599526
600- if auxiliaryArrayBuffer.[ i] = 1
601- then
527+ if auxiliaryArrayBuffer.[ i] = 1 then
602528 let index = prefixSumArrayBuffer.[ i] - 1
603529
604530 resultIndicesBuffer.[ index] <- allIndicesBuffer.[ i]
@@ -610,7 +536,7 @@ and SparseVector<'a when 'a : struct and 'a : equality>(size: int, indices: int[
610536
611537 let createUnion =
612538 opencl {
613- let! prefixSumArray = Toolbox.PrefixSum auxiliaryArray
539+ let! prefixSumArray = Toolbox.prefixSum auxiliaryArray
614540 let binder kernelP =
615541 let ndRange = _ 1D( auxiliaryArray.Length)
616542 kernelP
@@ -628,7 +554,7 @@ and SparseVector<'a when 'a : struct and 'a : equality>(size: int, indices: int[
628554 do ! createSortedConcatenation
629555 do ! filterThroughMask
630556 do ! fillAuxiliaryArray
631- do ! dropExplicitZeroes
557+ do ! Toolbox.EWiseAdd. dropExplicitZeroes zero allValues auxiliaryArray
632558 do ! createUnion
633559
634560 return upcast SparseVector< 'a>( this.Size, resultIndices, resultValues)
@@ -639,8 +565,7 @@ and SparseVector<'a when 'a : struct and 'a : equality>(size: int, indices: int[
639565 ( mask : Mask1D option )
640566 ( semiring : Semiring < 'a >) =
641567
642- if vector.Size <> this.Size
643- then
568+ if vector.Size <> this.Size then
644569 invalidArg
645570 " vector"
646571 ( sprintf " Argument has invalid dimension. Need %i , but given %i " this.Size vector.Size)
0 commit comments