Skip to content

Commit 6ff1971

Browse files
committed
refactor: remove use in test
1 parent c5fa0d0 commit 6ff1971

7 files changed

Lines changed: 33 additions & 40 deletions

File tree

tests/GraphBLAS-sharp.Tests/Common/ClArray/Copy.fs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ open Brahma.FSharp
77
open GraphBLAS.FSharp.Tests
88
open GraphBLAS.FSharp.Backend.Common
99
open GraphBLAS.FSharp.Backend.Objects.ClContext
10+
open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions
1011

1112
let logger = Log.create "ClArray.Copy.Tests"
1213

@@ -20,13 +21,10 @@ let config = Utils.defaultConfig
2021

2122
let makeTest<'a when 'a: equality> copyFun (array: array<'a>) =
2223
if array.Length > 0 then
23-
use clArray = context.CreateClArray array
24+
let clArray = context.CreateClArray array
2425

25-
let actual =
26-
use clActual: ClArray<'a> = copyFun q HostInterop clArray
27-
28-
let actual = Array.zeroCreate clActual.Length
29-
q.PostAndReply(fun ch -> Msg.CreateToHostMsg(clActual, actual, ch))
26+
let actual = (copyFun q HostInterop clArray: ClArray<_>).ToHostAndFree q
27+
clArray.Free q
3028

3129
logger.debug (
3230
eventX "Actual is {actual}"

tests/GraphBLAS-sharp.Tests/Common/ClArray/PrefixSum.fs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ open GraphBLAS.FSharp.Backend.Common
88
open GraphBLAS.FSharp.Tests.Context
99
open GraphBLAS.FSharp
1010
open GraphBLAS.FSharp.Backend.Objects.ClCell
11+
open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions
1112

1213
let logger = Log.create "ClArray.PrefixSum.Tests"
1314

@@ -28,12 +29,12 @@ let makeTest plus zero isEqual scan (array: 'a []) =
2829
)
2930

3031
let actual, actualSum =
31-
use clArray = context.CreateClArray array
32+
let clArray = context.CreateClArray array
3233
let (total: ClCell<_>) = scan q clArray zero
3334

34-
let actual = Array.zeroCreate<'a> clArray.Length
35+
let actual = clArray.ToHostAndFree q
3536
let actualSum = total.ToHostAndFree(q)
36-
q.PostAndReply(fun ch -> Msg.CreateToHostMsg(clArray, actual, ch)), actualSum
37+
actual, actualSum
3738

3839
logger.debug (
3940
eventX "Actual is {actual}\n"

tests/GraphBLAS-sharp.Tests/Common/ClArray/Replicate.fs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ open Brahma.FSharp
77
open GraphBLAS.FSharp.Backend.Common
88
open GraphBLAS.FSharp.Tests
99
open GraphBLAS.FSharp.Backend.Objects.ClContext
10+
open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions
1011

1112
let logger = Log.create "Replicate.Tests"
1213

@@ -20,13 +21,10 @@ let config = Utils.defaultConfig
2021

2122
let makeTest<'a when 'a: equality> replicateFun (array: array<'a>) i =
2223
if array.Length > 0 && i > 0 then
23-
use clArray = context.CreateClArray array
24+
let clArray = context.CreateClArray array
2425

25-
let actual =
26-
use clActual: ClArray<'a> = replicateFun q HostInterop clArray i
27-
28-
let actual = Array.zeroCreate clActual.Length
29-
q.PostAndReply(fun ch -> Msg.CreateToHostMsg(clActual, actual, ch))
26+
let actual = (replicateFun q HostInterop clArray i: ClArray<'a>).ToHostAndFree q
27+
clArray.Free q
3028

3129
logger.debug (
3230
eventX $"Actual is {actual}"

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ open Expecto.Logging.Message
66
open Brahma.FSharp
77
open GraphBLAS.FSharp.Backend.Common
88
open GraphBLAS.FSharp.Tests
9+
open GraphBLAS.FSharp.Backend.Objects.ClCell
10+
open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions
911

1012
let logger = Log.create "Reduce.Tests"
1113

@@ -28,15 +30,11 @@ let makeTest (reduce: MailboxProcessor<_> -> ClArray<'a> -> ClCell<'a>) plus zer
2830
)
2931

3032
let actualSum =
31-
use clArray = context.CreateClArray array
33+
let clArray = context.CreateClArray array
3234
let total = reduce clArray
3335

34-
let actualSum = [| zero |]
35-
36-
let sum =
37-
q.PostAndReply(fun ch -> Msg.CreateToHostMsg(total, actualSum, ch))
38-
39-
sum.[0]
36+
clArray.Free q
37+
total.ToHostAndFree q
4038

4139
logger.debug (
4240
eventX "Actual is {actual}\n"

tests/GraphBLAS-sharp.Tests/Common/Reduce/Sum.fs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ open GraphBLAS.FSharp.Backend.Common
88
open GraphBLAS.FSharp.Tests
99
open FSharp.Quotations
1010
open Context
11+
open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions
12+
open GraphBLAS.FSharp.Backend.Objects.ClCell
1113

1214
let logger = Log.create "Sum.Test"
1315

@@ -27,11 +29,11 @@ let makeTest plus zero sum (array: 'a []) =
2729
)
2830

2931
let actualSum =
30-
use clArray = context.CreateClArray array
31-
use total = sum q clArray
32+
let clArray = context.CreateClArray array
33+
let (total: ClCell<_>) = sum q clArray
3234

33-
let actualSum = [| zero |]
34-
q.PostAndReply(fun ch -> Msg.CreateToHostMsg(total, actualSum, ch)).[0]
35+
clArray.Free q
36+
total.ToHostAndFree q
3537

3638
logger.debug (
3739
eventX "Actual is {actual}\n"

tests/GraphBLAS-sharp.Tests/Common/Sort/Bitonic.fs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ open GraphBLAS.FSharp.Backend.Common
77
open Brahma.FSharp
88
open GraphBLAS.FSharp.Tests
99
open GraphBLAS.FSharp.Tests.Context
10+
open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions
1011

1112
module Bitonic =
1213
let logger = Log.create "BitonicSort.Tests"
@@ -32,22 +33,16 @@ module Bitonic =
3233

3334
let rows, cols, vals = Array.unzip3 array
3435

35-
use clRows = context.CreateClArray rows
36-
use clColumns = context.CreateClArray cols
37-
use clValues = context.CreateClArray vals
36+
let clRows = context.CreateClArray rows
37+
let clColumns = context.CreateClArray cols
38+
let clValues = context.CreateClArray vals
3839

3940
let actualRows, actualCols, actualValues =
4041
sort q clRows clColumns clValues
4142

42-
let rows = Array.zeroCreate<'n> clRows.Length
43-
let columns = Array.zeroCreate<'n> clColumns.Length
44-
let values = Array.zeroCreate<'a> clValues.Length
45-
46-
q.Post(Msg.CreateToHostMsg(clRows, rows))
47-
q.Post(Msg.CreateToHostMsg(clColumns, columns))
48-
49-
q.PostAndReply(fun ch -> Msg.CreateToHostMsg(clValues, values, ch))
50-
|> ignore
43+
let rows = clRows.ToHostAndFree q
44+
let columns = clColumns.ToHostAndFree q
45+
let values = clValues.ToHostAndFree q
5146

5247
rows, columns, values
5348

@@ -80,7 +75,6 @@ module Bitonic =
8075
testFixtures<float>
8176

8277
testFixtures<float32>
83-
8478
testFixtures<byte>
8579
testFixtures<bool> ]
8680
|> testList "Backend.Common.BitonicSort tests"

tests/GraphBLAS-sharp.Tests/Matrix/SpGeMM/Expand.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ let processor = Context.defaultContext.Queue
2222

2323
let config =
2424
{ Utils.defaultConfig with
25-
arbitrary = [ typeof<Generators.PairOfMatricesOfCompatibleSize> ] }
25+
arbitrary = [ typeof<Generators.PairOfMatricesOfCompatibleSize> ]
26+
endSize = 500
27+
maxTest = 100 }
2628

2729
let createCSRMatrix array isZero =
2830
Utils.createMatrixFromArray2D CSR array isZero

0 commit comments

Comments
 (0)