Mercurial > repos > public > sbplib_julia
diff src/LazyTensors/lazy_tensor_operations.jl @ 487:6a6b7eaf9edf feature/compose_identity_mappings
Move exception handling to end of file and update error message.
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Thu, 05 Nov 2020 11:30:53 +0100 |
parents | 4b49f03bdb98 |
children | df566372bb4f |
line wrap: on
line diff
--- a/src/LazyTensors/lazy_tensor_operations.jl Thu Nov 05 10:49:49 2020 +0100 +++ b/src/LazyTensors/lazy_tensor_operations.jl Thu Nov 05 11:30:53 2020 +0100 @@ -92,24 +92,6 @@ end export TensorMappingComposition -function check_domain_size(tm::TensorMapping, sz) - if domain_size(tm) != sz - throw(SizeMismatch(tm,sz)) - end -end - -struct SizeMismatch <: Exception - tm::TensorMapping - sz -end -export SizeMismatch - -function Base.showerror(io::IO, err::SizeMismatch) - print(io, "SizeMismatch: ") - print(io, "attempt to apply TensorMapping with domain size $(domain_size(err.tm)) to a domain of size $(err.sz)") -end - - range_size(tm::TensorMappingComposition) = range_size(tm.t1) domain_size(tm::TensorMappingComposition) = domain_size(tm.t2) @@ -315,3 +297,20 @@ flatten_tuple(t::NTuple{N, Number} where N) = t flatten_tuple(t::Tuple) = ((flatten_tuple.(t)...)...,) # simplify? flatten_tuple(ts::Vararg) = flatten_tuple(ts) + +function check_domain_size(tm::TensorMapping, sz) + if domain_size(tm) != sz + throw(SizeMismatch(tm,sz)) + end +end + +struct SizeMismatch <: Exception + tm::TensorMapping + sz +end +export SizeMismatch + +function Base.showerror(io::IO, err::SizeMismatch) + print(io, "SizeMismatch: ") + print(io, "domain size $(domain_size(err.tm)) of TensorMapping not matching size $(err.sz)") +end