Mercurial > repos > public > sbplib_julia
changeset 661:f0ceddeae993 feature/get_boundary_identifiers
Fix and test type stability of boundary_identifiers.
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Sun, 31 Jan 2021 13:04:19 +0100 |
parents | b21fea54ca10 |
children | 138c0fe24eb6 |
files | src/Grids/EquidistantGrid.jl src/Grids/Grids.jl test/testGrids.jl |
diffstat | 3 files changed, 7 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Grids/EquidistantGrid.jl Sat Jan 30 20:30:55 2021 +0100 +++ b/src/Grids/EquidistantGrid.jl Sun Jan 31 13:04:19 2021 +0100 @@ -41,7 +41,6 @@ Base.size(g::EquidistantGrid) = g.size -# TODO: Change to ndims? Seem to be the julia naming convention, at least for AbstractArrays. """ dimension(grid::EquidistantGrid) @@ -103,13 +102,5 @@ CartesianBoundary(2,Lower), ...) """ -function boundary_identifiers(g::EquidistantGrid) - bids = () - for i=1:dimension(g) - for r ∈ (Lower,Upper) - bids = (bids...,CartesianBoundary{i,r}()) - end - end - return bids -end +boundary_identifiers(g::EquidistantGrid) = (((ntuple(i->(CartesianBoundary{i,Lower}(),CartesianBoundary{i,Upper}()),dimension(g)))...)...,) export boundary_identifiers
--- a/src/Grids/Grids.jl Sat Jan 30 20:30:55 2021 +0100 +++ b/src/Grids/Grids.jl Sun Jan 31 13:04:19 2021 +0100 @@ -1,6 +1,7 @@ module Grids using Sbplib.RegionIndices +using Sbplib.LazyTensors export BoundaryIdentifier, CartesianBoundary
--- a/test/testGrids.jl Sat Jan 30 20:30:55 2021 +0100 +++ b/test/testGrids.jl Sun Jan 31 13:04:19 2021 +0100 @@ -57,9 +57,11 @@ @testset "boundary_identifiers" begin g = EquidistantGrid((2,5,3), (0.0,0.0,0.0), (2.0,1.0,3.0)) - @test boundary_identifiers(g) == (CartesianBoundary{1,Lower}(),CartesianBoundary{1,Upper}(), - CartesianBoundary{2,Lower}(),CartesianBoundary{2,Upper}(), - CartesianBoundary{3,Lower}(),CartesianBoundary{3,Upper}()) + bids = (CartesianBoundary{1,Lower}(),CartesianBoundary{1,Upper}(), + CartesianBoundary{2,Lower}(),CartesianBoundary{2,Upper}(), + CartesianBoundary{3,Lower}(),CartesianBoundary{3,Upper}()) + @test boundary_identifiers(g) == bids + @inferred boundary_identifiers(g) end end