Mercurial > repos > public > sbplib_julia
changeset 572:64f1b269e9fc feature/boundary_ops
Implement apply_transpose for different regions and remove boundschecks to simplify
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 01 Dec 2020 16:02:44 +0100 |
parents | 205238c342da |
children | 4e2490f568aa |
files | src/SbpOperators/boundaryops/boundary_restriction.jl test/testSbpOperators.jl |
diffstat | 2 files changed, 12 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/SbpOperators/boundaryops/boundary_restriction.jl Tue Dec 01 16:01:08 2020 +0100 +++ b/src/SbpOperators/boundaryops/boundary_restriction.jl Tue Dec 01 16:02:44 2020 +0100 @@ -52,16 +52,20 @@ apply_stencil_backwards(e.stencil,v,e.size) end -function LazyTensors.apply_transpose(e::BoundaryRestriction{T,Lower}, v::AbstractArray{T,0}, i) where T - @boundscheck if !(0 < Int(i) <= e.size) - throw(BoundsError()) - end +function LazyTensors.apply_transpose(e::BoundaryRestriction{T,Lower}, v::AbstractArray{T,0}, i::Index{Lower}) where T return e.stencil[Int(i)-1]*v[] end -function LazyTensors.apply_transpose(e::BoundaryRestriction{T,Upper}, v::AbstractArray{T,0}, i) where T - @boundscheck if !(0 < Int(i) <= e.size) - throw(BoundsError()) - end +function LazyTensors.apply_transpose(e::BoundaryRestriction{T,Upper}, v::AbstractArray{T,0}, i::Index{Upper}) where T return e.stencil[e.size[1] - Int(i)]*v[] end + +# Catch all combinations of Lower, Upper and Inner not caught by the two previous methods. +function LazyTensors.apply_transpose(e::BoundaryRestriction{T}, v::AbstractArray{T,0}, i::Index) where T + return zero(T) +end + +function LazyTensors.apply_transpose(e::BoundaryRestriction{T}, v::AbstractArray{T,0}, i) where T + r = getregion(i, closuresize(e), e.size) + apply_transpose(e, v, Index(i,r)) +end
--- a/test/testSbpOperators.jl Tue Dec 01 16:01:08 2020 +0100 +++ b/test/testSbpOperators.jl Tue Dec 01 16:02:44 2020 +0100 @@ -234,8 +234,6 @@ @test (e_r*v)[1] == v[end] @test e_l'*u == [u[]; zeros(10)] @test e_r'*u == [zeros(10); u[]] - @test_throws BoundsError (e_l*v)[2] - @test_throws BoundsError (e_l'*u)[20] # 2D v = rand(11, 15)