Skip to content

Commit 57ea45a

Browse files
authored
improve type-inference in mul_coefficients (#466)
* improve type-inference in mul_coefficients * special-case Vector branch * fix function call in _mulcoeff_maybeconvert * fix eltype promotion * only convert in out-of-place mul
1 parent 4408d97 commit 57ea45a

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/Operators/general/algebra.jl

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -689,16 +689,11 @@ end
689689
/(B::Operator, c::Number) = B * inv(c)
690690
/(B::Operator, c::Fun) = B * inv(c)
691691

692-
693-
694-
695-
696692
## Operations
697693
for mulcoeff in [:mul_coefficients, :mul_coefficients!]
698694
@eval begin
699695
function $mulcoeff(A::Operator, b)
700-
n = size(b, 1)
701-
ret = n > 0 ? $mulcoeff(view(A, FiniteRange, 1:n), b) : b
696+
mulcoeff_maybeconvert($mulcoeff, A, b)
702697
end
703698

704699
function $mulcoeff(A::TimesOperator, b)
@@ -712,6 +707,18 @@ for mulcoeff in [:mul_coefficients, :mul_coefficients!]
712707
end
713708
end
714709

710+
function _mulcoeff_maybeconvert(f::F, A, b) where {F}
711+
n = size(b, 1)
712+
n > 0 ? f(view(A, FiniteRange, 1:n), b) : b
713+
end
714+
715+
mulcoeff_maybeconvert(f, A, b) = _mulcoeff_maybeconvert(f, A, b)
716+
717+
function mulcoeff_maybeconvert(f::typeof(mul_coefficients), A, b::Vector)
718+
v = _mulcoeff_maybeconvert(f, A, b)
719+
T = promote_type(eltype(A), eltype(b))
720+
convert(Vector{T}, v)
721+
end
715722

716723
function *(A::Operator, b)
717724
ds = domainspace(A)

0 commit comments

Comments
 (0)