Skip to content

Commit 048949c

Browse files
committed
Now matrices are generated with arbitrary sparsity
1 parent d28348d commit 048949c

5 files changed

Lines changed: 86 additions & 78 deletions

File tree

src/GraphBLAS-sharp/AlgebraicStructures.fs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@ namespace GraphBLAS.FSharp
22

33
open Microsoft.FSharp.Quotations
44

5-
type UnaryOp<'a, 'b> =
6-
| UnaryOp of Expr<'a -> 'b>
5+
type UnaryOp<'a, 'b> = UnaryOp of Expr<'a -> 'b>
6+
type BinaryOp<'a, 'b, 'c> = BinaryOp of Expr<'a -> 'b -> 'c>
77

8-
type BinaryOp<'a, 'b, 'c> =
9-
| BinaryOp of Expr<'a -> 'b -> 'c>
10-
11-
type ClosedUnaryOp<'a> =
12-
| ClosedUnaryOp of Expr<'a -> 'a>
13-
14-
type ClosedBinaryOp<'a> =
15-
| ClosedBinaryOp of Expr<'a -> 'a -> 'a>
8+
type ClosedUnaryOp<'a> = ClosedUnaryOp of Expr<'a -> 'a>
9+
type ClosedBinaryOp<'a> = ClosedBinaryOp of Expr<'a -> 'a -> 'a>
1610

1711
// associative closed bin op (magma with associative)
1812
type ISemigroup<'a> =
Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
namespace GraphBLAS.FSharp.Algorithms
22

33
open GraphBLAS.FSharp.Predefined
4-
open GraphBLAS.FSharp.Helpers
54
open GraphBLAS.FSharp
6-
open Brahma.FSharp.OpenCL.WorkflowBuilder.Basic
7-
open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
85

96
module BFS =
107
let level (matrix: Matrix<bool>) (source: int) = graphblas {
@@ -24,17 +21,3 @@ module BFS =
2421

2522
return levels
2623
}
27-
28-
// let parentBFS (matrix: Matrix<bool>) (source: int) : Vector<int> =
29-
// let vertexCount = matrix.RowCount
30-
// let parents = SparseVector(vertexCount, [source, -1])
31-
32-
// let id = DenseVector(Array.init vertexCount id, IntegerMonoid.add)
33-
// let frontier = SparseVector(vertexCount, [source, source])
34-
35-
// for _ in 1 .. vertexCount - 1 do
36-
// frontier.[parents.Complemented] <- (frontier @. matrix) parents.Complemented IntegerSemiring.minFirst
37-
// parents.[frontier.Mask] <- frontier
38-
// frontier.[frontier.Mask] <- id
39-
40-
// upcast parents

src/GraphBLAS-sharp/Algorithms/TriangleCounting.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module TriangleCounting =
1414
let! convertedMatrix = lowerTriangular |> Matrix.apply (UnaryOp <@ bool2int @>)
1515
let! convertedTransposed = convertedMatrix |> Matrix.transpose
1616
let! lowerTriangularMask = lowerTriangular |> Matrix.mask
17-
let! result = Matrix.mxmWithMask AddMult.int lowerTriangularMask convertedMatrix convertedTransposed
17+
let! result = (convertedMatrix, convertedTransposed) ||> Matrix.mxmWithMask AddMult.int lowerTriangularMask
1818
let! (Scalar count) = result |> Matrix.reduce Add.int
1919
return count
2020
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
namespace GraphBLAS.FSharp
22

3-
type Scalar<'a> =
4-
| Scalar of 'a
3+
type Scalar<'a> = Scalar of 'a

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

Lines changed: 80 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@ module EWiseAdd
33
open Expecto
44
open FsCheck
55
open GraphBLAS.FSharp
6-
open MathNet.Numerics
7-
open Brahma.FSharp.OpenCL.WorkflowBuilder.Basic
86
open GraphBLAS.FSharp.Tests
9-
open System
107
open GraphBLAS.FSharp.Predefined
118
open TypeShape.Core
129
open Expecto.Logging
1310
open Expecto.Logging.Message
1411
open BackendState
1512
open GraphBLAS.FSharp.Helpers
1613

14+
let logger = Log.create "EWiseAddTests"
15+
1716
type OperationCase =
1817
{
1918
MatrixCase: MatrixBackendFormat
@@ -32,64 +31,97 @@ let testCases =
3231
MaskCase = unbox list.[1]
3332
}
3433

