1- module Backend.COOMatrix. EwiseAdd
1+ module Backend.EwiseAdd
22
33open FsCheck
44open Expecto
@@ -10,7 +10,7 @@ open GraphBLAS.FSharp
1010open GraphBLAS.FSharp .Tests .Generators
1111open GraphBLAS.FSharp .Tests .Utils
1212
13- let logger = Log.create " COOMatrix. EwiseAdd.Tests"
13+ let logger = Log.create " EwiseAdd.Tests"
1414
1515let context =
1616 let deviceType = ClDeviceType.Default
@@ -41,39 +41,40 @@ let checkResult op zero (baseMtx1: 'a [,]) (baseMtx2: 'a [,]) (actual: Matrix<'a
4141 let actual2D =
4242 Array2D.create actual.RowCount actual.ColumnCount zero
4343
44- match actual with
45- | MatrixCOO actual ->
46- for i in 0 .. actual.Rows.Length - 1 do
47- actual2D.[ actual.Rows.[ i], actual.Columns.[ i]] <- actual.Values.[ i]
44+ let actual2D =
45+ match actual with
46+ | MatrixCOO actual ->
47+ for i in 0 .. actual.Rows.Length - 1 do
48+ actual2D.[ actual.Rows.[ i], actual.Columns.[ i]] <- actual.Values.[ i]
49+
50+ actual2D
51+ | MatrixCSR actual ->
52+ let rowIndices =
53+ Array.create actual.ColumnIndices.Length 0
4854
49- for i in 0 .. rows - 1 do
50- for j in 0 .. columns - 1 do
51- Expect.equal actual2D.[ i, j] expected.[ i, j] " Elements of matrices should be equals."
52- | MatrixCSR actual ->
53- let rowIndices =
54- Array.create actual.ColumnIndices.Length 0
55+ for i in 0 .. actual.RowCount - 1 do
56+ if i < actual.RowCount - 1 then
57+ let rowStart = actual.RowPointers.[ i]
58+ let rowEnd = actual.RowPointers.[ i + 1 ]
59+ let rowLength = rowEnd - rowStart
5560
56- for i in 0 .. actual.RowCount - 1 do
57- if i < actual.RowCount - 1 then
58- let rowStart = actual.RowPointers .[ i ]
59- let rowEnd = actual.RowPointers.[ i + 1 ]
60- let rowLength = rowEnd - rowStart
61+ for j in 0 .. rowLength - 1 do
62+ rowIndices .[ rowStart + j ] <- i
63+ else
64+ let rowStart = actual.RowPointers.[ actual.RowCount - 1 ]
65+ let rowLength = rowIndices.Length - rowStart
6166
62- for j in 0 .. rowLength - 1 do
63- rowIndices.[ rowStart + j] <- i
64- else
65- let rowStart = actual.RowPointers.[ actual.RowCount - 1 ]
66- let rowLength = rowIndices.Length - rowStart
67+ for j in 0 .. rowLength - 1 do
68+ rowIndices.[ rowStart + j] <- i
6769
68- for j in 0 .. rowLength - 1 do
69- rowIndices.[ rowStart + j ] <- i
70+ for i in 0 .. rowIndices.Length - 1 do
71+ actual2D .[ rowIndices.[ i ], actual.ColumnIndices .[ i ]] <- actual.Values .[ i ]
7072
71- for i in 0 .. rowIndices.Length - 1 do
72- actual2D.[ rowIndices.[ i], actual.ColumnIndices.[ i]] <- actual.Values.[ i]
73+ actual2D
7374
74- for i in 0 .. rows - 1 do
75- for j in 0 .. columns - 1 do
76- Expect.equal actual2D.[ i, j] expected.[ i, j] " Elements of matrices should be equals."
75+ for i in 0 .. rows - 1 do
76+ for j in 0 .. columns - 1 do
77+ Expect.equal actual2D.[ i, j] expected.[ i, j] " Elements of matrices should be equals."
7778
7879let testCases =
7980 let q = context.Provider.CommandQueue
@@ -217,17 +218,29 @@ let testCases =
217218
218219 | _ -> failwith " No other types of matrices tested yet."
219220
220- [ testProperty " Correctness test on random int arrays "
221+ [ testProperty " Correctness test on random int matrices COO "
221222 <| ( fun size -> makeTest context ( PairOfSparseMatricesOfEqualSize.IntType()) size COO (+) <@ (+) @> 0 )
222223
223- testProperty " Correctness test on random bool arrays "
224+ testProperty " Correctness test on random bool matrices COO "
224225 <| ( fun size -> makeTest context ( PairOfSparseMatricesOfEqualSize.BoolType()) size COO (||) <@ (||) @> false )
225226
226- testProperty " Correctness test on random float arrays "
227+ testProperty " Correctness test on random float matrices COO "
227228 <| ( fun size -> makeTest context ( PairOfSparseMatricesOfEqualSize.FloatType()) size COO (+) <@ (+) @> 0.0 )
228229
229- testProperty " Correctness test on random byte arrays"
230- <| ( fun size -> makeTest context ( PairOfSparseMatricesOfEqualSize.ByteType()) size COO (+) <@ (+) @> 0 uy) ]
230+ testProperty " Correctness test on random byte matrices COO"
231+ <| ( fun size -> makeTest context ( PairOfSparseMatricesOfEqualSize.ByteType()) size COO (+) <@ (+) @> 0 uy)
232+
233+ testProperty " Correctness test on random int matrices CSR"
234+ <| ( fun size -> makeTest context ( PairOfSparseMatricesOfEqualSize.IntType()) size CSR (+) <@ (+) @> 0 )
235+
236+ testProperty " Correctness test on random bool matrices CSR"
237+ <| ( fun size -> makeTest context ( PairOfSparseMatricesOfEqualSize.BoolType()) size CSR (||) <@ (||) @> false )
238+
239+ testProperty " Correctness test on random float matrices CSR"
240+ <| ( fun size -> makeTest context ( PairOfSparseMatricesOfEqualSize.FloatType()) size CSR (+) <@ (+) @> 0.0 )
241+
242+ testProperty " Correctness test on random byte matrices CSR"
243+ <| ( fun size -> makeTest context ( PairOfSparseMatricesOfEqualSize.ByteType()) size CSR (+) <@ (+) @> 0 uy) ]
231244
232245let tests =
233- testCases |> testList " COOMatrix .EwiseAdd tests"
246+ testCases |> testList " Backend .EwiseAdd tests"
0 commit comments