JuliaArrays / JuliaArrays/StaticArrays.jl

Difference between Array reshaping and MArray/SizedArray reshaping

Open
#836 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

arrays bug
Dominant language
Julia
Stars
844
Forks
159
Avg merge
3d 21h
Merged PRs (30d)
3

Description

Modifying a reshaped array modifies the original array as well but it doesn't do that with MArray or SizedArray (a copy is created instead):

julia> vm = @MVector ones(4);

julia> vmr = reshape(vm, Size(2,2))
2×2 MArray{Tuple{2,2},Float64,2,4} with indices SOneTo(2)×SOneTo(2):
 1.0  1.0
 1.0  1.0

julia> vmr[1] = 12
12

julia> vm
4-element MArray{Tuple{4},Float64,1,4} with indices SOneTo(4):
 1.0
 1.0
 1.0
 1.0

Since we now have SizedArray that can wrap any AbstractArray, this could be fixed relatively easily. Is this something worth fixing before the 1.0 release?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the Julia REPL example for reshape on MArray and SizedArray, then trace the reshape entry points and storage behavior for these types versus ordinary Array. Determine the intended aliasing behavior and add regression coverage showing whether reshaped mutations affect the original; done means the behavior is consistent with the agreed semantics.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.