Skip to content

resize! failure after using ldiv! on v1.0 #583

Closed
JuliaLang/julia
#43510
@ChrisRackauckas

Description

@ChrisRackauckas

MWE:

using LinearAlgebra
function resizer()
  v = rand(7)
  w = similar(v)
  W = rand(7,7)
  luw = lu(W)
  ldiv!(vec(w),luw,v)
  resize!(v,3)
end
resizer()

The resize! fails because of the view on v which is built internally. Patching with

function LinearAlgebra.ldiv!(Y::AbstractVecOrMat, A::Factorization, B::AbstractVecOrMat)
    @assert !LinearAlgebra.has_offset_axes(Y, B)
    m, n = size(A, 1), size(A, 2)
    if m > n
        ldiv!(A, B)
        return copyto!(Y, B)
    else
        return ldiv!(A, copyto!(Y, B))
    end
end

fixes the issue. Note that this is a regression from v0.6 where

function resizer()
  v = rand(7)
  w = similar(v)
  W = rand(7,7)
  luw = lufact(W)
  A_ldiv_B!(w,luw,v)
  resize!(v,3)
end
resizer()

works.

Is that viewless version fine? Should I PR it? I don't really understand what supporting using only part of B is for. For reference the dispatch is

https://github.com/JuliaLang/julia/blob/f104ea4ec352519de76e52bf65ea7b3ed2dc6155/stdlib/LinearAlgebra/src/factorization.jl#L98-L108

Why not generally use B?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions