Skip to content

Commit 2441558

Browse files
committed
refactor: formatting
1 parent c75fd57 commit 2441558

11 files changed

Lines changed: 295 additions & 274 deletions

File tree

src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
<Compile Include="Objects/ClContextExtensions.fs" />
2020
<Compile Include="Objects/ClCell.fs" />
2121
<Compile Include="Quotes/SubReduce.fs" />
22-
<Compile Include="Quotes\Convert.fs" />
2322
<Compile Include="Quotes/Arithmetic.fs" />
23+
<Compile Include="Quotes/Convert.fs" />
2424
<Compile Include="Quotes/Mask.fs" />
2525
<Compile Include="Quotes/SubSum.fs" />
2626
<Compile Include="Quotes/PreparePositions.fs" />
@@ -35,27 +35,27 @@
3535
<Compile Include="Common/Sort/Radix.fs" />
3636
<Compile Include="Common/Sort/Bitonic.fs" />
3737
<Compile Include="Common/Sum.fs" />
38-
<Compile Include="Vector\Dense\DenseVector.fs" />
39-
<Compile Include="Vector\Sparse\Common.fs" />
40-
<Compile Include="Vector\Sparse\Map2AtLeastOne.fs" />
41-
<Compile Include="Vector\Sparse\Map2.fs" />
42-
<Compile Include="Vector\Sparse\Map.fs" />
43-
<Compile Include="Vector\Sparse\SparseVector.fs" />
44-
<Compile Include="Vector\SpMV.fs" />
45-
<Compile Include="Vector\Vector.fs" />
46-
<Compile Include="Matrix\Common.fs" />
47-
<Compile Include="Matrix\COO\Map.fs" />
48-
<Compile Include="Matrix\COO\Map2.fs" />
49-
<Compile Include="Matrix\COO\Map2AtLeastOne.fs" />
50-
<Compile Include="Matrix\COO\Matrix.fs" />
51-
<Compile Include="Matrix\CSR\Map.fs" />
52-
<Compile Include="Matrix\CSR\Map2.fs" />
53-
<Compile Include="Matrix\CSR\Map2AtLeastOne.fs" />
54-
<Compile Include="Matrix\CSR\Matrix.fs" />
55-
<Compile Include="Matrix\LIL\Matrix.fs" />
56-
<Compile Include="Matrix\SpGeMM\Expand.fs" />
57-
<Compile Include="Matrix\SpGeMM\Masked.fs" />
58-
<Compile Include="Matrix\Matrix.fs" />
38+
<Compile Include="Vector/Dense/DenseVector.fs" />
39+
<Compile Include="Vector/Sparse/Common.fs" />
40+
<Compile Include="Vector/Sparse/Map2AtLeastOne.fs" />
41+
<Compile Include="Vector/Sparse/Map2.fs" />
42+
<Compile Include="Vector/Sparse/Map.fs" />
43+
<Compile Include="Vector/Sparse/SparseVector.fs" />
44+
<Compile Include="Vector/SpMV.fs" />
45+
<Compile Include="Vector/Vector.fs" />
46+
<Compile Include="Matrix/Common.fs" />
47+
<Compile Include="Matrix/COO/Map.fs" />
48+
<Compile Include="Matrix/COO/Map2.fs" />
49+
<Compile Include="Matrix/COO/Map2AtLeastOne.fs" />
50+
<Compile Include="Matrix/COO/Matrix.fs" />
51+
<Compile Include="Matrix/CSR/Map.fs" />
52+
<Compile Include="Matrix/CSR/Map2.fs" />
53+
<Compile Include="Matrix/CSR/Map2AtLeastOne.fs" />
54+
<Compile Include="Matrix/CSR/Matrix.fs" />
55+
<Compile Include="Matrix/LIL/Matrix.fs" />
56+
<Compile Include="Matrix/SpGeMM/Expand.fs" />
57+
<Compile Include="Matrix/SpGeMM/Masked.fs" />
58+
<Compile Include="Matrix/Matrix.fs" />
5959
<Compile Include="Algorithms/BFS.fs" />
6060
</ItemGroup>
6161
<Import Project="..\..\.paket\Paket.Restore.targets" />

src/GraphBLAS-sharp.Backend/Quotes/Arithmetic.fs

Lines changed: 77 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
open GraphBLAS.FSharp.Backend.Objects
44

55
module ArithmeticOperations =
6-
// unary
7-
let inline optionUnOp zero unaryOp =
6+
let inline mkUnaryOp zero unaryOp =
87
<@ fun x ->
98
let mutable res = zero
109

@@ -14,104 +13,120 @@ module ArithmeticOperations =
1413

1514
if res = zero then None else Some res @>
1615

17-
let inline addLeftConst zero constant =
18-
optionUnOp zero <@ fun x -> constant + x @>
16+
let inline mkNumericSum zero =
17+
<@ fun (x: 't option) (y: 't option) ->
18+
let mutable res = zero
1919

