I am working in a codebase where we use Vectors divided in multiple “viewing windows” (SubArrays) representing some data.
Recently I had to serialize those views and noticed that the information about the parent array and index offsets was lost in the process.
As an example:
import Serialization original = [10.0, 20.0, 30.0, 40.0, 50.0, 60.0] window = @view original[3:5] Serialization.serialize("example", window) serialized = Serialization.deserialize("example")
If we compare
window, both the parent and offsets are wrong.
parent(window) # [10.0, 20.0, 30.0, 40.0, 50.0, 60.0] parent(serialized) # [30.0, 40.0, 50.0] window.indices # (3:5, ) serialized.indices # (1:3, )
This is the behavior even when serializing both the original vector and subarray together.
Serialization.serialize("example2", (original, window)) (w, y) = Serialization.deserialize("example2")
There is no relation between
parent(y) and there seems to be no way (besides searching and matching on it) to find on
y from which indices of
w it is supposed to refer to, an information that I needed.
So, my question is if there is some rationale behind this behavior or I just stumbled into a bug?
And does anybody knows if in the current Julia version (LTS or Release) there is a way to serialize Vectors together SubArrays with losing their linking? Or I will have to roll my own serializer?