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

Add uplo check to Bidiagonal, Symmetric, and Hermitian base constructors #42466

Merged
merged 1 commit into from
Oct 5, 2021

Conversation

mcognetta
Copy link
Contributor

Currently, most, but not all, constructors for Bidiagonal, Symmetric, and Hermitian matrices perform an uplo check to see if it is valid (U/:U or L/:L). However, the base constructors do not.

This PR adds an uplo check to the base constructors and slightly expands the throw_uplo error message.


For example,

At HEAD:

julia> Bidiagonal(rand(2), rand(1), 'U')
2×2 Bidiagonal{Float64,Array{Float64,1}}:
 0.792414  0.848267
          0.0463521

julia> Bidiagonal(rand(2), rand(1), 'X')
2×2 Bidiagonal{Float64,Array{Float64,1}}:
 0.916971    
 0.0       0.27176

julia> Bidiagonal(rand(2), rand(1), :U)
2×2 Bidiagonal{Float64,Array{Float64,1}}:
 0.810733  0.828368
          0.628955

julia> Bidiagonal(rand(2), rand(1), :X)
ERROR: ArgumentError: uplo argument must be either :U (upper) or :L (lower)
Stacktrace:
 [1] throw_uplo() at /home/mc/github/julia/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/LinearAlgebra.jl:257
 [2] char_uplo at /home/mc/github/julia/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/LinearAlgebra.jl:242 [inlined]
 [3] Bidiagonal(::Array{Float64,1}, ::Array{Float64,1}, ::Symbol) at /home/mc/github/julia/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/bidiag.jl:65
 [4] top-level scope at REPL[6]:1

This PR:

julia> Bidiagonal(rand(2), rand(1), 'U')
2×2 Bidiagonal{Float64, Vector{Float64}}:
 0.970627  0.828208
          0.265786

julia> Bidiagonal(rand(2), rand(1), 'X')
ERROR: ArgumentError: uplo argument must be either :U/'U' (upper) or :L/'L' (lower)
Stacktrace:
 [1] throw_uplo()
   @ LinearAlgebra ~/github/julia-dev/usr/share/julia/stdlib/v1.8/LinearAlgebra/src/LinearAlgebra.jl:265
 [2] Bidiagonal{Float64, Vector{Float64}}(dv::Vector{Float64}, ev::Vector{Float64}, uplo::Char)
   @ LinearAlgebra ~/github/julia-dev/usr/share/julia/stdlib/v1.8/LinearAlgebra/src/bidiag.jl:13
 [3] Bidiagonal(dv::Vector{Float64}, ev::Vector{Float64}, uplo::Char)
   @ LinearAlgebra ~/github/julia-dev/usr/share/julia/stdlib/v1.8/LinearAlgebra/src/bidiag.jl:69
 [4] top-level scope
   @ REPL[3]:1

julia> Bidiagonal(rand(2), rand(1), :U)
2×2 Bidiagonal{Float64, Vector{Float64}}:
 0.768898  0.461265
          0.409974

julia> Bidiagonal(rand(2), rand(1), :X)
ERROR: ArgumentError: uplo argument must be either :U/'U' (upper) or :L/'L' (lower)
Stacktrace:
 [1] throw_uplo()
   @ LinearAlgebra ~/github/julia-dev/usr/share/julia/stdlib/v1.8/LinearAlgebra/src/LinearAlgebra.jl:265
 [2] char_uplo
   @ ~/github/julia-dev/usr/share/julia/stdlib/v1.8/LinearAlgebra/src/LinearAlgebra.jl:251 [inlined]
 [3] Bidiagonal
   @ ~/github/julia-dev/usr/share/julia/stdlib/v1.8/LinearAlgebra/src/bidiag.jl:18 [inlined]
 [4] Bidiagonal(dv::Vector{Float64}, ev::Vector{Float64}, uplo::Symbol)
   @ LinearAlgebra ~/github/julia-dev/usr/share/julia/stdlib/v1.8/LinearAlgebra/src/bidiag.jl:76
 [5] top-level scope
   @ REPL[5]:1

And likewise for Symmetric and Hermitian.

@mcognetta mcognetta closed this Oct 2, 2021
@mcognetta mcognetta reopened this Oct 2, 2021
@mcognetta
Copy link
Contributor Author

Buildbot errors seem unrelated.

@dkarrasch dkarrasch merged commit 3a2441d into JuliaLang:master Oct 5, 2021
Comment on lines -266 to +265
@noinline throw_uplo() = throw(ArgumentError("uplo argument must be either :U (upper) or :L (lower)"))
@noinline throw_uplo() = throw(ArgumentError("uplo argument must be either :U/'U' (upper) or :L/'L' (lower)"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andreasnoack I guess this change here should be reverted according to your comment that the Char representation is internal? The additional checks in this PR should be fine, though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I'd think so. At least temporarily until a decision has been made.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linear algebra Linear algebra
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants