Skip to content

Commit 777f23d

Browse files
authored
Make uniformscaling inequal to matrices (#37525)
Closes #35485
1 parent c760957 commit 777f23d

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ Language changes
3939
a function like other operators. The dotted version `.-->` is now parsed as well.
4040
For backwards compatibility, `-->` still parses using its own expression head
4141
instead of `:call`.
42+
* Instances of `UniformScaling` are no longer `isequal` to matrices. Previous
43+
behaviour violated the rule that `isequal(x, y)` implies `hash(x) == hash(y)`.
4244

4345
Compiler/Runtime improvements
4446
-----------------------------

stdlib/LinearAlgebra/src/LinearAlgebra.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Base: \, /, *, ^, +, -, ==
1111
import Base: USE_BLAS64, abs, acos, acosh, acot, acoth, acsc, acsch, adjoint, asec, asech,
1212
asin, asinh, atan, atanh, axes, big, broadcast, ceil, conj, convert, copy, copyto!, cos,
1313
cosh, cot, coth, csc, csch, eltype, exp, fill!, floor, getindex, hcat,
14-
getproperty, imag, inv, isapprox, isone, iszero, IndexStyle, kron, kron!, length, log, map, ndims,
14+
getproperty, imag, inv, isapprox, isequal, isone, iszero, IndexStyle, kron, kron!, length, log, map, ndims,
1515
oneunit, parent, power_by_squaring, print_matrix, promote_rule, real, round, sec, sech,
1616
setindex!, show, similar, sin, sincos, sinh, size, sqrt,
1717
strides, stride, tan, tanh, transpose, trunc, typed_hcat, vec

stdlib/LinearAlgebra/src/uniformscaling.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ function ==(A::StridedMatrix, J::UniformScaling)
324324
return true
325325
end
326326

327+
isequal(A::AbstractMatrix, J::UniformScaling) = false
328+
isequal(J::UniformScaling, A::AbstractMatrix) = false
329+
327330
function isapprox(J1::UniformScaling{T}, J2::UniformScaling{S};
328331
atol::Real=0, rtol::Real=Base.rtoldefault(T,S,atol), nans::Bool=false) where {T<:Number,S<:Number}
329332
isapprox(J1.λ, J2.λ, rtol=rtol, atol=atol, nans=nans)

stdlib/LinearAlgebra/test/uniformscaling.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,13 @@ end
400400
@test 0denseI != 2I != 0denseI # test generic path / inequality on diag
401401
@test alltwos != 2I != alltwos # test generic path / inequality off diag
402402
@test rdenseI != I != rdenseI # test square matrix check
403+
404+
# isequal
405+
@test !isequal(I, I(3))
406+
@test !isequal(I(1), I)
407+
@test !isequal([1], I)
408+
@test isequal(I, 1I)
409+
@test !isequal(2I, 3I)
403410
end
404411

405412
@testset "operations involving I should preserve eltype" begin

0 commit comments

Comments
 (0)