Skip to content

Commit c4ebf2a

Browse files
committed
refactor: merge min max
1 parent 7eead12 commit c4ebf2a

6 files changed

Lines changed: 20 additions & 31 deletions

File tree

src/GraphBLAS-sharp.Backend/Common/PrefixSum.fs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,7 @@ module PrefixSum =
136136

137137
let private scanExclusive<'a when 'a: struct> =
138138
scanGeneral
139-
<@ fun (a: ClArray<'a>) (b: 'a) (c: int) (d: int) (e: int) ->
140-
141-
() @>
139+
<@ fun (_: ClArray<'a>) (_: 'a) (_: int) (_: int) (_: int) -> () @>
142140
<@ fun (resultBuffer: ClArray<'a>) (resultLocalBuffer: 'a []) (inputArrayLength: int) (smth: int) (gid: int) (i: int) (localID: int) ->
143141

144142
if gid < inputArrayLength then

src/GraphBLAS-sharp.Backend/Matrix/COOMatrix/COOMatrix.fs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,11 @@ module COOMatrix =
108108
let diagonalNumber = x
109109

110110
let mutable leftEdge = diagonalNumber + 1 - secondSide
111-
if leftEdge < 0 then leftEdge <- 0
111+
leftEdge <- max 0 leftEdge
112112

113113
let mutable rightEdge = firstSide - 1
114114

115-
if rightEdge > diagonalNumber then // TODO()
116-
rightEdge <- diagonalNumber
115+
rightEdge <- min diagonalNumber rightEdge
117116

118117
while leftEdge <= rightEdge do
119118
let middleIdx = (leftEdge + rightEdge) / 2
@@ -169,12 +168,11 @@ module COOMatrix =
169168

170169
if i < sumOfSides then
171170
let mutable leftEdge = localID + 1 - secondLocalLength
172-
if leftEdge < 0 then leftEdge <- 0
171+
leftEdge <- max 0 leftEdge
173172

174173
let mutable rightEdge = firstLocalLength - 1
175174

176-
if rightEdge > localID then // TODO()
177-
rightEdge <- localID
175+
rightEdge <- min localID rightEdge
178176

179177
while leftEdge <= rightEdge do
180178
let middleIdx = (leftEdge + rightEdge) / 2

src/GraphBLAS-sharp.Backend/Matrix/CSRMatrix/Elementwise.fs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ namespace GraphBLAS.FSharp.Backend.Matrix.CSR
33
open System
44
open Brahma.FSharp
55
open GraphBLAS.FSharp.Backend.Common
6-
open GraphBLAS.FSharp.Backend.Predefined
76
open Microsoft.FSharp.Quotations
87

98
module internal Elementwise =
@@ -84,7 +83,7 @@ module internal Elementwise =
8483
let localArraySize = workGroupSize + 2
8584

8685
let merge =
87-
<@ fun (ndRange: Range1D) rows (firstRowPointers: ClArray<int>) (firstColumns: ClArray<int>) (firstValues: ClArray<'a>) (secondRowPointers: ClArray<int>) (secondColumns: ClArray<int>) (secondValues: ClArray<'b>) (allRows: ClArray<int>) (allColumns: ClArray<int>) (leftMergedValues: ClArray<'a>) (rightMergedValues: ClArray<'b>) (isEndOfRowBitmap: ClArray<int>) (isLeftBitmap: ClArray<int>) ->
86+
<@ fun (ndRange: Range1D) (firstRowPointers: ClArray<int>) (firstColumns: ClArray<int>) (firstValues: ClArray<'a>) (secondRowPointers: ClArray<int>) (secondColumns: ClArray<int>) (secondValues: ClArray<'b>) (allRows: ClArray<int>) (allColumns: ClArray<int>) (leftMergedValues: ClArray<'a>) (rightMergedValues: ClArray<'b>) (isEndOfRowBitmap: ClArray<int>) (isLeftBitmap: ClArray<int>) ->
8887

8988
let globalID = ndRange.GlobalID0
9089
let localID = ndRange.LocalID0
@@ -299,7 +298,6 @@ module internal Elementwise =
299298
(fun () ->
300299
kernel.KernelFunc
301300
ndRange
302-
(matrixLeftRowPointers.Length - 1)
303301
matrixLeftRowPointers
304302
matrixLeftColumns
305303
matrixLeftValues

src/GraphBLAS-sharp.Backend/Matrix/Common.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module GraphBLAS.FSharp.Backend.Matrix
1+
namespace GraphBLAS.FSharp.Backend.Matrix
22

33
open Brahma.FSharp
44
open GraphBLAS.FSharp.Backend.Common

src/GraphBLAS-sharp.Backend/Vector/SparseVector/Elementwise.fs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@ module Elementwise =
2121
let diagonalNumber = x
2222

2323
let mutable leftEdge = diagonalNumber + 1 - secondSide
24-
if leftEdge < 0 then leftEdge <- 0
24+
leftEdge <- max 0 leftEdge
2525

2626
let mutable rightEdge = firstSide - 1
2727

28-
if rightEdge > diagonalNumber then
29-
rightEdge <- diagonalNumber
28+
rightEdge <- min rightEdge diagonalNumber
3029

3130
while leftEdge <= rightEdge do
3231
let middleIdx = (leftEdge + rightEdge) / 2
@@ -76,8 +75,7 @@ module Elementwise =
7675

7776
let mutable rightEdge = firstLocalLength - 1
7877

79-
if rightEdge > localID then
80-
rightEdge <- localID
78+
rightEdge <- min rightEdge localID
8179

8280
while leftEdge <= rightEdge do
8381
let middleIdx = (leftEdge + rightEdge) / 2

tests/GraphBLAS-sharp.Tests/Program.fs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,14 @@ let matrixTests =
1616
let commonTests =
1717
testList
1818
"Common tests"
19-
[
20-
// [ Common.BitonicSort.tests
21-
// Common.PrefixSum.tests
22-
// Common.Scatter.tests
19+
[ Common.BitonicSort.tests
20+
Common.PrefixSum.tests
21+
Common.Scatter.tests
2322
Common.RemoveDuplicates.tests
24-
// Common.Copy.tests
25-
// Common.Replicate.tests
26-
// Common.Reduce.tests
27-
// Common.Sum.tests ]
28-
]
23+
Common.Copy.tests
24+
Common.Replicate.tests
25+
Common.Reduce.tests
26+
Common.Sum.tests ]
2927
|> testSequenced
3028

3129
let vectorTests =
@@ -55,10 +53,9 @@ let allTests =
5553
testList
5654
"All tests"
5755
[ commonTests
58-
//matrixTests
59-
//vectorTests
60-
//algorithmsTests ]
61-
]
56+
matrixTests
57+
vectorTests
58+
algorithmsTests ]
6259
|> testSequenced
6360

6461
[<EntryPoint>]

0 commit comments

Comments
 (0)