Skip to content

Fix segfault in Diagonal * OffsetMatrix #45548

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

Merged
merged 2 commits into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions stdlib/LinearAlgebra/src/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ function *(D::Diagonal, transA::Transpose{<:Any,<:AbstractMatrix})
end

@inline function __muldiag!(out, D::Diagonal, B, alpha, beta)
require_one_based_indexing(B)
require_one_based_indexing(out)
if iszero(alpha)
_rmul_or_fill!(out, beta)
Expand All @@ -306,6 +307,7 @@ end
return out
end
@inline function __muldiag!(out, A, D::Diagonal, alpha, beta)
require_one_based_indexing(A)
require_one_based_indexing(out)
if iszero(alpha)
_rmul_or_fill!(out, beta)
Expand Down
13 changes: 13 additions & 0 deletions stdlib/LinearAlgebra/test/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
isdefined(Main, :Furlongs) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "Furlongs.jl"))
using .Main.Furlongs

isdefined(Main, :OffsetArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "OffsetArrays.jl"))
using .Main.OffsetArrays

n=12 #Size of matrix problem to test
Random.seed!(1)

Expand Down Expand Up @@ -785,6 +788,16 @@ end
@test_throws DimensionMismatch lmul!(Diagonal([1]), [1,2,3]) # nearby
end

@testset "Multiplication of a Diagonal with an OffsetArray" begin
# Offset indices should throw
D = Diagonal(1:4)
A = OffsetArray(rand(4,4), 2, 2)
@test_throws ArgumentError D * A
@test_throws ArgumentError A * D
@test_throws ArgumentError mul!(similar(A, size(A)), A, D)
@test_throws ArgumentError mul!(similar(A, size(A)), D, A)
end

@testset "Triangular division by Diagonal #27989" begin
K = 5
for elty in (Float32, Float64, ComplexF32, ComplexF64)
Expand Down