Mercurial > repos > public > sbplib_julia
comparison src/LazyTensors/lazy_tensor_operations.jl @ 481:2fde16253a84 feature/compose_identity_mappings
Proposal for SizeMismatch exception
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 05 Nov 2020 10:25:30 +0100 |
parents | c1a366331e75 |
children | f0f272666a64 |
comparison
equal
deleted
inserted
replaced
480:c1a366331e75 | 481:2fde16253a84 |
---|---|
95 function check_matching_size(t1::TensorMapping, t2::TensorMapping) | 95 function check_matching_size(t1::TensorMapping, t2::TensorMapping) |
96 if domain_size(t1) != range_size(t2) | 96 if domain_size(t1) != range_size(t2) |
97 throw(DimensionMismatch("the first argument has domain size $(domain_size(t1)) while the second has range size $(range_size(t2)) ")) | 97 throw(DimensionMismatch("the first argument has domain size $(domain_size(t1)) while the second has range size $(range_size(t2)) ")) |
98 end | 98 end |
99 end | 99 end |
100 | |
101 struct SizeMismatch <: Exception | |
102 tm::TensorMapping | |
103 sz::NTuple{N,Int} | |
104 end | |
105 | |
106 function showerror(io::IO, err::SizeMismatch) | |
107 print(io, "SizeMismatch: ") | |
108 print(io, "attempt to apply TensorMapping with domain size $(domain_size(tm)) to a domain of size $sz") | |
109 end | |
110 | |
100 | 111 |
101 range_size(tm::TensorMappingComposition) = range_size(tm.t1) | 112 range_size(tm::TensorMappingComposition) = range_size(tm.t1) |
102 domain_size(tm::TensorMappingComposition) = domain_size(tm.t2) | 113 domain_size(tm::TensorMappingComposition) = domain_size(tm.t2) |
103 | 114 |
104 function apply(c::TensorMappingComposition{T,R,K,D}, v::AbstractArray{T,D}, I::Vararg{S,R} where S) where {T,R,K,D} | 115 function apply(c::TensorMappingComposition{T,R,K,D}, v::AbstractArray{T,D}, I::Vararg{S,R} where S) where {T,R,K,D} |