From e4af86193b87d5ec85fc16ba1a6dbee5626f6986 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Fri, 6 Sep 2019 18:58:24 -0700 Subject: [PATCH] Normalize index to CartesianIndex in _modify! --- stdlib/LinearAlgebra/src/generic.jl | 11 +++++++---- stdlib/LinearAlgebra/test/matmul.jl | 6 ++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/stdlib/LinearAlgebra/src/generic.jl b/stdlib/LinearAlgebra/src/generic.jl index 1ffdf95ba6978..b5d0a05907cd0 100644 --- a/stdlib/LinearAlgebra/src/generic.jl +++ b/stdlib/LinearAlgebra/src/generic.jl @@ -61,12 +61,15 @@ julia> C """ @inline @propagate_inbounds function _modify!(p::MulAddMul{ais1, bis0}, x, C, idx′) where {ais1, bis0} - # Workaround for performance penalty of splatting a number (#29114): - idx = idx′ isa Integer ? (idx′,) : idx′ + # `idx′` may be an integer, a tuple of integer, or a `CartesianIndex`. + # Let `CartesianIndex` constructor normalize them so that it can be + # used uniformly. It also acts as a workaround for performance penalty + # of splatting a number (#29114): + idx = CartesianIndex(idx′) if bis0 - C[idx...] = p(x) + C[idx] = p(x) else - C[idx...] = p(x, C[idx...]) + C[idx] = p(x, C[idx]) end return end diff --git a/stdlib/LinearAlgebra/test/matmul.jl b/stdlib/LinearAlgebra/test/matmul.jl index d2e9893c71058..022124d7127ec 100644 --- a/stdlib/LinearAlgebra/test/matmul.jl +++ b/stdlib/LinearAlgebra/test/matmul.jl @@ -575,4 +575,10 @@ end end end +@testset "CartesianIndex handling in _modify!" begin + C = rand(10, 10) + A = rand(10, 10) + @test mul!(view(C, 1:10, 1:10), A, 0.5) == A * 0.5 +end + end # module TestMatmul