35-
type PairOfSparseMatricesOfEqualSize =
34+
type PairOfSparseMatricesOfEqualSize() =
35+
static let MaxSparcity = 100
36+
static let SparsityGen = Gen.choose (0, MaxSparcity)
37+
static let GenericSparseGen valueGenProvider =
38+
gen {
39+
let! sparsity = SparsityGen
40+
logger.debug (
41+
eventX "Sparcity is {sp} of {ms}"
42+
>> setField "sp" sparsity
43+
>> setField "ms" MaxSparcity
44+
)
45+
46+
return! valueGenProvider sparsity
47+
}
48+
3649
static member IntType() =
37-
Generators.pairOfMatricesOfEqualSizeGenerator (
38-
Gen.oneof [
39-
Arb.generate<int>
40-
Gen.constant 0
41-
]
42-
) |> Arb.fromGen
50+
fun sparsity ->
51+
Generators.pairOfMatricesOfEqualSizeGenerator (
52+
Gen.frequency [
53+
(MaxSparcity - sparsity, Arb.generate<int>)
54+
(sparsity, Gen.constant 0)
55+
]
56+
)
57+
|> GenericSparseGen
58+
|> Arb.fromGen
4359

4460
static member FloatType() =
45-
Generators.pairOfMatricesOfEqualSizeGenerator (
46-
Gen.oneof [
47-
(Arb.Default.NormalFloat() |> Arb.toGen |> Gen.map float)
48-
Gen.constant 0.
49-
]
50-
) |> Arb.fromGen
61+
fun sparsity ->
62+
Generators.pairOfMatricesOfEqualSizeGenerator (
63+
Gen.frequency [
64+
(MaxSparcity - sparsity, Arb.Default.NormalFloat() |> Arb.toGen |> Gen.map float)
65+
(sparsity, Gen.constant 0.)
66+
]
67+
)
68+
|> GenericSparseGen
69+
|> Arb.fromGen
5170

5271
static member SByteType() =
53-
Generators.pairOfMatricesOfEqualSizeGenerator (
54-
Gen.oneof [
55-
Arb.generate<sbyte>
56-
Gen.constant 0y
57-
]
58-
) |> Arb.fromGen
72+
fun sparsity ->
73+
Generators.pairOfMatricesOfEqualSizeGenerator (
74+
Gen.frequency [
75+
(MaxSparcity - sparsity, Arb.generate<sbyte>)
76+
(sparsity, Gen.constant 0y)
77+
]
78+
)
79+
|> GenericSparseGen
80+
|> Arb.fromGen
5981

6082
static member ByteType() =
61-
Generators.pairOfMatricesOfEqualSizeGenerator (
62-
Gen.oneof [
63-
Arb.generate<byte>
64-
Gen.constant 0uy
65-
]
66-
) |> Arb.fromGen
83+
fun sparsity ->
84+
Generators.pairOfMatricesOfEqualSizeGenerator (
85+
Gen.frequency [
86+
(MaxSparcity - sparsity, Arb.generate<byte>)
87+
(sparsity, Gen.constant 0uy)
88+
]
89+
)
90+
|> GenericSparseGen
91+
|> Arb.fromGen
6792

6893
static member Int16Type() =
69-
Generators.pairOfMatricesOfEqualSizeGenerator (
70-
Gen.oneof [
71-
Arb.generate<int16>
72-
Gen.constant 0s
73-
]
74-
) |> Arb.fromGen
94+
fun sparsity ->
95+
Generators.pairOfMatricesOfEqualSizeGenerator (
96+
Gen.frequency [
97+
(MaxSparcity - sparsity, Arb.generate<int16>)
98+
(sparsity, Gen.constant 0s)
99+
]
100+
)
101+
|> GenericSparseGen
102+
|> Arb.fromGen
75103

76104
static member UInt16Type() =
77-
Generators.pairOfMatricesOfEqualSizeGenerator (
78-
Gen.oneof [
79-
Arb.generate<uint16>
80-
Gen.constant 0us
81-
]
82-
) |> Arb.fromGen
105+
fun sparsity ->
106+
Generators.pairOfMatricesOfEqualSizeGenerator (
107+
Gen.frequency [
108+
(MaxSparcity - sparsity, Arb.generate<uint16>)
109+
(sparsity, Gen.constant 0us)
110+
]
111+
)
112+
|> GenericSparseGen
113+
|> Arb.fromGen
83114

84115
static member BoolType() =
85-
Generators.pairOfMatricesOfEqualSizeGenerator (
86-
Gen.oneof [
87-
Arb.generate<bool>
88-
Gen.constant false
89-
]
90-
) |> Arb.fromGen
91-
92-
let logger = Log.create "eWiseAddTests"
116+
fun sparsity ->
117+
Generators.pairOfMatricesOfEqualSizeGenerator (
118+
Gen.frequency [
119+
(MaxSparcity - sparsity, Arb.generate<bool>)
120+
(sparsity, Gen.constant false)
121+
]
122+
)
123+
|> GenericSparseGen
124+
|> Arb.fromGen
93125

94126
let checkCorrectnessGeneric<'a when 'a : struct and 'a : equality>
95127
(sum: 'a -> 'a -> 'a)

0 commit comments

Comments
 (0)