20-
let inline addRightConst zero constant =
21-
optionUnOp zero <@ fun x -> x + constant @>
20+
match x, y with
21+
| Some f, Some s -> res <- f + s
22+
| Some f, None -> res <- f
23+
| None, Some s -> res <- s
24+
| None, None -> ()
2225

23-
let inline mulLeftConst zero constant =
24-
optionUnOp zero <@ fun x -> constant * x @>
26+
if res = zero then None else Some res @>
2527

26-
let inline mulRightConst zero constant =
27-
optionUnOp zero <@ fun x -> x * constant @>
28+
let inline mkNumericSumAtLeastOne zero =
29+
<@ fun (values: AtLeastOne<'t, 't>) ->
30+
let mutable res = zero
31+
32+
match values with
33+
| Both (f, s) -> res <- f + s
34+
| Left f -> res <- f
35+
| Right s -> res <- s
2836

29-
// binary
37+
if res = zero then None else Some res @>
3038

31-
let inline optionBinOpQ zero binOp =
32-
<@ fun (x: 'a option) (y: 'a option) ->
39+
let inline mkNumericMul zero =
40+
<@ fun (x: 't option) (y: 't option) ->
3341
let mutable res = zero
3442

3543
match x, y with
36-
| Some f, Some s -> res <- (%binOp) f s
37-
| Some f, None -> res <- f
38-
| None, Some s -> res <- s
39-
| None, None -> ()
44+
| Some f, Some s -> res <- f * s
45+
| _ -> ()
4046

4147
if res = zero then None else Some res @>
4248

43-
let inline optionBinOp zero binOp =
44-
fun (x: 'a option) (y: 'a option) ->
49+
let inline mkNumericMulAtLeastOne zero =
50+
<@ fun (values: AtLeastOne<'t, 't>) ->
4551
let mutable res = zero
4652

53+
match values with
54+
| Both (f, s) -> res <- f * s
55+
| _ -> ()
56+
57+
if res = zero then None else Some res @>
58+
59+
let boolSum =
60+
<@ fun (x: bool option) (y: bool option) ->
61+
let mutable res = false
62+
4763
match x, y with
48-
| Some left, Some right -> res <- binOp left right
49-
| Some left, None -> res <- left
50-
| None, Some right -> res <- right
5164
| None, None -> ()
65+
| _ -> res <- true
5266

53-
if res = zero then None else Some res
67+
if res then Some true else None @>
5468

55-
let createOptionPair zero opQ op =
56-
optionBinOpQ zero opQ, optionBinOp zero op
57-
58-
let inline createOptionSumPair zero = createOptionPair zero <@ (+) @> (+)
69+
let inline addLeftConst zero constant =
70+
mkUnaryOp zero <@ fun x -> constant + x @>
5971

60-
let intSumOption = createOptionSumPair 0
61-
let byteSumOption = createOptionSumPair 0uy
62-
let floatSumOption = createOptionSumPair 0.0
63-
let float32SumOption = createOptionSumPair 0f
72+
let inline addRightConst zero constant =
73+
mkUnaryOp zero <@ fun x -> x + constant @>
6474

65-
let boolSumOption = createOptionPair false <@ (||) @> (||)
75+
let intSumOption = mkNumericSum 0
76+
let byteSumOption = mkNumericSum 0uy
77+
let floatSumOption = mkNumericSum 0.0
78+
let float32SumOption = mkNumericSum 0f
6679

67-
let inline createOptionMulPair zero = createOptionPair zero <@ (*) @> (*)
80+
let boolSumAtLeastOne =
81+
<@ fun (_: AtLeastOne<bool, bool>) -> Some true @>
6882

69-
let intMulOption = createOptionMulPair 0
70-
let byteMulOption = createOptionMulPair 0uy
71-
let floatMulOption = createOptionMulPair 0.0
72-
let float32MulOption = createOptionMulPair 0f
83+
let intSumAtLeastOne = mkNumericSumAtLeastOne 0
84+
let byteSumAtLeastOne = mkNumericSumAtLeastOne 0uy
85+
let floatSumAtLeastOne = mkNumericSumAtLeastOne 0.0
86+
let float32SumAtLeastOne = mkNumericSumAtLeastOne 0f
7387

74-
let boolMulOption = createOptionPair true <@ (&&) @> (&&)
88+
let boolMulOption =
89+
<@ fun (x: bool option) (y: bool option) ->
90+
let mutable res = false
7591

76-
let inline atLeastOneBinOpQ zero binOp =
77-
Convert.optionToAtLeastOne <| optionBinOpQ zero binOp
92+
match x, y with
93+
| Some _, Some _ -> res <- true
94+
| _ -> ()
7895

