|
| 1 | +module GraphBLAS.FSharp.Tests.Matrix.ByRows |
| 2 | + |
| 3 | +open Expecto |
| 4 | +open GraphBLAS.FSharp.Tests |
| 5 | +open GraphBLAS.FSharp.Backend |
| 6 | +open GraphBLAS.FSharp.Objects |
| 7 | +open GraphBLAS.FSharp.Backend.Matrix |
| 8 | +open GraphBLAS.FSharp.Backend.Objects |
| 9 | +open GraphBLAS.FSharp.Backend.Objects.ClContext |
| 10 | +open GraphBLAS.FSharp.Objects.ClVectorExtensions |
| 11 | + |
| 12 | +let context = Context.defaultContext.ClContext |
| 13 | + |
| 14 | +let processor = Context.defaultContext.Queue |
| 15 | + |
| 16 | +let config = Utils.defaultConfig |
| 17 | + |
| 18 | +let makeTest<'a when 'a : struct> isEqual zero testFun (array: 'a [,]) = |
| 19 | + |
| 20 | + let matrix = Matrix.CSR.FromArray2D(array, isEqual zero) |
| 21 | + |
| 22 | + if matrix.NNZ > 0 then |
| 23 | + |
| 24 | + let clMatrix = matrix.ToDevice context |
| 25 | + |
| 26 | + let rows = testFun processor HostInterop clMatrix |
| 27 | + |
| 28 | + "Rows count must be the same" |
| 29 | + |> Expect.equal (Seq.length rows) (Array2D.length1 array) |
| 30 | + |
| 31 | + rows |
| 32 | + |> Seq.iteri (fun index -> function |
| 33 | + | Some (actualRow: ClVector.Sparse<_>) -> |
| 34 | + let expectedRow = Vector.Sparse.FromArray(array.[index, *], (isEqual zero)) |
| 35 | + let actualHost = actualRow.ToHost processor |
| 36 | + |
| 37 | + Utils.compareSparseVectors isEqual actualHost expectedRow |
| 38 | + | None -> |
| 39 | + "Expected row must be None" |
| 40 | + |> Expect.isFalse (Array.exists ((<<) not <| isEqual zero) array.[index, *])) |
| 41 | + |
| 42 | +let createTest isEqual (zero: 'a) = |
| 43 | + CSR.Matrix.byRows context Utils.defaultWorkGroupSize |
| 44 | + |> makeTest<'a> isEqual zero |
| 45 | + |> testPropertyWithConfig config $"test on %A{typeof<'a>}" |
| 46 | + |
| 47 | +let tests = |
| 48 | + [ createTest (=) 0 |
| 49 | + |
| 50 | + if Utils.isFloat64Available context.ClDevice then |
| 51 | + createTest Utils.floatIsEqual 0.0 |
| 52 | + |
| 53 | + createTest Utils.float32IsEqual 0.0f |
| 54 | + createTest (=) false ] |
| 55 | + |> testList "CSR byRows" |
0 commit comments