-
Notifications
You must be signed in to change notification settings - Fork 586
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
Nifti1Image design prevents efficient caching #1362
Labels
Performance
issues related to computation time or memory usage
Comments
arthurmensch
changed the title
Nifti1Image have states, which prevents efficient caching
Nifti1Image design prevents efficient caching
Jan 23, 2017
Otherwise we could use (ping@ogrisel @GaelVaroquaux). It would be safe and efficient. class UnsafeNifti1Image(Nifti1Image):
def __getstate__(self):
if self.get_filename() is not None:
filename = self.get_filename()
stat = os.stat(filename)
last_modified = stat.st_mtime
state = {'filename': filename,
'last_modified': last_modified}
else:
state = {'dataobj': np.asarray(self._dataobj),
'header': self.header,
'affine': self.affine,
'extra': self.extra}
return state
def __setstate__(self, state):
if 'filename' in state:
print('unpickling')
new_self = Nifti1Image.from_filename(state['filename'])
else:
new_self = Nifti1Image(dataobj=state['dataobj'],
affine=state['affine'],
header=state['header'],
extra=state['extra'])
self.__dict__ = new_self.__dict__ |
Here is the full gist that:
https://gist.github.com/arthurmensch/3331024db4ce08510b3bd51a0469c322 The real proper way to integrate it would be to
ping @GaelVaroquaux what's your opinion on this ? |
Remi-Gau
added
the
Performance
issues related to computation time or memory usage
label
Dec 23, 2023
Maybe worth rechecking if this issue is still valid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a long-standing issue, that we have already tried to adress without success.
yields
This indicates that the cached mask function is not properly recalled the second time.
With the following monkey-patch, it works properly:
Integrating the patch in nilearn does not break any test. Should I try to merge this ? I guess we should do a non regression test based on the code snippet above.
The issue is pretty preocuppying as all users are likely to have double-size masking cache on their disk
The text was updated successfully, but these errors were encountered: