Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate implicit pseudo-inverses of vectors #50955

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions stdlib/LinearAlgebra/src/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ rank(A::AbstractMatrix, tol::Real) = rank(A,rtol=tol)
nullspace(A::AbstractVector, tol::Real) = nullspace(reshape(A, length(A), 1), rtol= tol)
nullspace(A::AbstractMatrix, tol::Real) = nullspace(A, rtol=tol)
pinv(A::AbstractMatrix{T}, tol::Real) where T = pinv(A, rtol=tol)

# To be removed in 2.0
@deprecate /(x::Number, v::AbstractVector) x*pinv(v)
@deprecate (\)(a::AbstractVector, b::AbstractArray) pinv(a) * b
4 changes: 0 additions & 4 deletions stdlib/LinearAlgebra/src/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,6 @@ function (\)(A::AbstractMatrix, B::AbstractVecOrMat)
return qr(A, ColumnNorm()) \ B
end

(\)(a::AbstractVector, b::AbstractArray) = pinv(a) * b
"""
A / B

Expand Down Expand Up @@ -1163,9 +1162,6 @@ function (/)(A::AbstractVecOrMat, B::AbstractVecOrMat)
size(A,2) != size(B,2) && throw(DimensionMismatch("Both inputs should have the same number of columns"))
return copy(adjoint(adjoint(B) \ adjoint(A)))
end
# \(A::StridedMatrix,x::Number) = inv(A)*x Should be added at some point when the old elementwise version has been deprecated long enough
# /(x::Number,A::StridedMatrix) = x*inv(A)
/(x::Number, v::AbstractVector) = x*pinv(v)

cond(x::Number) = iszero(x) ? Inf : 1.0
cond(x::Number, p) = cond(x)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/LinearAlgebra/test/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ Random.seed!(1)
@test T*b ≈ Tfull*b
@test T'*b ≈ Tfull'*b
if relty != BigFloat # not supported by pivoted QR
@test T/b' ≈ Tfull/b'
@test (@test_deprecated T/b')(@test_deprecated Tfull/b')
end
end
end
Expand Down
29 changes: 24 additions & 5 deletions stdlib/LinearAlgebra/test/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ bimg = randn(n,2)/2
@test_throws DimensionMismatch b'\b
@test_throws DimensionMismatch b\b'
@test norm(a*x - b, 1)/norm(b) < ε*κ*n*2 # Ad hoc, revisit!
@test zeros(eltya,n)\fill(eltya(1),n) ≈ (zeros(eltya,n,1)\fill(eltya(1),n,1))[1,1]
temp = @test_deprecated zeros(eltya,n)\fill(eltya(1),n)
@test temp ≈ (zeros(eltya,n,1)\fill(eltya(1),n,1))[1,1]
end

@testset "Test nullspace" begin
Expand Down Expand Up @@ -1136,6 +1137,22 @@ end
end
end

function test_rdiv_pinv_consistency_dep(a, b)
temp1 = @test_deprecated /(a*b,b)
temp2 = @test_deprecated b/b
@test temp1 ≈ (a*temp2) ≈ (a*b)*pinv(b) ≈ a*(b*pinv(b))
@test typeof(temp1) == a*(typeof(temp2)) == typeof((a*b)*pinv(b)) == typeof(a*(b*pinv(b)))
end
function test_ldiv_pinv_consistency_dep(a, b)
temp1 = @test_deprecated \(a,a*b)
temp2 = @test_deprecated \(a,a)
@test temp1 ≈ temp2*b ≈ (pinv(a)*a)*b ≈ pinv(a)*(a*b)
@test typeof(temp1) == typeof((temp2*b)) == typeof((pinv(a)*a)*b) == typeof(pinv(a)*(a*b))
end
function test_div_pinv_consistency_dep(a, b)
test_rdiv_pinv_consistency_dep(a, b)
test_ldiv_pinv_consistency_dep(a, b)
end
function test_rdiv_pinv_consistency(a, b)
@test (a*b)/b ≈ a*(b/b) ≈ (a*b)*pinv(b) ≈ a*(b*pinv(b))
@test typeof((a*b)/b) == typeof(a*(b/b)) == typeof((a*b)*pinv(b)) == typeof(a*(b*pinv(b)))
Expand All @@ -1156,13 +1173,15 @@ end
cm = rand(elty, 5, 1)
rm = rand(elty, 1, 5)
@testset "dot products" begin
test_div_pinv_consistency(r, c)
test_div_pinv_consistency(rm, c)
test_div_pinv_consistency(r, cm)
test_div_pinv_consistency_dep(r, c)
test_rdiv_pinv_consistency_dep(rm, c)
test_ldiv_pinv_consistency(rm, c)
test_rdiv_pinv_consistency(r, cm)
test_ldiv_pinv_consistency_dep(r, cm)
test_div_pinv_consistency(rm, cm)
end
@testset "outer products" begin
test_div_pinv_consistency(c, r)
test_div_pinv_consistency_dep(c, r)
test_div_pinv_consistency(cm, rm)
end
@testset "matrix/vector" begin
Expand Down
4 changes: 3 additions & 1 deletion stdlib/LinearAlgebra/test/qr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ end
# @test qr(Int[]) == (Int[],1)

B = rand(7,2)
@test (1:7)\B ≈ Vector(1:7)\B
x = @test_deprecated ((1:7)\B)
y = @test_deprecated (Vector(1:7)\B)
@test x ≈ y
end

@testset "Issue 16520" begin
Expand Down