From 0cb46e4e5cda53433bad027ee76a7a669520dd09 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Mon, 1 Aug 2022 10:27:01 -0400 Subject: [PATCH] define rank(::AbstractVector) (#46169) --- stdlib/LinearAlgebra/src/generic.jl | 2 +- stdlib/LinearAlgebra/test/generic.jl | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/stdlib/LinearAlgebra/src/generic.jl b/stdlib/LinearAlgebra/src/generic.jl index 36ced82eb6c7db..ac56cb191488a9 100644 --- a/stdlib/LinearAlgebra/src/generic.jl +++ b/stdlib/LinearAlgebra/src/generic.jl @@ -978,7 +978,7 @@ function rank(A::AbstractMatrix; atol::Real = 0.0, rtol::Real = (min(size(A)...) tol = max(atol, rtol*s[1]) count(x -> x > tol, s) end -rank(x::Number) = iszero(x) ? 0 : 1 +rank(x::Union{Number,AbstractVector}) = iszero(x) ? 0 : 1 """ tr(M) diff --git a/stdlib/LinearAlgebra/test/generic.jl b/stdlib/LinearAlgebra/test/generic.jl index 805d9eddef8c88..25a89977bce54d 100644 --- a/stdlib/LinearAlgebra/test/generic.jl +++ b/stdlib/LinearAlgebra/test/generic.jl @@ -235,6 +235,8 @@ end @test norm(NaN, 0) === NaN end +@test rank(zeros(4)) == 0 +@test rank(1:10) == 1 @test rank(fill(0, 0, 0)) == 0 @test rank([1.0 0.0; 0.0 0.9],0.95) == 1 @test rank([1.0 0.0; 0.0 0.9],rtol=0.95) == 1