Mercurial > repos > public > sbplib_julia
comparison src/LazyTensors/lazy_tensor_operations.jl @ 1006:d9476fede83d refactor/lazy_tensors
Add check methods for range size
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Sun, 20 Mar 2022 22:22:32 +0100 |
parents | becd95ba0fce |
children | f7a718bcb4da |
comparison
equal
deleted
inserted
replaced
1005:becd95ba0fce | 1006:d9476fede83d |
---|---|
269 LazyOuterProduct(tms::Vararg{LazyTensor}) = foldl(LazyOuterProduct, tms) | 269 LazyOuterProduct(tms::Vararg{LazyTensor}) = foldl(LazyOuterProduct, tms) |
270 | 270 |
271 | 271 |
272 function check_domain_size(tm::LazyTensor, sz) | 272 function check_domain_size(tm::LazyTensor, sz) |
273 if domain_size(tm) != sz | 273 if domain_size(tm) != sz |
274 throw(SizeMismatch(tm,sz)) | 274 throw(DomainSizeMismatch(tm,sz)) |
275 end | 275 end |
276 end | 276 end |
277 | 277 |
278 struct SizeMismatch <: Exception | 278 function check_range_size(tm::LazyTensor, sz) |
279 if range_size(tm) != sz | |
280 throw(RangeSizeMismatch(tm,sz)) | |
281 end | |
282 end | |
283 | |
284 struct DomainSizeMismatch <: Exception | |
279 tm::LazyTensor | 285 tm::LazyTensor |
280 sz | 286 sz |
281 end | 287 end |
282 | 288 |
283 function Base.showerror(io::IO, err::SizeMismatch) | 289 function Base.showerror(io::IO, err::DomainSizeMismatch) |
284 print(io, "SizeMismatch: ") | 290 print(io, "DomainSizeMismatch: ") |
285 print(io, "domain size $(domain_size(err.tm)) of LazyTensor not matching size $(err.sz)") | 291 print(io, "domain size $(domain_size(err.tm)) of LazyTensor not matching size $(err.sz)") |
286 end | 292 end |
293 | |
294 | |
295 struct RangeSizeMismatch <: Exception | |
296 tm::LazyTensor | |
297 sz | |
298 end | |
299 | |
300 function Base.showerror(io::IO, err::RangeSizeMismatch) | |
301 print(io, "RangeSizeMismatch: ") | |
302 print(io, "range size $(range_size(err.tm)) of LazyTensor not matching size $(err.sz)") | |
303 end |