Skip to content

Broadcasted setindex (surprisingly) silently doesn't do anything #498

Description

@kshyatt

MWE:

julia> using BlockArrays, LinearAlgebra

julia> A = mortar(reshape([randn(2, 2), randn(2, 2), randn(2, 2), randn(2, 2)], (2, 2)))
2×2-blocked 4×4 BlockMatrix{Float64}:
 -0.915837  -0.333415-0.458008   0.521461
 -0.566032   1.290960.515333  -0.969364
 ───────────────────────┼──────────────────────
  0.449189  -0.0617162-0.96811   -1.22779 
 -0.155907   1.19382-2.00874   -0.362436

julia> for ii in axes(A, 1), jj in axes(A, 2)
          A[ii, jj] = ifelse( ii == jj, 2.0, 1.0)
       end

julia> A
2×2-blocked 4×4 BlockMatrix{Float64}:
 2.0  1.01.0  1.0
 1.0  2.01.0  1.0
 ──────────┼──────────
 1.0  1.02.0  1.0
 1.0  1.01.0  2.0

julia> A[diagind(A)] .= -1.0
4-element view(reshape(::BlockedArray{…,::Matrix{Float64}}, 16), 1:5:16) with eltype Float64:
 -1.0
 -1.0
 -1.0
 -1.0

julia> A
2×2-blocked 4×4 BlockMatrix{Float64}:
 2.0  1.01.0  1.0
 1.0  2.01.0  1.0
 ──────────┼──────────
 1.0  1.02.0  1.0
 1.0  1.01.0  2.0

It seems like A should've been modified in these last two steps, or warned me that I was doing something unsupported...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions