comparison src/LazyTensors/lazy_tensor_operations.jl @ 919:b41180efb6c2 performance/get_region_type_inference

Start refactor to improve type stability for apply(op,::TensorApplication,...)
author Jonatan Werpers <jonatan@werpers.com>
date Mon, 21 Feb 2022 10:33:58 +0100
parents 76e5682d0e52
children 8b0ff2fddc32 f1c2a4fa0ee1
comparison
equal deleted inserted replaced
911:a378ab959b6f 919:b41180efb6c2
428 428
429 function Base.showerror(io::IO, err::SizeMismatch) 429 function Base.showerror(io::IO, err::SizeMismatch)
430 print(io, "SizeMismatch: ") 430 print(io, "SizeMismatch: ")
431 print(io, "domain size $(domain_size(err.tm)) of TensorMapping not matching size $(err.sz)") 431 print(io, "domain size $(domain_size(err.tm)) of TensorMapping not matching size $(err.sz)")
432 end 432 end
433
434 function apply_with_region(op, v, boundary_width::Integer, dim_size::Integer, i)
435 if 0 < i <= boundary_width
436 return LazyTensors.apply(op,v,Index(i,Lower))
437 elseif boundary_width < i <= dim_size-boundary_width
438 return LazyTensors.apply(op,v,Index(i,Interior))
439 elseif dim_size-boundary_width < i <= dim_size
440 return LazyTensors.apply(op,v,Index(i,Upper))
441 else
442 error("Bounds error") # TODO: Make this more standard
443 end
444 end
445 # TBD: Can these methods be merge by having a function as an arguement instead?
446 # TODO: Add inference test that show where things break and how this rewrite fixes it.
447 function apply_transpose_with_region(op, v, boundary_width::Integer, dim_size::Integer, i)
448 if 0 < i <= boundary_width
449 return LazyTensors.apply_transpose(op,v,Index(i,Lower))
450 elseif boundary_width < i <= dim_size-boundary_width
451 return LazyTensors.apply_transpose(op,v,Index(i,Interior))
452 elseif dim_size-boundary_width < i <= dim_size
453 return LazyTensors.apply_transpose(op,v,Index(i,Upper))
454 else
455 error("Bounds error") # TODO: Make this more standard
456 end
457 end