Why can't we resize a reinterpreted matrix?

Even if the parent array were a Vector, you couldn’t resize the reinterpreted array. reinterpret made a Base.ReinterpretArray, a wrapper struct with a .parent field referencing the parent array, so it doesn’t actually own its data. If you want to resize it, you have to change the parent array in 1 of 2 unsavory ways:

  1. Resize the parent array implicitly, and I can’t justify mutating any instance implicitly.
  2. Append data to the underlying buffer just for the ReinterpretArray, but now you have to disallow resizing the parent array or else you would corrupt the data belonging to the ReinterpretArray.

That’s not to say that you’re restricted from doing all unsafe things with shared buffers; you can mutate the parent array in ways that changes the wrappers. It’s just in this case your parent array is not 1-dimensional, so you can’t resize it. The linked github issue in the last comment ended on a question I really want answered, though; I had always assumed they drew the resizability line at vectors because appending data for N-1 dimensions along 1 specific dimension would be too large and inflexible a behavior, but it reads like there’s a whole other dimension to the issue.

2 Likes