Mercurial > repos > public > sbplib_julia
changeset 1356:49d03d1169ef feature/variable_derivatives
Remove code designed to help inference because it seems to have been solved elsewhere
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 08 Feb 2023 21:32:48 +0100 |
parents | 102ebdaf7c11 |
children | 74ceac9c91e4 |
files | src/LazyTensors/lazy_tensor_operations.jl src/RegionIndices/RegionIndices.jl src/SbpOperators/boundaryops/boundary_operator.jl src/SbpOperators/volumeops/constant_interior_scaling_operator.jl src/SbpOperators/volumeops/inference_trouble.txt src/SbpOperators/volumeops/volume_operator.jl |
diffstat | 6 files changed, 6 insertions(+), 85 deletions(-) [+] |
line wrap: on
line diff
--- a/src/LazyTensors/lazy_tensor_operations.jl Wed Feb 08 21:21:28 2023 +0100 +++ b/src/LazyTensors/lazy_tensor_operations.jl Wed Feb 08 21:32:48 2023 +0100 @@ -1,5 +1,3 @@ -using Sbplib.RegionIndices - """ TensorApplication{T,R,D} <: LazyArray{T,R} @@ -325,29 +323,3 @@ print(io, "RangeSizeMismatch: ") print(io, "range size $(range_size(err.tm)) of LazyTensor not matching size $(err.sz)") end - -# TODO: These should probably be removed. From new testing in performance/get_region_type_inference it seems that the problems are solved without these -function apply_with_region(op, v, boundary_width::Integer, dim_size::Integer, i) - if 0 < i <= boundary_width - return LazyTensors.apply(op,v,Index(i,Lower)) - elseif boundary_width < i <= dim_size-boundary_width - return LazyTensors.apply(op,v,Index(i,Interior)) - elseif dim_size-boundary_width < i <= dim_size - return LazyTensors.apply(op,v,Index(i,Upper)) - else - error("Bounds error") # TODO: Make this more standard - end -end -# TBD: Can these methods be merge by having a function as an arguement instead? -# TODO: Add inference test that show where things break and how this rewrite fixes it. -function apply_transpose_with_region(op, v, boundary_width::Integer, dim_size::Integer, i) - if 0 < i <= boundary_width - return LazyTensors.apply_transpose(op,v,Index(i,Lower)) - elseif boundary_width < i <= dim_size-boundary_width - return LazyTensors.apply_transpose(op,v,Index(i,Interior)) - elseif dim_size-boundary_width < i <= dim_size - return LazyTensors.apply_transpose(op,v,Index(i,Upper)) - else - error("Bounds error") # TODO: Make this more standard - end -end
--- a/src/RegionIndices/RegionIndices.jl Wed Feb 08 21:21:28 2023 +0100 +++ b/src/RegionIndices/RegionIndices.jl Wed Feb 08 21:32:48 2023 +0100 @@ -65,7 +65,6 @@ error("Bounds error") # TODO: Make this more standard end end -# 2022-02-21: Using the return values of getregion cause type inference to give up in certain cases, for example H*H*v export getregion
--- a/src/SbpOperators/boundaryops/boundary_operator.jl Wed Feb 08 21:21:28 2023 +0100 +++ b/src/SbpOperators/boundaryops/boundary_operator.jl Wed Feb 08 21:32:48 2023 +0100 @@ -54,5 +54,6 @@ end function LazyTensors.apply_transpose(op::BoundaryOperator, v::AbstractArray{<:Any,0}, i) - return LazyTensors.apply_transpose_with_region(op, v, closure_size(op), op.size[1], i) + r = getregion(i, closure_size(op), op.size) + apply_transpose(op, v, Index(i,r)) end
--- a/src/SbpOperators/volumeops/constant_interior_scaling_operator.jl Wed Feb 08 21:21:28 2023 +0100 +++ b/src/SbpOperators/volumeops/constant_interior_scaling_operator.jl Wed Feb 08 21:32:48 2023 +0100 @@ -41,7 +41,8 @@ end function LazyTensors.apply(op::ConstantInteriorScalingOperator, v::AbstractVector, i) - return LazyTensors.apply_with_region(op, v, closure_size(op), op.size[1], i) + r = getregion(i, closure_size(op), op.size[1]) + return LazyTensors.apply(op, v, Index(i, r)) end LazyTensors.apply_transpose(op::ConstantInteriorScalingOperator, v, i) = apply(op, v, i)
--- a/src/SbpOperators/volumeops/inference_trouble.txt Wed Feb 08 21:21:28 2023 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -Innan ändringarna på den här branchen: - -begin - using Sbplib - using Sbplib.Grids - using Sbplib.SbpOperators - - g = EquidistantGrid((10,10),(0.,0.), (1.,1.)) - v = evalOn(g, (x,y)->x^2+y^2+1) - H = inner_product(g, 1., [1/2]) -end - -# Not type stable -LazyTensors.apply(H.t1, H.t2*v, 1,2) -@code_warntype LazyTensors.apply(H.t1, H.t2*v, 1,2) -@code_warntype LazyTensors.apply(H.t1.tm, view(H.t2*v,:,1), 2) - -# Nedan är halvdåliga -@code_warntype LazyTensors.apply(H.t1.tm, view(H.t2*v,1,:), 2) -@code_warntype LazyTensors.apply(H.t1.tm, view(v,1,:), 2) -@code_warntype LazyTensors.apply(H.t1.tm, view(v,:,1), 2) -@code_warntype LazyTensors.apply(H.t1.tm, v[:,1], 2) - - - - - - - - - -begin - using Sbplib - using Sbplib.Grids - using Sbplib.SbpOperators - import Sbplib.SbpOperators: Stencil - using Sbplib.RegionIndices - - g = EquidistantGrid(10,0., 1.) - v = evalOn(g, (x)->x^2+1) - H = inner_product(g, 1., [1/2]) - V = SbpOperators.volume_operator(g, Stencil(1.,center=1), (Stencil(1/2,center=1),), SbpOperators.even,1) - b = SbpOperators.boundary_operator(g, Stencil(1/2,center=1), CartesianBoundary{1,Lower}()) -end - -@code_warntype LazyTensors.apply(H, H*v, 2) -@code_warntype LazyTensors.apply(V, V*v, 2) -@code_warntype LazyTensors.apply(b, b*v, 2) - - - -begin -end
--- a/src/SbpOperators/volumeops/volume_operator.jl Wed Feb 08 21:21:28 2023 +0100 +++ b/src/SbpOperators/volumeops/volume_operator.jl Wed Feb 08 21:32:48 2023 +0100 @@ -32,6 +32,7 @@ end function LazyTensors.apply(op::VolumeOperator, v::AbstractVector, i) - return LazyTensors.apply_with_region(op, v, closure_size(op), op.size[1], i) + r = getregion(i, closure_size(op), op.size[1]) + return LazyTensors.apply(op, v, Index(i, r)) end # TODO: Move this to LazyTensors when we have the region communication down.