Skip to content

Commit e5345a7

Browse files
committed
Added generator for bitonic sort
1 parent 077f2a2 commit e5345a7

3 files changed

Lines changed: 111 additions & 29 deletions

File tree

tests/GraphBLAS-sharp.Tests/BackendCommonTests/BitonicSortTests.fs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,26 @@ let testContext =
2727
|> Seq.tryHead
2828

2929
let makeTest (context: ClContext) (q: MailboxProcessor<_>) sort (filter: 'a -> bool) (array: ('n * 'n * 'a) []) =
30-
if array.Length > 0 then
31-
let projection (row: 'n) (col: 'n) (v: 'a) = row, col
30+
let projection (row: 'n) (col: 'n) (v: 'a) = row, col
3231

33-
let rows, cols, vals =
34-
array
35-
|> Array.distinctBy ((<|||) projection)
36-
|> Array.filter (fun (_, _, v) -> filter v)
37-
|> Array.unzip3
32+
let rows, cols, vals =
33+
array
34+
|> Array.distinctBy ((<|||) projection)
35+
|> Array.filter (fun (_, _, v) -> filter v)
36+
|> Array.unzip3
37+
38+
if rows.Length > 0 then
39+
logger.debug (
40+
eventX "Initial size is {size}"
41+
>> setField "size" (sprintf "%A" rows.Length)
42+
)
43+
44+
// logger.debug (
45+
// eventX "Initial are {rows}, {cols}, {vals}"
46+
// >> setField "rows" (sprintf "%A" rows)
47+
// >> setField "cols" (sprintf "%A" cols)
48+
// >> setField "vals" (sprintf "%A" vals)
49+
// )
3850

3951
use clRows = context.CreateClArray rows
4052
use clCols = context.CreateClArray cols
@@ -55,12 +67,12 @@ let makeTest (context: ClContext) (q: MailboxProcessor<_>) sort (filter: 'a -> b
5567

5668
rows, cols, vals
5769

58-
logger.debug (
59-
eventX "Actual are {actualRows}, {actualCols}, {actualVals}"
60-
>> setField "actualRows" (sprintf "%A" actualRows)
61-
>> setField "actualCols" (sprintf "%A" actualCols)
62-
>> setField "actualVals" (sprintf "%A" actualVals)
63-
)
70+
// logger.debug (
71+
// eventX "Actual are {actualRows}, {actualCols}, {actualVals}"
72+
// >> setField "actualRows" (sprintf "%A" actualRows)
73+
// >> setField "actualCols" (sprintf "%A" actualCols)
74+
// >> setField "actualVals" (sprintf "%A" actualVals)
75+
// )
6476

6577
let expectedRows, expectedCols, expectedVals =
6678
(rows, cols, vals)

tests/GraphBLAS-sharp.Tests/Helpers.fs

Lines changed: 79 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -331,14 +331,84 @@ module Generators =
331331
|> genericSparseGenerator false Arb.generate<bool>
332332
|> Arb.fromGen
333333

334-
// type ArrayOfDistinctKeys() =
335-
// // Stack overflow.
336-
// static member ArrayOfDistinctKeysArb() =
337-
// gen {
338-
// let! array = Arb.generate<(uint64 * int)[]>
339-
// return Array.distinctBy (fun (key, _) -> key) array
340-
// }
341-
// |> Arb.fromGen
334+
type ArrayOfDistinctKeys() =
335+
static let arrayOfDistinctKeysGenerator (keysGenerator: Gen<'n>) (valuesGenerator: Gen<'a>) =
336+
let tuplesGenerator =
337+
Gen.map3
338+
<| fun a b c -> a, b, c
339+
<| keysGenerator
340+
<| keysGenerator
341+
<| valuesGenerator
342+
343+
gen {
344+
let! length =
345+
Gen.sized
346+
<| fun size -> Gen.choose (1, size)
347+
348+
let! array =
349+
Gen.arrayOfLength
350+
<| length
351+
<| tuplesGenerator
352+
353+
return Array.distinctBy (fun (r, c, _) -> r, c) array
354+
}
355+
356+
static member IntType() =
357+
arrayOfDistinctKeysGenerator
358+
<| Arb.generate<int>
359+
<| Arb.generate<int>
360+
|> Arb.fromGen
361+
362+
static member FloatType() =
363+
arrayOfDistinctKeysGenerator
364+
<| Arb.generate<int>
365+
<| (Arb.Default.NormalFloat()
366+
|> Arb.toGen
367+
|> Gen.map float)
368+
|> Arb.fromGen
369+
370+
static member SByteType() =
371+
arrayOfDistinctKeysGenerator
372+
<| Arb.generate<int>
373+
<| Arb.generate<sbyte>
374+
|> Arb.fromGen
375+
376+
static member ByteType() =
377+
arrayOfDistinctKeysGenerator
378+
<| Arb.generate<int>
379+
<| Arb.generate<byte>
380+
|> Arb.fromGen
381+
382+
static member Int16Type() =
383+
arrayOfDistinctKeysGenerator
384+
<| Arb.generate<int>
385+
<| Arb.generate<int16>
386+
|> Arb.fromGen
387+
388+
static member UInt16Type() =
389+
arrayOfDistinctKeysGenerator
390+
<| Arb.generate<int>
391+
<| Arb.generate<uint16>
392+
|> Arb.fromGen
393+
394+
static member Int32Type() =
395+
arrayOfDistinctKeysGenerator
396+
<| Arb.generate<int>
397+
<| Arb.generate<int32>
398+
|> Arb.fromGen
399+
400+
static member UInt32Type() =
401+
arrayOfDistinctKeysGenerator
402+
<| Arb.generate<int>
403+
<| Arb.generate<uint32>
404+
|> Arb.fromGen
405+
406+
static member BoolType() =
407+
arrayOfDistinctKeysGenerator
408+
<| Arb.generate<int>
409+
<| Arb.generate<bool>
410+
|> Arb.fromGen
411+
342412

343413
module Utils =
344414
type TestContext =
@@ -356,7 +426,7 @@ module Utils =
356426
typeof<Generators.PairOfMatricesOfCompatibleSize>
357427
typeof<Generators.PairOfSparseMatrixOAndVectorfCompatibleSize>
358428
typeof<Generators.PairOfSparseVectorAndMatrixOfCompatibleSize>
359-
// typeof<Generators.ArrayOfDistinctKeys>
429+
typeof<Generators.ArrayOfDistinctKeys>
360430
] }
361431

362432
let rec cartesian listOfLists =

tests/GraphBLAS-sharp.Tests/Program.fs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ open GraphBLAS.FSharp.IO
1111
let allTests =
1212
testList
1313
"All tests"
14-
[ Backend.BitonicSort.tests
15-
Backend.PrefixSum.tests
16-
Backend.Convert.tests
17-
Backend.RemoveDuplicates.tests
18-
Backend.Copy.tests
19-
Backend.Replicate.tests
20-
Backend.EwiseAdd.tests
14+
[ //Backend.BitonicSort.tests
15+
// Backend.PrefixSum.tests
16+
// Backend.Convert.tests
17+
// Backend.RemoveDuplicates.tests
18+
// Backend.Copy.tests
19+
// Backend.Replicate.tests
20+
// Backend.EwiseAdd.tests
2121
Backend.Transpose.tests
2222
//Matrix.GetTuples.tests
2323
//Matrix.Mxv.tests

0 commit comments

Comments
 (0)