Skip to content

Commit 8dc01a0

Browse files
committed
add: (vector, mask, value) generator
1 parent 72e07f0 commit 8dc01a0

6 files changed

Lines changed: 67 additions & 7 deletions

File tree

benchmarks/GraphBLAS-sharp.Benchmarks/Helpers.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ open BenchmarkDotNet.Jobs
1414
open GraphBLAS.FSharp.Tests
1515
open FsCheck
1616
open Expecto
17+
open GraphBLAS.FSharp.Test
1718

1819
type CommonConfig() =
1920
inherit ManualConfig()
@@ -258,7 +259,7 @@ module Utils =
258259
module VectorGenerator =
259260
let private pairOfVectorsOfEqualSize (valuesGenerator: Gen<'a>) createVector =
260261
gen {
261-
let! length = Gen.sized <| fun size -> Gen.constant size
262+
let! length = Gen.sized <| Gen.constant
262263

263264
let! leftArray = Gen.arrayOfLength length valuesGenerator
264265

tests/GraphBLAS-sharp.Tests/Generators.fs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,3 +758,62 @@ module Generators =
758758
static member BoolType() =
759759
pairOfVectorsOfEqualSize <| Arb.generate<bool>
760760
|> Arb.fromGen
761+
762+
type PairOfArraysAndValue() =
763+
static let pairOfVectorsOfEqualSize (valuesGenerator: Gen<'a>) =
764+
gen {
765+
let! length = Gen.sized <| fun size -> Gen.choose (1, size)
766+
767+
let! leftArray = Gen.arrayOfLength length valuesGenerator
768+
769+
let! rightArray = Gen.arrayOfLength length valuesGenerator
770+
771+
let value =
772+
List.last <| Gen.sample 100 1 valuesGenerator
773+
774+
return (leftArray, rightArray, value)
775+
}
776+
777+
static member IntType() =
778+
pairOfVectorsOfEqualSize <| Arb.generate<int>
779+
|> Arb.fromGen
780+
781+
static member FloatType() =
782+
pairOfVectorsOfEqualSize
783+
<| (Arb.Default.NormalFloat()
784+
|> Arb.toGen
785+
|> Gen.map float)
786+
|> Arb.fromGen
787+
788+
static member Float32Type() =
789+
pairOfVectorsOfEqualSize
790+
<| (normalFloat32Generator <| System.Random())
791+
|> Arb.fromGen
792+
793+
static member SByteType() =
794+
pairOfVectorsOfEqualSize <| Arb.generate<sbyte>
795+
|> Arb.fromGen
796+
797+
static member ByteType() =
798+
pairOfVectorsOfEqualSize <| Arb.generate<byte>
799+
|> Arb.fromGen
800+
801+
static member Int16Type() =
802+
pairOfVectorsOfEqualSize <| Arb.generate<int16>
803+
|> Arb.fromGen
804+
805+
static member UInt16Type() =
806+
pairOfVectorsOfEqualSize <| Arb.generate<uint16>
807+
|> Arb.fromGen
808+
809+
static member Int32Type() =
810+
pairOfVectorsOfEqualSize <| Arb.generate<int32>
811+
|> Arb.fromGen
812+
813+
static member UInt32Type() =
814+
pairOfVectorsOfEqualSize <| Arb.generate<uint32>
815+
|> Arb.fromGen
816+
817+
static member BoolType() =
818+
pairOfVectorsOfEqualSize <| Arb.generate<bool>
819+
|> Arb.fromGen

tests/GraphBLAS-sharp.Tests/Helpers.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ module Utils =
2828
typeof<Generators.ArrayOfDistinctKeys>
2929
typeof<Generators.ArrayOfAscendingKeys>
3030
typeof<Generators.BufferCompatibleArray>
31-
typeof<Generators.PairOfVectorsOfEqualSize> ] }
31+
typeof<Generators.PairOfVectorsOfEqualSize>
32+
typeof<Generators.PairOfArraysAndValue> ] }
3233

3334
let floatIsEqual x y =
3435
abs (x - y) < Accuracy.medium.absolute

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ open GraphBLAS.FSharp.Objects
99
open GraphBLAS.FSharp.Backend.Matrix
1010
open GraphBLAS.FSharp.Backend.Objects
1111
open GraphBLAS.FSharp.Objects.MatrixExtensions
12+
open GraphBLAS.FSharp.Test
1213

1314
let logger = Log.create "Mxm.Tests"
1415

@@ -60,8 +61,7 @@ let makeTest context q zero isEqual plus mul mxmFun (leftMatrix: 'a [,], rightMa
6061
|> Expect.equal actual expected
6162

6263
let tests =
63-
64-
let getCorrectnessTestName datatype = sprintf "Correctness on %s" datatype
64+
let getCorrectnessTestName = sprintf "Correctness on %s"
6565

6666
let config =
6767
{ Utils.defaultConfig with

tests/GraphBLAS-sharp.Tests/Vector/AssignByMask.fs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ let makeTest<'a when 'a: struct and 'a: equality>
5555
(fillVector: MailboxProcessor<Msg> -> AllocationFlag -> ClVector<'a> -> ClVector<'a> -> ClCell<'a> -> ClVector<'a>)
5656
isComplemented
5757
case
58-
(vector: 'a [], mask: 'a [])
59-
(value: 'a)
58+
(vector: 'a [], mask: 'a [], value: 'a)
6059
=
6160

6261
let leftVector =

tests/GraphBLAS-sharp.Tests/Vector/Reduce.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ let testFixtures case =
8989
createTest<float32> case Utils.float32IsEqual System.Single.MaxValue min <@ min @> "min"
9090
createTest<byte> case (=) System.Byte.MaxValue min <@ min @> "min"
9191
createTest<bool> case (=) false (||) <@ (||) @> "add"
92-
createTest<bool> case (=) true (&&) <@ (&&) @> "multiply"]
92+
createTest<bool> case (=) true (&&) <@ (&&) @> "multiply" ]
9393

9494
let tests =
9595
operationGPUTests "Reduce tests" testFixtures

0 commit comments

Comments
 (0)