Skip to content

Commit

Permalink
Make uniformscaling inequal to matrices (#37525)
Browse files Browse the repository at this point in the history
Closes #35485
  • Loading branch information
jakobnissen authored Oct 19, 2020
1 parent c760957 commit 777f23d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Language changes
a function like other operators. The dotted version `.-->` is now parsed as well.
For backwards compatibility, `-->` still parses using its own expression head
instead of `:call`.
* Instances of `UniformScaling` are no longer `isequal` to matrices. Previous
behaviour violated the rule that `isequal(x, y)` implies `hash(x) == hash(y)`.

Compiler/Runtime improvements
-----------------------------
Expand Down
2 changes: 1 addition & 1 deletion stdlib/LinearAlgebra/src/LinearAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Base: \, /, *, ^, +, -, ==
import Base: USE_BLAS64, abs, acos, acosh, acot, acoth, acsc, acsch, adjoint, asec, asech,
asin, asinh, atan, atanh, axes, big, broadcast, ceil, conj, convert, copy, copyto!, cos,
cosh, cot, coth, csc, csch, eltype, exp, fill!, floor, getindex, hcat,
getproperty, imag, inv, isapprox, isone, iszero, IndexStyle, kron, kron!, length, log, map, ndims,
getproperty, imag, inv, isapprox, isequal, isone, iszero, IndexStyle, kron, kron!, length, log, map, ndims,
oneunit, parent, power_by_squaring, print_matrix, promote_rule, real, round, sec, sech,
setindex!, show, similar, sin, sincos, sinh, size, sqrt,
strides, stride, tan, tanh, transpose, trunc, typed_hcat, vec
Expand Down
3 changes: 3 additions & 0 deletions stdlib/LinearAlgebra/src/uniformscaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ function ==(A::StridedMatrix, J::UniformScaling)
return true
end

isequal(A::AbstractMatrix, J::UniformScaling) = false
isequal(J::UniformScaling, A::AbstractMatrix) = false

function isapprox(J1::UniformScaling{T}, J2::UniformScaling{S};
atol::Real=0, rtol::Real=Base.rtoldefault(T,S,atol), nans::Bool=false) where {T<:Number,S<:Number}
isapprox(J1.λ, J2.λ, rtol=rtol, atol=atol, nans=nans)
Expand Down
7 changes: 7 additions & 0 deletions stdlib/LinearAlgebra/test/uniformscaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,13 @@ end
@test 0denseI != 2I != 0denseI # test generic path / inequality on diag
@test alltwos != 2I != alltwos # test generic path / inequality off diag
@test rdenseI != I != rdenseI # test square matrix check

# isequal
@test !isequal(I, I(3))
@test !isequal(I(1), I)
@test !isequal([1], I)
@test isequal(I, 1I)
@test !isequal(2I, 3I)
end

@testset "operations involving I should preserve eltype" begin
Expand Down

0 comments on commit 777f23d

Please sign in to comment.