79-
let inline atLeastOneBinOp zero binOp =
80-
let optionOp = optionBinOp zero binOp
81-
// convert AtLeastOne -> Option
82-
function
83-
| Both (left, right) -> optionOp (Some left) (Some right)
84-
| Left left -> optionOp (Some left) None
85-
| Right right -> optionOp None (Some right)
96+
if res then Some true else None @>
8697

87-
let inline createAtLeastOnePair zero opQ op =
88-
atLeastOneBinOpQ zero opQ, atLeastOneBinOp zero op
98+
let inline mulLeftConst zero constant =
99+
mkUnaryOp zero <@ fun x -> constant * x @>
89100

90-
let inline createAtLeastOneSumPair zero = createAtLeastOnePair zero <@ (+) @> (+)
101+
let inline mulRightConst zero constant =
102+
mkUnaryOp zero <@ fun x -> x * constant @>
91103

92-
let intSumAtLeastOne = createAtLeastOneSumPair 0
93-
let byteSumAtLeastOne = createAtLeastOneSumPair 0uy
94-
let floatSumAtLeastOne = createAtLeastOneSumPair 0.0
95-
let float32SumAtLeastOne = createAtLeastOneSumPair 0f
104+
let intMulOption = mkNumericMul 0
105+
let byteMulOption = mkNumericMul 0uy
106+
let floatMulOption = mkNumericMul 0.0
107+
let float32MulOption = mkNumericMul 0f
96108

97-
let boolSumAtLeastOne = createAtLeastOnePair false <@ (||) @> (||)
109+
let boolMulAtLeastOne =
110+
<@ fun (values: AtLeastOne<bool, bool>) ->
111+
let mutable res = false
98112

99-
let inline createAtLeastOneMulPair zero = createAtLeastOnePair zero <@ (*) @> (*)
113+
match values with
114+
| Both _ -> res <- true
115+
| _ -> ()
100116

101-
let intMulAtLeastOne = createAtLeastOneMulPair 0
102-
let byteMulAtLeastOne = createAtLeastOneMulPair 0uy
103-
let floatMulAtLeastOne = createAtLeastOneMulPair 0.0
104-
let float32MulAtLeastOne = createAtLeastOneMulPair 0f
117+
if res then Some true else None @>
105118

106-
let boolMulAtLeastOne = createAtLeastOnePair true <@ (&&) @> (&&)
119+
let intMulAtLeastOne = mkNumericMulAtLeastOne 0
120+
let byteMulAtLeastOne = mkNumericMulAtLeastOne 0uy
121+
let floatMulAtLeastOne = mkNumericMulAtLeastOne 0.0
122+
let float32MulAtLeastOne = mkNumericMulAtLeastOne 0f
107123

108124
let notOption =
109125
<@ fun x ->
110126
match x with
111127
| Some true -> None
112128
| _ -> Some true @>
113129

114-
// unwrapped operands
115130
let inline private binOpQ zero op =
116131
<@ fun (left: 'a) (right: 'a) ->
117132
let result = (%op) left right

src/GraphBLAS-sharp.Backend/Quotes/Convert.fs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@ module Convert =
1212
| Some left, None -> (%op) (Left left)
1313
| None, None -> None @>
1414

