Skip to content

Commit

Permalink
Base._return_type -> MA.promote_operation
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed May 21, 2024
1 parent 06977b1 commit 66a53ad
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/arithmetic.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
function _preallocate_output(X::AlgebraElement, a::Number, op)
T = Base._return_type(op, Tuple{eltype(X),typeof(a)})
T = MA.promote_operation(op, eltype(X), typeof(a))
return similar(X, T)
end

function _preallocate_output(X::AlgebraElement, Y::AlgebraElement, op)
T = Base._return_type(op, Tuple{eltype(X),eltype(Y)})
T = MA.promote_operation(op, eltype(X), eltype(Y))
if coeffs(Y) isa DenseArray # what a hack :)
return similar(Y, T)
end
Expand Down
6 changes: 3 additions & 3 deletions src/coefficients.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ end

function LinearAlgebra.dot(ac::AbstractCoefficients, bc::AbstractCoefficients)
if isempty(values(ac)) || isempty(values(bc))
return zero(Base._return_type(*, Tuple{valtype(ac),valtype(bc)}))
return zero(MA.promote_sum_mul(valtype(ac), valtype(bc)))
else
return sum(c * star(bc[i]) for (i, c) in nonzero_pairs(ac))
end
Expand All @@ -107,7 +107,7 @@ end
function LinearAlgebra.dot(w::AbstractVector, ac::AbstractCoefficients)
@assert key_type(ac) <: Integer
if isempty(values(ac))
return zero(Base._return_type(*, eltype(w), valtype(ac)))
return zero(MA.promote_sum_mul(eltype(w), valtype(ac)))
else
return sum(w[i] * star(v) for (i, v) in nonzero_pairs(ac))
end
Expand All @@ -116,7 +116,7 @@ end
function LinearAlgebra.dot(ac::AbstractCoefficients, w::AbstractVector)
@assert key_type(ac) <: Integer
if isempty(values(ac))
return zero(Base._return_type(*, eltype(w), valtype(ac)))
return zero(MA.promote_sum_mul(eltype(w), valtype(ac)))
else
return sum(v * star(w[i]) for (i, v) in nonzero_pairs(ac))
end
Expand Down
4 changes: 2 additions & 2 deletions src/sparse_coeffs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ end

### temporary convenience? how to handle this?
function __prealloc(X::SparseCoefficients, a::Number, op)
T = Base._return_type(op, Tuple{valtype(X),typeof(a)})
T = MA.promote_operation(op, valtype(X), typeof(a))
return similar(X, T)
end

function __prealloc(X::SparseCoefficients, Y::SparseCoefficients, op)
# this is not even correct for op = *
T = Base._return_type(op, Tuple{valtype(X),valtype(Y)})
T = MA.promote_operation(op, valtype(X), valtype(Y))
return similar(X, T)
end

Expand Down

0 comments on commit 66a53ad

Please sign in to comment.