Skip to content

Commit 8c1ad9f

Browse files
committed
Test revival
1 parent 4c620c6 commit 8c1ad9f

5 files changed

Lines changed: 246 additions & 241 deletions

File tree

Lines changed: 74 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,75 @@
11
module Backend.Copy
2-
//
3-
//open Expecto
4-
//open Expecto.Logging
5-
//open Expecto.Logging.Message
6-
//open Brahma.FSharp.OpenCL
7-
//open GraphBLAS.FSharp.Backend
8-
//
9-
//let logger = Log.create "Copy.Tests"
10-
//
11-
//let context =
12-
// let deviceType = ClDeviceType.Default
13-
// let platformName = ClPlatform.Any
14-
// ClContext(platformName, deviceType)
15-
//
16-
//let testCases =
17-
// let q = context.CommandQueue
18-
// q.Error.Add(fun e -> failwithf "%A" e)
19-
//
20-
// let getCopyFun copy =
21-
// fun (array: array<_>) ->
22-
// let wgSize =
23-
// [| for i in 0 .. 5 -> pown 2 i |]
24-
// |> Array.filter (fun i -> array.Length % i = 0)
25-
// |> Array.max
26-
//
27-
// copy q wgSize
28-
//
29-
// let makeTest getCopyFun (array: array<'a>) filterFun =
30-
// if array.Length > 0 then
31-
// use clArray = context.CreateClArray array
32-
//
33-
// let copy = getCopyFun array
34-
//
35-
// let actual =
36-
// use clActual: ClArray<'a> = copy clArray
37-
//
38-
// let actual = Array.zeroCreate clActual.Length
39-
// q.PostAndReply(fun ch -> Msg.CreateToHostMsg(clActual, actual, ch))
40-
//
41-
// logger.debug (
42-
// eventX "Actual is {actual}"
43-
// >> setField "actual" (sprintf "%A" actual)
44-
// )
45-
//
46-
// let expected = filterFun array
47-
// let actual = filterFun actual
48-
//
49-
// "Array should be equals to original"
50-
// |> Expect.sequenceEqual actual expected
51-
//
52-
// [ testProperty "Correctness test on random int arrays"
53-
// <| (let copy = ClArray.copy context
54-
// let getCopyFun = getCopyFun copy
55-
// fun (array: array<int>) -> makeTest getCopyFun array id)
56-
//
57-
// testProperty "Correctness test on random bool arrays"
58-
// <| (let copy = ClArray.copy context
59-
// let getCopyFun = getCopyFun copy
60-
//
61-
// fun (array: array<bool>) -> makeTest getCopyFun array id)
62-
//
63-
// testProperty "Correctness test on random float arrays"
64-
// <| (let copy = ClArray.copy context
65-
// let getCopyFun = getCopyFun copy
66-
//
67-
// fun (array: array<float>) -> makeTest getCopyFun array (Array.filter (System.Double.IsNaN >> not)))
68-
//
69-
// testProperty "Correctness test on random byte arrays"
70-
// <| (let copy = ClArray.copy context
71-
// let getCopyFun = getCopyFun copy
72-
//
73-
// fun (array: array<byte>) -> makeTest getCopyFun array id)
74-
//
75-
// ]
76-
//
77-
//let tests = testCases |> testList "Array.copy tests"
2+
3+
open Expecto
4+
open Expecto.Logging
5+
open Expecto.Logging.Message
6+
open Brahma.FSharp
7+
open GraphBLAS.FSharp.Backend
8+
open GraphBLAS.FSharp.Tests
9+
10+
let logger = Log.create "Copy.Tests"
11+
12+
let context = Utils.defaultContext.ClContext
13+
14+
let testCases =
15+
let q = Utils.defaultContext.Queue
16+
q.Error.Add(fun e -> failwithf "%A" e)
17+
18+
let getCopyFun copy =
19+
fun (array: array<_>) ->
20+
let wgSize =
21+
[| for i in 0 .. 5 -> pown 2 i |]
22+
|> Array.filter (fun i -> array.Length % i = 0)
23+
|> Array.max
24+
25+
copy q wgSize
26+
27+
let makeTest getCopyFun (array: array<'a>) filterFun =
28+
if array.Length > 0 then
29+
use clArray = context.CreateClArray array
30+
31+
let copy = getCopyFun array
32+
33+
let actual =
34+
use clActual: ClArray<'a> = copy clArray
35+
36+
let actual = Array.zeroCreate clActual.Length
37+
q.PostAndReply(fun ch -> Msg.CreateToHostMsg(clActual, actual, ch))
38+
39+
logger.debug (
40+
eventX "Actual is {actual}"
41+
>> setField "actual" (sprintf "%A" actual)
42+
)
43+
44+
let expected = filterFun array
45+
let actual = filterFun actual
46+
47+
"Array should be equals to original"
48+
|> Expect.sequenceEqual actual expected
49+
50+
[ testProperty "Correctness test on random int arrays"
51+
<| (let copy = ClArray.copy context
52+
let getCopyFun = getCopyFun copy
53+
fun (array: array<int>) -> makeTest getCopyFun array id)
54+
55+
testProperty "Correctness test on random bool arrays"
56+
<| (let copy = ClArray.copy context
57+
let getCopyFun = getCopyFun copy
58+
59+
fun (array: array<bool>) -> makeTest getCopyFun array id)
60+
61+
testProperty "Correctness test on random float arrays"
62+
<| (let copy = ClArray.copy context
63+
let getCopyFun = getCopyFun copy
64+
65+
fun (array: array<float>) -> makeTest getCopyFun array (Array.filter (System.Double.IsNaN >> not)))
66+
67+
testProperty "Correctness test on random byte arrays"
68+
<| (let copy = ClArray.copy context
69+
let getCopyFun = getCopyFun copy
70+
71+
fun (array: array<byte>) -> makeTest getCopyFun array id)
72+
73+
]
74+
75+
let tests = testCases |> testList "Array.copy tests"
Lines changed: 75 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,76 @@
11
module Backend.RemoveDuplicates
2-
//
3-
//open Expecto
4-
//open Expecto.Logging
5-
//open Expecto.Logging.Message
6-
//open Brahma.FSharp.OpenCL
7-
//open GraphBLAS.FSharp.Backend
8-
//
9-
//let logger = Log.create "RemoveDuplicates.Tests"
10-
//
11-
//let context =
12-
// let deviceType = ClDeviceType.Default
13-
// let platformName = ClPlatform.Any
14-
// ClContext(platformName, deviceType)
15-
//
16-
//let testCases =
17-
// let removeDuplicates_wg_1 = ClArray.removeDuplications context 1
18-
// let removeDuplicates_wg_2 = ClArray.removeDuplications context 2
19-
// let removeDuplicates_wg_32 = ClArray.removeDuplications context 32
20-
// let q = context.CommandQueue
21-
// q.Error.Add(fun e -> failwithf "%A" e)
22-
//
23-
// [ testCase "Simple correctness test"
24-
// <| fun () ->
25-
// let array = [| 1; 2; 2; 3; 3; 3 |]
26-
//
27-
// let clArray = context.CreateClArray array
28-
//
29-
// let actual =
30-
// let clActual = removeDuplicates_wg_2 q clArray
31-
//
32-
// let actual = Array.zeroCreate clActual.Length
33-
// q.PostAndReply(fun ch -> Msg.CreateToHostMsg(clActual, actual, ch))
34-
//
35-
// logger.debug (
36-
// eventX "Actual is {actual}"
37-
// >> setField "actual" (sprintf "%A" actual)
38-
// )
39-
//
40-
// let expected = [| 1; 2; 3 |]
41-
//
42-
// "Array should be without duplicates"
43-
// |> Expect.sequenceEqual actual expected
44-
//
45-
// testProperty "Correctness test on random int arrays"
46-
// <| fun (array: array<int>) ->
47-
// let array = Array.sort array
48-
//
49-
// if array.Length > 0 then
50-
// let clArray = context.CreateClArray array
51-
//
52-
// let removeDuplicates =
53-
// if array.Length % 32 = 0 then
54-
// removeDuplicates_wg_32
55-
// else
56-
// removeDuplicates_wg_2
57-
//
58-
// let actual =
59-
// let clActual = removeDuplicates q clArray
60-
//
61-
// let actual = Array.zeroCreate clActual.Length
62-
// q.PostAndReply(fun ch -> Msg.CreateToHostMsg(clActual, actual, ch))
63-
//
64-
// logger.debug (
65-
// eventX "Actual is {actual}"
66-
// >> setField "actual" (sprintf "%A" actual)
67-
// )
68-
//
69-
// let expected = Seq.distinct array |> Array.ofSeq
70-
//
71-
// "Array should be without duplicates"
72-
// |> Expect.sequenceEqual actual expected
73-
//
74-
// ]
75-
//
76-
//let tests =
77-
// testCases
78-
// |> testList "Array.removeDuplicates tests"
2+
3+
open Expecto
4+
open Expecto.Logging
5+
open Expecto.Logging.Message
6+
open Brahma.FSharp
7+
open GraphBLAS.FSharp.Backend
8+
open GraphBLAS.FSharp.Tests
9+
10+
let logger = Log.create "RemoveDuplicates.Tests"
11+
12+
let context = Utils.defaultContext.ClContext
13+
14+
let testCases =
15+
let removeDuplicates_wg_1 = ClArray.removeDuplications context 1
16+
let removeDuplicates_wg_2 = ClArray.removeDuplications context 2
17+
let removeDuplicates_wg_32 = ClArray.removeDuplications context 32
18+
let q = Utils.defaultContext.Queue
19+
q.Error.Add(fun e -> failwithf "%A" e)
20+
21+
[ testCase "Simple correctness test"
22+
<| fun () ->
23+
let array = [| 1; 2; 2; 3; 3; 3 |]
24+
25+
let clArray = context.CreateClArray array
26+
27+
let actual =
28+
let clActual = removeDuplicates_wg_2 q clArray
29+
30+
let actual = Array.zeroCreate clActual.Length
31+
q.PostAndReply(fun ch -> Msg.CreateToHostMsg(clActual, actual, ch))
32+
33+
logger.debug (
34+
eventX "Actual is {actual}"
35+
>> setField "actual" (sprintf "%A" actual)
36+
)
37+
38+
let expected = [| 1; 2; 3 |]
39+
40+
"Array should be without duplicates"
41+
|> Expect.sequenceEqual actual expected
42+
43+
testProperty "Correctness test on random int arrays"
44+
<| fun (array: array<int>) ->
45+
let array = Array.sort array
46+
47+
if array.Length > 0 then
48+
let clArray = context.CreateClArray array
49+
50+
let removeDuplicates =
51+
if array.Length % 32 = 0 then
52+
removeDuplicates_wg_32
53+
else
54+
removeDuplicates_wg_2
55+
56+
let actual =
57+
let clActual = removeDuplicates q clArray
58+
59+
let actual = Array.zeroCreate clActual.Length
60+
q.PostAndReply(fun ch -> Msg.CreateToHostMsg(clActual, actual, ch))
61+
62+
logger.debug (
63+
eventX "Actual is {actual}"
64+
>> setField "actual" (sprintf "%A" actual)
65+
)
66+
67+
let expected = Seq.distinct array |> Array.ofSeq
68+
69+
"Array should be without duplicates"
70+
|> Expect.sequenceEqual actual expected
71+
72+
]
73+
74+
let tests =
75+
testCases
76+
|> testList "Array.removeDuplicates tests"

0 commit comments

Comments
 (0)