15-
let optionToAtLeastOne (op: Expr<'a option -> 'b option -> 'c option>) =
16-
<@ fun (item: AtLeastOne<'a, 'b>) ->
17-
match item with
18-
| Both (left, right) -> (%op) (Some left) (Some right)
19-
| Left left -> (%op) (Some left) None
20-
| Right right -> (%op) None (Some right) @>
21-
2215
let assignToOption (op: Expr<'a option -> 'a option -> 'a option>) =
2316
<@ fun (leftItem: 'a option) (rightItem: 'b option) (value: 'a) ->
2417
match rightItem with

src/GraphBLAS-sharp/GraphBLAS-sharp.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<Compile Include="Exceptions.fs" />
1919
<Compile Include="AlgebraicStructures.fs" />
2020
<Compile Include="GraphblasEvaluation.fs" />
21-
<Compile Include="Objects\Vector.fs" />
21+
<Compile Include="Objects/Vector.fs" />
2222
<Compile Include="Objects/Matrix.fs" />
2323
<Compile Include="Objects/Scalar.fs" />
2424
<Compile Include="Objects/VectorExtensions.fs" />

tests/GraphBLAS-sharp.Tests/GraphBLAS-sharp.Tests.fsproj

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,18 @@
2525
<Compile Include="Common/ClArray/RemoveDuplicates.fs" />
2626
<Compile Include="Common/ClArray/Copy.fs" />
2727
<Compile Include="Common/ClArray/Replicate.fs" />
28-
<Compile Include="Common\ClArray\ChunkBySize.fs" />
29-
<Compile Include="Common\ClArray\Assign.fs" />
30-
<Compile Include="Common\ClArray\Concat.fs" />
31-
<Compile Include="Common\ClArray\Fill.fs" />
32-
<Compile Include="Common\ClArray\Pairwise.fs" />
28+
<Compile Include="Common/ClArray/ChunkBySize.fs" />
29+
<Compile Include="Common/ClArray/Assign.fs" />
30+
<Compile Include="Common/ClArray/Concat.fs" />
31+
<Compile Include="Common/ClArray/Fill.fs" />
32+
<Compile Include="Common/ClArray/Pairwise.fs" />
3333
<Compile Include="Common/Sort/Bitonic.fs" />
3434
<Compile Include="Common/Sort/Radix.fs" />
3535
<Compile Include="Common/Reduce/Sum.fs" />
3636
<Compile Include="Common/Reduce/Reduce.fs" />
3737
<Compile Include="Common/Reduce/ReduceByKey.fs" />
3838
<Compile Include="Common/Scan/PrefixSum.fs" />
3939
<Compile Include="Common/Scan/ByKey.fs" />
40-
<!--Compile Include="MatrixOperationsTests/GetTuplesTests.fs" /-->
41-
<!--Compile Include="MatrixOperationsTests/MxvTests.fs" /-->
42-
<!--Compile Include="MatrixOperationsTests/VxmTests.fs" /-->
43-
<!--Compile Include="AlgorithmsTests/BfsTests.fs" /-->
4440
<Compile Include="Vector/ZeroCreate.fs" />
4541
<Compile Include="Vector/OfList.fs" />
4642
<Compile Include="Vector/Copy.fs" />
@@ -49,15 +45,14 @@
4945
<Compile Include="Vector/Reduce.fs" />
5046
<Compile Include="Vector/Map2.fs" />
5147
<Compile Include="Vector/SpMV.fs" />
52-
<Compile Include="Vector\Map.fs" />
5348
<Compile Include="Algorithms/BFS.fs" />
5449
<Compile Include="Matrix/Convert.fs" />
5550
<Compile Include="Matrix/Map2.fs" />
5651
<Compile Include="Matrix/Transpose.fs" />
5752
<Compile Include="Matrix/Map.fs" />
5853
<Compile Include="Matrix/SpGeMM/Masked.fs" />
5954
<Compile Include="Matrix/SpGeMM/Expand.fs" />
60-
<Compile Include="Matrix\RowsLengths.fs" />
55+
<Compile Include="Matrix/RowsLengths.fs" />
6156
<Compile Include="Program.fs" />
6257
</ItemGroup>
6358
<Import Project="..\..\.paket\Paket.Restore.targets" />

tests/GraphBLAS-sharp.Tests/Matrix/Map.fs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,33 +59,35 @@ let correctnessGenericTest
5959
(case: OperationCase<MatrixFormat>)
6060
(matrix: 'a [,])
6161
=
62+
match case.Format with
63+
| LIL -> ()
64+
| _ ->
65+
let mtx =
66+
Utils.createMatrixFromArray2D case.Format matrix (isEqual zero)
6267

63-
let mtx =
64-
Utils.createMatrixFromArray2D case.Format matrix (isEqual zero)
68+
if mtx.NNZ > 0 then
69+
try
70+
let m = mtx.ToDevice case.TestContext.ClContext
6571

66-
if mtx.NNZ > 0 then
67-
try
68-
let m = mtx.ToDevice case.TestContext.ClContext
72+
let res = addFun q HostInterop m
6973

70-
let res = addFun q HostInterop m
74+
m.Dispose q
7175

72-
m.Dispose q
76+
let (cooRes: ClMatrix<'a>) = toCOOFun q HostInterop res
77+
let actual = cooRes.ToHost q
7378

74-
let (cooRes: ClMatrix<'a>) = toCOOFun q HostInterop res
75-
let actual = cooRes.ToHost q
79+
cooRes.Dispose q
80+
res.Dispose q
7681

77-
cooRes.Dispose q
78-
res.Dispose q
82+
logger.debug (
83+
eventX "Actual is {actual}"
84+
>> setField "actual" (sprintf "%A" actual)
85+
)
7986

80-
logger.debug (
81-
eventX "Actual is {actual}"
82-
>> setField "actual" (sprintf "%A" actual)
83-
)
84-
85-
checkResult isEqual op zero matrix actual
86-
with
87-
| ex when ex.Message = "InvalidBufferSize" -> ()
88-
| ex -> raise ex
87+
checkResult isEqual op zero matrix actual
88+
with
89+
| ex when ex.Message = "InvalidBufferSize" -> ()
90+
| ex -> raise ex
8991

9092
let createTestMap case (zero: 'a) (constant: 'a) binOp isEqual opQ =
9193
let getCorrectnessTestName = getCorrectnessTestName case

0 commit comments

Comments
 (0)