Skip to content

Commit

Permalink
Merge #1423
Browse files Browse the repository at this point in the history
1423: Clean up MatrixFields tests r=dennisYatunin a=dennisYatunin

Peeled off from #1399. Cleans up `test/MatrixFields` by creating `matrix_field_test_utils.jl` and moving all shared testing code there. Simplifies the matrix broadcast tests by removing a lot of variables that were being passed around as function arguments (e.g., replaces anonymous functions of the form `(args...) -> f(args...)` with `() -> f(args...)`, since both give the same benchmarking results). Sets the default values of `time_ratio_limit` and `max_eps_error_limit` to 10, which should help us avoid random CI failures.

- [x] Code follows the [style guidelines](https://clima.github.io/ClimateMachine.jl/latest/DevDocs/CodeStyle/) OR N/A.
- [x] Unit tests are included OR N/A.
- [x] Code is exercised in an integration test OR N/A.
- [x] Documentation has been added/updated OR N/A.


Co-authored-by: Dennis Yatunin <[email protected]>
  • Loading branch information
bors[bot] and dennisYatunin authored Aug 9, 2023
2 parents 55b7014 + 8990e5d commit fc34a0a
Show file tree
Hide file tree
Showing 4 changed files with 372 additions and 426 deletions.
30 changes: 9 additions & 21 deletions test/MatrixFields/band_matrix_row.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
using Test
using JET
using LinearAlgebra: I

using ClimaCore.MatrixFields
import ClimaCore: Geometry

macro test_all(expression)
return quote
local test_func() = $(esc(expression))
@test test_func() # correctness
@test (@allocated test_func()) == 0 # allocations
@test_opt test_func() # type instabilities
end
end
include("matrix_field_test_utils.jl")

@testset "BandMatrixRow Unit Tests" begin
@test_all DiagonalMatrixRow(1) ==
Expand Down Expand Up @@ -41,14 +29,14 @@ end
TridiagonalMatrixRow(1, 0, 1) / 2 - I ==
zero(PentadiagonalMatrixRow{Int})

T(value) = (; a = (), b = value, c = (value, (; d = (value,)), (;)))
@test_all QuaddiagonalMatrixRow(T(0.5), T(1), T(1), T(1 // 2)) +
BidiagonalMatrixRow(T(-0.5), T(-1 // 2)) ==
QuaddiagonalMatrixRow(T(1), T(1), T(1), T(1)) / 2
@test_all PentadiagonalMatrixRow(T(0), T(0.5), T(1), T(1 // 2), T(0)) -
TridiagonalMatrixRow(T(1), T(0), T(1)) / 2 -
0.5 * DiagonalMatrixRow(T(2)) ==
PentadiagonalMatrixRow(T(0), T(0), T(0), T(0), T(0))
NT = nested_type
@test_all QuaddiagonalMatrixRow(NT(0.5), NT(1), NT(1), NT(1 // 2)) +
BidiagonalMatrixRow(NT(-0.5), NT(-1 // 2)) ==
QuaddiagonalMatrixRow(NT(1), NT(1), NT(1), NT(1)) / 2
@test_all PentadiagonalMatrixRow(NT(0), NT(0.5), NT(1), NT(1 // 2), NT(0)) -
TridiagonalMatrixRow(NT(1), NT(0), NT(1)) / 2 -
0.5 * DiagonalMatrixRow(NT(2)) ==
PentadiagonalMatrixRow(NT(0), NT(0), NT(0), NT(0), NT(0))

@test_throws "Cannot promote" BidiagonalMatrixRow(1, 1) + I
@test_throws "Cannot promote" BidiagonalMatrixRow(1, 1) +
Expand Down
Loading

0 comments on commit fc34a0a

Please sign in to comment.