Skip to content

Commit 5b2a1f0

Browse files
authored
Fix ambiguities and re-enable Aqua (#162)
1 parent e038c94 commit 5b2a1f0

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

.github/workflows/aqua.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,17 @@ jobs:
2121
Pkg.develop(PackageSpec(path=pwd()))
2222
using MutableArithmetics, Aqua
2323
# Skip ambiguity test for now
24-
Aqua.test_all(MutableArithmetics; ambiguities = false)
24+
Aqua.test_all(
25+
MutableArithmetics;
26+
ambiguities = (
27+
exclude = [
28+
# TODO(odow): These ones are suspect, and may be bugs.
29+
MutableArithmetics.LinearAlgebra.mul!,
30+
# These ones are probably safe to ignore because there are
31+
# only called internally.
32+
MutableArithmetics.buffered_operate_fallback!,
33+
MutableArithmetics.buffered_operate_to_fallback!,
34+
MutableArithmetics.promote_operation_fallback,
35+
],
36+
),
37+
)

src/dispatch.jl

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,10 @@ end
576576
# non-`<:Number` scalar elements, so we define some of these for
577577
# `<:AbstractMutable` scalar elements here.
578578

579-
function Base.:*(A::Scaling, B::_SparseMat{<:AbstractMutable})
579+
function Base.:*(
580+
A::LinearAlgebra.UniformScaling,
581+
B::_SparseMat{<:AbstractMutable},
582+
)
580583
return _SparseMat(
581584
B.m,
582585
B.n,
@@ -597,7 +600,10 @@ function Base.:*(A::Number, B::_SparseMat{<:AbstractMutable})
597600
)
598601
end
599602

600-
function Base.:*(A::_SparseMat{<:AbstractMutable}, B::Scaling)
603+
function Base.:*(
604+
A::_SparseMat{<:AbstractMutable},
605+
B::LinearAlgebra.UniformScaling,
606+
)
601607
return _SparseMat(
602608
A.m,
603609
A.n,
@@ -638,7 +644,20 @@ function Base.:*(A::_SparseMat, B::AbstractMutable)
638644
)
639645
end
640646

641-
function Base.:/(A::_SparseMat{<:AbstractMutable}, B::Scaling)
647+
function Base.:/(
648+
A::_SparseMat{<:AbstractMutable},
649+
B::LinearAlgebra.UniformScaling,
650+
)
651+
return _SparseMat(
652+
A.m,
653+
A.n,
654+
copy(A.colptr),
655+
copy(SparseArrays.rowvals(A)),
656+
SparseArrays.nonzeros(A) ./ B,
657+
)
658+
end
659+
660+
function Base.:/(A::_SparseMat{<:AbstractMutable}, B::Number)
642661
return _SparseMat(
643662
A.m,
644663
A.n,
@@ -702,6 +721,14 @@ function Base.:*(α::Number, A::LinearAlgebra.Hermitian{<:AbstractMutable})
702721
)
703722
end
704723

724+
# Fix ambiguity identified by Aqua.jl.
725+
function Base.:*::Real, A::LinearAlgebra.Hermitian{<:AbstractMutable})
726+
return LinearAlgebra.Hermitian(
727+
α * parent(A),
728+
LinearAlgebra.sym_uplo(A.uplo),
729+
)
730+
end
731+
705732
# These three have specific methods that just redirect to `Matrix{T}` which
706733
# does not work, e.g. if `zero(T)` has a different type than `T`.
707734

src/interface.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ function promote_operation(op::F, args::Vararg{Type,N}) where {F<:Function,N}
105105
return promote_operation_fallback(op, args...)
106106
end
107107

108+
# Fix ambiguities identified by Aqua.jl
109+
promote_operation(::typeof(-)) = Any
110+
promote_operation(::typeof(+)) = Any
111+
promote_operation(::typeof(*)) = Any
112+
108113
# Helpful error for common mistake
109114
function promote_operation(
110115
op::Union{typeof(+),typeof(-),AddSubMul},
@@ -368,6 +373,9 @@ end
368373

369374
buffer_for(::F, args::Vararg{Type,N}) where {F<:Function,N} = nothing
370375

376+
# Fix ambiguity identified by Aqua.jl
377+
buffer_for(::AddSubMul) = nothing
378+
371379
function buffered_operate_to_fallback!(
372380
::IsNotMutable,
373381
buffer,

0 commit comments

Comments
 (0)