Skip to content

Commit

Permalink
Merge pull request #30 from JuliaAlgebra/bl/return_type
Browse files Browse the repository at this point in the history
Base._return_type -> MA.promote_operation
  • Loading branch information
kalmarek authored May 27, 2024
2 parents 06977b1 + 66a53ad commit 7901688
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)))

Check warning on line 101 in src/coefficients.jl

View check run for this annotation

Codecov / codecov/patch

src/coefficients.jl#L101

Added line #L101 was not covered by tests
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)))

Check warning on line 110 in src/coefficients.jl

View check run for this annotation

Codecov / codecov/patch

src/coefficients.jl#L110

Added line #L110 was not covered by tests
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)))

Check warning on line 119 in src/coefficients.jl

View check run for this annotation

Codecov / codecov/patch

src/coefficients.jl#L119

Added line #L119 was not covered by tests
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 7901688

Please sign in to comment.