Skip to content

Commit ec7ee9d

Browse files
authored
Improve error handling for tensor functions (#238)
* Correct nested interpolation * throw spacemismatch * Add testcase * small fix
1 parent 23b99a4 commit ec7ee9d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/tensors/linalg.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ for f in (:cos, :sin, :tan, :cot, :cosh, :sinh, :tanh, :coth, :atan, :acot, :asi
444444
sf = string(f)
445445
@eval function Base.$f(t::AbstractTensorMap)
446446
domain(t) == codomain(t) ||
447-
error("$sf of a tensor only exist when domain == codomain.")
447+
throw(SpaceMismatch("`$($sf)` of a tensor only exist when domain == codomain"))
448448
T = float(scalartype(t))
449449
tf = similar(t, T)
450450
if T <: Real
@@ -464,7 +464,7 @@ for f in (:sqrt, :log, :asin, :acos, :acosh, :atanh, :acoth)
464464
sf = string(f)
465465
@eval function Base.$f(t::AbstractTensorMap)
466466
domain(t) == codomain(t) ||
467-
error("$sf of a tensor only exist when domain == codomain.")
467+
throw(SpaceMismatch("`$($sf)` of a tensor only exist when domain == codomain"))
468468
T = complex(float(scalartype(t)))
469469
tf = similar(t, T)
470470
for (c, b) in blocks(t)

test/tensors.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,12 @@ for V in spacelist
667667
@test tanh(@constinferred atanh(t7)) t7
668668
t8 = coth(t)
669669
@test coth(@constinferred acoth(t8)) t8
670+
t = randn(T, W, V1) # not square
671+
for f in
672+
(cos, sin, tan, cot, cosh, sinh, tanh, coth, atan, acot, asinh,
673+
sqrt, log, asin, acos, acosh, atanh, acoth)
674+
@test_throws SpaceMismatch f(t)
675+
end
670676
end
671677
end
672678
end

0 commit comments

Comments
 (0)