Skip to content

Commit

Permalink
define rank(::AbstractVector) (#46169)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj authored Aug 1, 2022
1 parent d44ba87 commit 0b9eda1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stdlib/LinearAlgebra/src/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions stdlib/LinearAlgebra/test/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0b9eda1

Please sign in to comment.