-
Notifications
You must be signed in to change notification settings - Fork 17
Description
When moving a Ref (that itself points to an array of Refs) to another buffer, the original elements are not copied to that buffer.
I don't know if that is intentional, but as it is now I do not have a way to move the original elements to the new buffer.
This is blocking the development of xboinc.
MWE:
import xobjects as xo
import xtrack as xt
class ElementRefClass(xo.UnionRef):
_reftypes = [xt.Drift._XoStruct, xt.Multipole._XoStruct]
class ElementRefData(xo.Struct):
elements = ElementRefClass[:]
class MyStruct(xo.Struct):
refdata = xo.Ref(ElementRefData)
thisref = ElementRefData(elements=[xt.Drift(length=1.7)._xobject, xt.Multipole(knl=[0,1.2])._xobject])
newstruct = MyStruct()
newstruct.refdata = thisref
newstruct.refdata.elements[0]
newstruct.refdata.elements[1]will throw an error. What happens is that the MyStruct is created on a different buffer, and when assigning the field newstruct.refdata = thisref the ElementRefData is moved to the new buffer, but the Drift and Multipole elements themselves are not moved (this, or they are moved but their offsets are not correctly updated - I don't know which is the underlying issue).
I know this can be avoided by creating the ElementRefData in the same buffer as the MyStruct, but this cannot be done in my use case, because in practice the creation of ElementRefData is rather wastefull and creates a buffer that is several times larger than needed (which is an issue for xboinc).