Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group data2array tests #1946

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ steps:
key: unit_data_ndims
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/DataLayouts/unit_ndims.jl"

- label: "Unit: unit_data2array"
key: unit_data2array
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/DataLayouts/unit_data2array.jl"

- label: "Unit: data1d"
key: unit_data1d
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/DataLayouts/data1d.jl"
Expand Down
30 changes: 0 additions & 30 deletions test/DataLayouts/data0d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,6 @@ end
data_if2 = data_f .+ data_if
@test data_if2 isa IF{S}
@test size(data_if2) == (2, 1, 1, 1, 1)

FT = Float64
array = rand(FT, 2, 1)
data = IF{FT, 2}(array)
@test DataLayouts.data2array(data) == reshape(parent(data), :)
@test parent(DataLayouts.array2data(DataLayouts.data2array(data), data)) ==
parent(data)
end

@testset "broadcasting DataF + IFH data object => IFH" begin
Expand All @@ -141,14 +134,6 @@ end
data_ifh2 = data_f .+ data_ifh
@test data_ifh2 isa IFH{S}
@test size(data_ifh2) == (2, 1, 1, 1, 3)


FT = Float64
array = rand(FT, 2, 1, Nh)
data = IFH{FT, 2, Nh}(array)
@test DataLayouts.data2array(data) == reshape(parent(data), :)
@test parent(DataLayouts.array2data(DataLayouts.data2array(data), data)) ==
parent(data)
end

@testset "broadcasting DataF + IJF data object => IJF" begin
Expand All @@ -159,13 +144,6 @@ end
data_ijf2 = data_f .+ data_ijf
@test data_ijf2 isa IJF{S}
@test size(data_ijf2) == (2, 2, 1, 1, 1)

FT = Float64
array = rand(FT, 2, 2, 1)
data = IJF{FT, 2}(array)
@test DataLayouts.data2array(data) == reshape(parent(data), :)
@test parent(DataLayouts.array2data(DataLayouts.data2array(data), data)) ==
parent(data)
end

@testset "broadcasting DataF + IJFH data object => IJFH" begin
Expand All @@ -177,14 +155,6 @@ end
data_ijfh2 = data_f .+ data_ijfh
@test data_ijfh2 isa IJFH{S}
@test size(data_ijfh2) == (2, 2, 1, 1, Nh)

FT = Float64
Nh = 3
array = rand(FT, 2, 2, 1, Nh)
data = IJFH{FT, 2, Nh}(array)
@test DataLayouts.data2array(data) == reshape(parent(data), :)
@test parent(DataLayouts.array2data(DataLayouts.data2array(data), data)) ==
parent(data)
end

@testset "broadcasting DataF + VIFH data object => VIFH" begin
Expand Down
11 changes: 0 additions & 11 deletions test/DataLayouts/data1dx.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,6 @@ import ClimaCore.DataLayouts: VIFH, slab, column, VF, IFH, vindex, slab_index
Complex{FT}(sum(array[:, :, 1, :]), sum(array[:, :, 2, :]))
@test sum(x -> x[2], data) ≈ sum(array[:, :, 3, :])
end

FT = Float64
Nv = 10 # number of vertical levels
Ni = 4 # number of nodal points
Nh = 10 # number of elements
array = rand(FT, Nv, Ni, 1, Nh)
data = VIFH{FT, Nv, Ni, Nh}(array)
@test DataLayouts.data2array(data) ==
reshape(parent(data), DataLayouts.nlevels(data), :)
@test parent(DataLayouts.array2data(DataLayouts.data2array(data), data)) ==
parent(data)
end

@testset "VIFH boundscheck" begin
Expand Down
9 changes: 0 additions & 9 deletions test/DataLayouts/data2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,6 @@ end
@test sum(data.:1) ≈ Complex(sum(array[:, :, 1, :]), sum(array[:, :, 2, :])) atol =
10eps()
@test sum(x -> x[2], data) ≈ sum(array[:, :, 3, :]) atol = 10eps()

FT = Float64
Nij = 4 # number of nodal points
Nh = 10 # number of elements
array = rand(FT, Nij, Nij, 1, Nh)
data = IJFH{FT, Nij, Nh}(array)
@test DataLayouts.data2array(data) == reshape(parent(data), :)
@test parent(DataLayouts.array2data(DataLayouts.data2array(data), data)) ==
parent(data)
end

@testset "IJFH boundscheck" begin
Expand Down
11 changes: 0 additions & 11 deletions test/DataLayouts/data2dx.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,6 @@ import ClimaCore.DataLayouts: VF, IJFH, VIJFH, slab, column, slab_index, vindex
Complex{FT}(sum(array[:, :, :, 1, :]), sum(array[:, :, :, 2, :]))
@test sum(x -> x[2], data) ≈ sum(array[:, :, :, 3, :])
end

FT = Float64
Nv = 10 # number of vertical levels
Ni = 4 # number of nodal points
Nh = 10 # number of elements
array = rand(FT, Nv, Nij, Nij, 1, Nh)
data = VIJFH{FT, Nv, Nij, Nh}(array)
@test DataLayouts.data2array(data) ==
reshape(parent(data), DataLayouts.nlevels(data), :)
@test parent(DataLayouts.array2data(DataLayouts.data2array(data), data)) ==
parent(data)
end

@testset "VIJFH boundscheck" begin
Expand Down
50 changes: 50 additions & 0 deletions test/DataLayouts/unit_data2array.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#=
julia --project
using Revise; include(joinpath("test", "DataLayouts", "unit_data2array.jl"))
=#
using Test
using ClimaCore.DataLayouts

function is_data2array2data_identity(data)
all(
parent(DataLayouts.array2data(DataLayouts.data2array(data), data)) .==
parent(data),
)
end

@testset "data2array & array2data" begin
FT = Float64
Nv = 10 # number of vertical levels
Nij = 4 # number of nodal points
Nh = 10 # number of elements

array = rand(FT, 2, 1)
data = IF{FT, 2}(array)
@test DataLayouts.data2array(data) == reshape(parent(data), :)
@test is_data2array2data_identity(data)

array = rand(FT, 2, 1, Nh)
data = IFH{FT, 2, Nh}(array)
@test DataLayouts.data2array(data) == reshape(parent(data), :)
@test is_data2array2data_identity(data)

array = rand(FT, 2, 2, 1)
data = IJF{FT, 2}(array)
@test DataLayouts.data2array(data) == reshape(parent(data), :)
@test is_data2array2data_identity(data)

array = rand(FT, Nij, Nij, 1, Nh)
data = IJFH{FT, Nij, Nh}(array)
@test DataLayouts.data2array(data) == reshape(parent(data), :)
@test is_data2array2data_identity(data)

array = rand(FT, Nv, Nij, 1, Nh)
data = VIFH{FT, Nv, Nij, Nh}(array)
@test DataLayouts.data2array(data) == reshape(parent(data), Nv, :)
@test is_data2array2data_identity(data)

array = rand(FT, Nv, Nij, Nij, 1, Nh)
data = VIJFH{FT, Nv, Nij, Nh}(array)
@test DataLayouts.data2array(data) == reshape(parent(data), Nv, :)
@test is_data2array2data_identity(data)
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ include("tabulated_tests.jl")
unit_tests = [
UnitTest("DataLayouts fill" ,"DataLayouts/unit_fill.jl"),
UnitTest("DataLayouts ndims" ,"DataLayouts/unit_ndims.jl"),
UnitTest("DataLayouts array<->data" ,"DataLayouts/unit_data2array.jl"),
UnitTest("DataLayouts get_struct" ,"DataLayouts/unit_struct.jl"),
UnitTest("Recursive" ,"RecursiveApply/unit_recursive_apply.jl"),
UnitTest("PlusHalf" ,"Utilities/unit_plushalf.jl"),
Expand Down
Loading