Skip to content

dot(x,A,x) fails for 1x1 SymTridiagonal #945

Closed
JuliaLang/julia
#46473
@stevengj

Description

@stevengj

Bug found by @smataigne:

julia> dot([1], SymTridiagonal([1],Int[]), [1])
ERROR: BoundsError: attempt to access 1-element Vector{Int64} at index [2]
Stacktrace:
 [1] getindex
   @ ./array.jl:924 [inlined]
 [2] dot(x::Vector{Int64}, S::SymTridiagonal{Int64, Vector{Int64}}, y::Vector{Int64})
   @ LinearAlgebra /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/LinearAlgebra/src/tridiag.jl:265

This line assumes the matrix is at least 2x2: https://github.com/JuliaLang/julia/blob/18fa3835a78bdbe5982daf32b8aa84ab7fd2362e/stdlib/LinearAlgebra/src/tridiag.jl#L266-L267

Recommendation: change this check to:

 if nx  1
    nx == 0 && return dot(zero(eltype(x)), zero(eltype(S)), zero(eltype(y)))
    return dot(x[1], S.dv[1], y[1])
end

(Rationale: the common case is nx > 1, so better to have a single check nx ≤ 1 in that circumstance than separate nx == 0 and nx == 1 checks.)

Just needs someone to create a PR with this text and add a patch.

cc @dkarrasch who added this code in JuliaLang/julia#32739.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions