Skip to content

Commit 9645c63

Browse files
committed
Change prune to select
1 parent ada8e43 commit 9645c63

8 files changed

Lines changed: 42 additions & 35 deletions

File tree

src/GraphBLAS-sharp/Algorithms/TriangleCounting.fs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@ namespace GraphBLAS.FSharp.Algorithms
22

33
open GraphBLAS.FSharp.Predefined
44
open GraphBLAS.FSharp
5-
open Brahma.FSharp.OpenCL.WorkflowBuilder.Basic
6-
open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
75

86
module TriangleCounting =
9-
let sandia (lowerTriangular: Matrix<bool>) = graphblas {
10-
let bool2int = function
11-
| true -> 1
12-
| false -> 0
7+
let sandia (matrix: Matrix<bool>) = graphblas {
8+
let! lowerTriangular = matrix |> Matrix.select (UnaryOp <@ fun (i, j, _) -> i <= j @>)
9+
let! matrix' = lowerTriangular |> Matrix.apply (UnaryOp <@ function | true -> 1 | false -> 0 @>)
10+
let! transposed = matrix' |> Matrix.transpose
1311

14-
let! convertedMatrix = lowerTriangular |> Matrix.apply (UnaryOp <@ bool2int @>)
15-
let! convertedTransposed = convertedMatrix |> Matrix.transpose
1612
let! lowerTriangularMask = lowerTriangular |> Matrix.mask
17-
let! result = (convertedMatrix, convertedTransposed) ||> Matrix.mxmWithMask AddMult.int lowerTriangularMask
13+
let! result = (matrix', transposed) ||> Matrix.mxmWithMask AddMult.int lowerTriangularMask
1814
let! (Scalar count) = result |> Matrix.reduce Add.int
15+
1916
return count
2017
}

src/GraphBLAS-sharp/Methods/Matrix.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ module Matrix =
4646

4747
let mask (matrix: Matrix<'a>) : GraphblasEvaluation<Mask2D> = failwith "Not Implemented yet"
4848
let complemented (matrix: Matrix<'a>) : GraphblasEvaluation<Mask2D> = failwith "Not Implemented yet"
49+
let switchTo (matrixType: MatrixType) (matrix: Matrix<'a>) : GraphblasEvaluation<Matrix<'a>> = failwith "Not Implemented yet"
4950
let synchronize (matrix: Matrix<'a>) : GraphblasEvaluation<unit> = failwith "Not Implemented yet"
50-
// let convert<'a when 'a :> Matrix<'a>>() = ()
5151

5252
(*
5353
assignment, extraction and filling
@@ -150,7 +150,7 @@ module Matrix =
150150

151151
let eWiseMult (semiring: ISemiring<'a>) (leftMatrix: Matrix<'a>) (rightMatrix: Matrix<'a>) : GraphblasEvaluation<Matrix<'a>> = failwith "Not Implemented yet"
152152
let apply (mapper: UnaryOp<'a, 'b>) (matrix: Matrix<'a>) : GraphblasEvaluation<Matrix<'b>> = failwith "Not Implemented yet"
153-
let prune (predicate: UnaryOp<'a, bool>) (matrix: Matrix<'a>) : GraphblasEvaluation<Matrix<'a>> = failwith "Not Implemented yet"
153+
let select (predicate: UnaryOp<int * int * 'a, bool>) (matrix: Matrix<'a>) : GraphblasEvaluation<Matrix<'a>> = failwith "Not Implemented yet"
154154
let reduceRows (monoid: IMonoid<'a>) (matrix: Matrix<'a>) : GraphblasEvaluation<Vector<'a>> = failwith "Not Implemented yet"
155155
let reduceCols (monoid: IMonoid<'a>) (matrix: Matrix<'a>) : GraphblasEvaluation<Vector<'a>> = failwith "Not Implemented yet"
156156
let reduce (monoid: IMonoid<'a>) (matrix: Matrix<'a>) : GraphblasEvaluation<Scalar<'a>> = failwith "Not Implemented yet"
@@ -162,7 +162,7 @@ module Matrix =
162162
let eWiseAddWithMask (semiring: ISemiring<'a>) (mask: Mask2D) (leftMatrix: Matrix<'a>) (rightMatrix: Matrix<'a>) : GraphblasEvaluation<Matrix<'a>> = failwith "Not Implemented yet"
163163
let eWiseMultWithMask (semiring: ISemiring<'a>) (mask: Mask2D) (leftMatrix: Matrix<'a>) (rightMatrix: Matrix<'a>) : GraphblasEvaluation<Matrix<'a>> = failwith "Not Implemented yet"
164164
let applyWithMask (mapper: UnaryOp<'a, 'b>) (mask: Mask2D) (matrix: Matrix<'a>) : GraphblasEvaluation<Matrix<'b>> = failwith "Not Implemented yet"
165-
let pruneWithMask (predicate: UnaryOp<'a, bool>) (mask: Mask2D) (matrix: Matrix<'a>) : GraphblasEvaluation<Matrix<'a>> = failwith "Not Implemented yet"
165+
let selectWithMask (predicate: UnaryOp<int * int * 'a, bool>) (mask: Mask2D) (matrix: Matrix<'a>) : GraphblasEvaluation<Matrix<'a>> = failwith "Not Implemented yet"
166166
let reduceRowsWithMask (monoid: IMonoid<'a>) (mask: Mask1D) (matrix: Matrix<'a>) : GraphblasEvaluation<Vector<'a>> = failwith "Not Implemented yet"
167167
let reduceColsWithMask (monoid: IMonoid<'a>) (mask: Mask1D) (matrix: Matrix<'a>) : GraphblasEvaluation<Vector<'a>> = failwith "Not Implemented yet"
168168
let kroneckerWithMask (semiring: ISemiring<'a>) (mask: Mask2D) (leftMatrix: Matrix<'a>) (rightMatrix: Matrix<'a>) : GraphblasEvaluation<Matrix<'a>> = failwith "Not Implemented yet"

src/GraphBLAS-sharp/Methods/Vector.fs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,32 +45,40 @@ module Vector =
4545
let tuples (vector: Vector<'a>) : GraphblasEvaluation<VectorTuples<'a>> = failwith "Not Implemented yet"
4646
let mask (vector: Vector<'a>) : GraphblasEvaluation<Mask1D> = failwith "Not Implemented yet"
4747
let complemented (vector: Vector<'a>) : GraphblasEvaluation<Mask1D> = failwith "Not Implemented yet"
48+
let switchTo (vectorType: VectorType) (vector: Vector<'a>) : GraphblasEvaluation<Vector<'a>> = failwith "Not Implemented yet"
4849
let synchronize (vector: Vector<'a>) : GraphblasEvaluation<unit> = failwith "Not Implemented yet"
4950

5051
(*
5152
assignment, extraction and filling
5253
*)
5354

5455
/// vec.[mask]
55-
let extractSubVector (mask: Mask1D) (vector: Vector<'a>) : GraphblasEvaluation<Vector<'a>> = failwith "Not Implemented yet"
56+
let extractSubVector (mask: Mask1D) (vector: Vector<'a>) : GraphblasEvaluation<Vector<'a>> =
57+
failwith "Not Implemented yet"
5658

5759
/// vec.[idx]
58-
let extractValue (idx: int) (vector: Vector<'a>) : GraphblasEvaluation<Scalar<'a>> = failwith "Not Implemented yet"
60+
let extractValue (idx: int) (vector: Vector<'a>) : GraphblasEvaluation<Scalar<'a>> =
61+
failwith "Not Implemented yet"
5962

6063
/// t <- vec
61-
let assignVector (source: Vector<'a>) (target: Vector<'a>) : GraphblasEvaluation<unit> = failwith "Not Implemented yet"
64+
let assignVector (source: Vector<'a>) (target: Vector<'a>) : GraphblasEvaluation<unit> =
65+
failwith "Not Implemented yet"
6266

6367
/// t.[mask] <- vec
64-
let assignSubVector (mask: Mask1D) (source: Vector<'a>) (target: Vector<'a>) : GraphblasEvaluation<unit> = failwith "Not Implemented yet"
68+
let assignSubVector (mask: Mask1D) (source: Vector<'a>) (target: Vector<'a>) : GraphblasEvaluation<unit> =
69+
failwith "Not Implemented yet"
6570

6671
/// t.[idx] <- value
67-
let assignValue (idx: int) (value: Scalar<'a>) (target: Vector<'a>) : GraphblasEvaluation<unit> = failwith "Not Implemented yet"
72+
let assignValue (idx: int) (value: Scalar<'a>) (target: Vector<'a>) : GraphblasEvaluation<unit> =
73+
failwith "Not Implemented yet"
6874

6975
/// vec.[*] <- value
70-
let fillVector (value: Scalar<'a>) (vector: Vector<'a>) : GraphblasEvaluation<unit> = failwith "Not Implemented yet"
76+
let fillVector (value: Scalar<'a>) (vector: Vector<'a>) : GraphblasEvaluation<unit> =
77+
failwith "Not Implemented yet"
7178

7279
/// vec.[mask] <- value
73-
let fillSubVector (mask: Mask1D) (value: Scalar<'a>) (vector: Vector<'a>) : GraphblasEvaluation<unit> = failwith "Not Implemented yet"
80+
let fillSubVector (mask: Mask1D) (value: Scalar<'a>) (vector: Vector<'a>) : GraphblasEvaluation<unit> =
81+
failwith "Not Implemented yet"
7482

7583
(*
7684
operations
@@ -80,13 +88,13 @@ module Vector =
8088
let eWiseAdd (semiring: ISemiring<'a>) (mask: Mask1D option) (leftVector: Vector<'a>) (rightVector: Vector<'a>) : GraphblasEvaluation<Vector<'a>> = failwith "Not Implemented yet"
8189
let eWiseMult (semiring: ISemiring<'a>) (leftVector: Vector<'a>) (rightVector: Vector<'a>) : GraphblasEvaluation<Vector<'a>> = failwith "Not Implemented yet"
8290
let apply (mapper: UnaryOp<'a, 'b>) (vector: Vector<'a>) : GraphblasEvaluation<Vector<'b>> = failwith "Not Implemented yet"
83-
let prune (predicate: UnaryOp<'a, bool>) (vector: Vector<'a>) : GraphblasEvaluation<Vector<'a>> = failwith "Not Implemented yet"
91+
let select (predicate: UnaryOp<'a, bool>) (vector: Vector<'a>) : GraphblasEvaluation<Vector<'a>> = failwith "Not Implemented yet"
8492
let reduce (monoid: IMonoid<'a>) (vector: Vector<'a>) : GraphblasEvaluation<Scalar<'a>> = failwith "Not Implemented yet"
8593

8694
let vxmWithMask (semiring: ISemiring<'a>) (mask: Mask1D) (vector: Vector<'a>) (matrix: Matrix<'a>) : GraphblasEvaluation<Vector<'a>> = failwith "Not Implemented yet"
8795
let eWiseAddWithMask (semiring: ISemiring<'a>) (mask: Mask1D) (leftVector: Vector<'a>) (rightVector: Vector<'a>) : GraphblasEvaluation<Vector<'a>> = failwith "Not Implemented yet"
8896
let applyWithMask (mapper: UnaryOp<'a, 'b>) (mask: Mask1D) (vector: Vector<'a>) : GraphblasEvaluation<Vector<'b>> = failwith "Not Implemented yet"
89-
let pruneWithMask (predicate: UnaryOp<'a, bool>) (mask: Mask1D) (vector: Vector<'a>) : GraphblasEvaluation<Vector<'a>> = failwith "Not Implemented yet"
97+
let selectWithMask (predicate: UnaryOp<'a, bool>) (mask: Mask1D) (vector: Vector<'a>) : GraphblasEvaluation<Vector<'a>> = failwith "Not Implemented yet"
9098

9199
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
92100
module VectorTuples =

src/GraphBLAS-sharp/Objects/Masks.fs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
namespace GraphBLAS.FSharp
22

3+
type MaskType =
4+
| Regular
5+
| Complemented
6+
| NoMask
7+
38
type Mask1D(indices: int[], size: int, isComplemented: bool) =
49
member this.Indices = indices
510
member this.Size = size

src/GraphBLAS-sharp/Objects/Matrix.fs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
namespace GraphBLAS.FSharp
22

3+
// matrixFormat
4+
type MatrixType =
5+
| CSR
6+
| COO
7+
38
type Matrix<'a> =
49
| MatrixCSR of CSRMatrix<'a>
510
| MatrixCOO of COOMatrix<'a>

src/GraphBLAS-sharp/Objects/Vector.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
namespace GraphBLAS.FSharp
22

3+
type VectorType =
4+
| COO
5+
| Dense
6+
37
type Vector<'a> =
48
| VectorCOO of COOVector<'a>
59
| VectorDense of ArrayVector<'a>

tests/GraphBLAS-sharp.Tests/Common.fs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,6 @@ open GraphBLAS.FSharp
66
open Microsoft.FSharp.Reflection
77
open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
88

9-
type MatrixBackendFormat =
10-
| CSR
11-
| COO
12-
13-
type VectorBackendFormat =
14-
| Sparse
15-
16-
type MaskType =
17-
| Regular
18-
| Complemented
19-
| NoMask
20-
219
module Generators =
2210
let dimension2DGenerator =
2311
Gen.sized <| fun size ->

tests/GraphBLAS-sharp.Tests/OperationsTests/EWiseAddTests.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ let logger = Log.create "EWiseAddTests"
1515
type OperationCase =
1616
{
1717
ClContext: OpenCLEvaluationContext
18-
MatrixCase: MatrixBackendFormat
18+
MatrixCase: MatrixType
1919
MaskCase: MaskType
2020
}
2121

2222
let testCases =
2323
[
2424
Utils.avaliableContexts "*" |> Seq.map box
25-
Utils.listOfUnionCases<MatrixBackendFormat> |> Seq.map box
25+
Utils.listOfUnionCases<MatrixType> |> Seq.map box
2626
Utils.listOfUnionCases<MaskType> |> Seq.map box
2727
]
2828
|> List.map List.ofSeq

0 commit comments

Comments
 (0)