@@ -8,74 +8,51 @@ open GraphBLAS.FSharp.Tests
88open GraphBLAS.FSharp .Backend .Common
99open GraphBLAS.FSharp .Backend .Objects .ClContext
1010
11- let logger = Log.create " Copy.Tests"
11+ let logger = Log.create " ClArray. Copy.Tests"
1212
1313let context = Context.defaultContext.ClContext
1414
15- let testCases =
16- let q = Context.defaultContext.Queue
17- q.Error.Add( fun e -> failwithf " %A " e)
18-
19- let getCopyFun copy =
20- fun ( array : array < _ >) ->
21- let wgSize =
22- [| for i in 0 .. 5 -> pown 2 i |]
23- |> Array.filter ( fun i -> array.Length % i = 0 )
24- |> Array.max
15+ let wgSize = 32
2516
26- copy wgSize q HostInterop
17+ let q = Context.defaultContext.Queue
2718
28- let makeTest getCopyFun ( array : array < 'a >) filterFun =
29- if array.Length > 0 then
30- use clArray = context.CreateClArray array
19+ let makeTest < 'a when 'a : equality > copyFun ( array : array < 'a >) = // TODO()
20+ if array.Length > 0 then
21+ use clArray = context.CreateClArray array
3122
32- let copy = getCopyFun array
23+ let actual =
24+ use clActual: ClArray < 'a > = copyFun q HostInterop clArray
3325
34- let actual =
35- use clActual: ClArray < 'a > = copy clArray
26+ let actual = Array.zeroCreate clActual.Length
27+ q.PostAndReply ( fun ch -> Msg.CreateToHostMsg ( clActual, actual , ch ))
3628
37- let actual = Array.zeroCreate clActual.Length
38- q.PostAndReply( fun ch -> Msg.CreateToHostMsg( clActual, actual, ch))
29+ logger.debug (
30+ eventX " Actual is {actual}"
31+ >> setField " actual" $" %A {actual}"
32+ )
3933
40- logger.debug (
41- eventX " Actual is {actual}"
42- >> setField " actual" ( sprintf " %A " actual)
43- )
34+ let expected = array
35+ let actual = actual
4436
45- let expected = filterFun array
46- let actual = filterFun actual
37+ " Array should be equals to original "
38+ |> Expect.sequenceEqual actual expected
4739
48- " Array should be equals to original"
49- |> Expect.sequenceEqual actual expected
40+ let creatTest < 'a when 'a : equality > =
41+ ClArray.copy context wgSize
42+ |> makeTest< 'a>
43+ |> testProperty $" Correctness test on random %A {typeof<'a>} arrays"
5044
51- [ testProperty " Correctness test on random int arrays"
52- <| ( let copy = ClArray.copy context
53- let getCopyFun = getCopyFun copy
54- fun ( array : array < int >) -> makeTest getCopyFun array id)
55-
56- testProperty " Correctness test on random bool arrays"
57- <| ( let copy = ClArray.copy context
58- let getCopyFun = getCopyFun copy
45+ let testCases =
46+ q.Error.Add( fun e -> failwithf " %A " e)
5947
60- fun ( array : array < bool >) -> makeTest getCopyFun array id)
48+ [ creatTest< int>
49+ creatTest< bool>
6150
6251 if Utils.isFloat64Available context.ClDevice then
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.IsNormal))
68-
69- testProperty " Correctness test on random float32 arrays"
70- <| ( let copy = ClArray.copy context
71- let getCopyFun = getCopyFun copy
72-
73- fun ( array : array < float32 >) -> makeTest getCopyFun array ( Array.filter System.Single.IsNormal))
74-
75- testProperty " Correctness test on random byte arrays"
76- <| ( let copy = ClArray.copy context
77- let getCopyFun = getCopyFun copy
52+ creatTest< float>
7853
79- fun ( array : array < byte >) -> makeTest getCopyFun array id) ]
54+ creatTest< float32>
55+ creatTest< byte> ]
8056
81- let tests = testCases |> testList " Array.copy tests"
57+ let tests =
58+ testCases |> testList " ClArray.copy tests"
0 commit comments