Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deep copies and reference counting in Horace. #1816

Open
abuts opened this issue Jan 22, 2025 · 0 comments
Open

deep copies and reference counting in Horace. #1816

abuts opened this issue Jan 22, 2025 · 0 comments
Labels
Discussion Task requiring further discussion

Comments

@abuts
Copy link
Member

abuts commented Jan 22, 2025

Problem description:

Currently Horace would fail if one use asignment to duplicate temporarty filebacked objects. E.g.:

1>>w1 = sqw(filename1,'-filebacked');
2>>w2 = sqw(filename2,'-filebacked');
3>>wt = w1+w2;
4>>wt1=wt;     % wt1= copy(wt);   -- current solution
5>>wt = wt*2;
6>>wt1 =wt1*3; -- FAIL!!!

This is because obects wt and wt1 at row 3 and 4 are using the same .tmp sqw object, Row 5 deletes temporarty sqw file wt object uses after which operation wt1 at row 6 does not have underlying file to work with.

Current solution for that is to use copy operation to create deep copies of filebacked sqw objects. Filebacked sqw objects are usuallt used this way by advanced users so this is not a big problem.

It we implement unique references and reference counting for instruments, detectors and samples, this problem would occur for all sqw objects in operations like that:

>>w1 = sqw(filename);
>>w2 = w1;   % shallow copy. Solution w2 = copy(w1); -- currently not implemented but must be.
>>w1 = w1.set_mod_pulse(…);
>>w2 = w2.set_mod_pulse(…); % FAIL!

This will be immediately noticed and we have to retrain users to use copy for all similar operations, which is usually a problem.

Ultimate solution would be to overload = operator, but Matlab does not allow us to do it. There is matlab.mixin.Copyable superclass, which have sealed signature for copy method and protected method copySingle to overload. This looks like all what is necessary to overload = so may be = is also overloaded by Matlab in matlab.mixin.Copyable. Matlab does not says this anywhere but worth checking the thing.

Purpose of the ticket:

The ticket it to check matlab.mixin.Copyable operations and make political decision of what to do with deep copying if = is impossible to overloaded.

Number of places marked in tests by referencing this ticket are actually test implementation of reference counting. These tests should be enabled if decided to implement reference counting

@abuts abuts added the Discussion Task requiring further discussion label Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion Task requiring further discussion
Projects
None yet
Development

No branches or pull requests

1 participant