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

changing operations to compute function #2066

Closed
wants to merge 4 commits into from
Closed

Conversation

ashmeigh
Copy link
Collaborator

@ashmeigh ashmeigh commented Feb 26, 2024

Summary of Changes

This pull request implements a significant shift in how operations are executed within our project, addressing issue. the code is moving from a partial function execution style to adopting a compute_function method across various operations. This transition facilitates a clearer separation between the setup and execution phases of operations.

Key Changes:

  • Introduced a compute_function static method in multiple operation classes, standardising the execution approach. This method encapsulates the core logic for operation execution on a per-slice basis.
  • Adjusted the operation execution framework to support the new compute_function method, ensuring all operations are compatible with this standardised approach.
  • Phased out the use of partial functions for operation execution in favour of the more explicit and structured compute_function

@@ -31,8 +30,8 @@ class RebinFilter(BaseFilter):
filter_name = "Rebin"
link_histograms = True

@staticmethod
def filter_func(images: ImageStack, rebin_param=0.5, mode=None, progress=None) -> ImageStack:
@classmethod
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change back to staticmethod

progress=progress)
images.shared_array = empty_resized_data
params = {'new_shape': new_shape, 'mode': mode}
ps.run_compute_func(cls.compute_function, images.data.shape[0], images.shared_array, params, progress)
Copy link
Collaborator

@samtygier-stfc samtygier-stfc Feb 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ps.run_compute_func(RebinFilter.compute_function, images.data.shape[0], [images.shared_array, empty_resized_data], params, progress)


empty_resized_data = _create_reshaped_array(images, rebin_param)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to keep this

Comment on lines 61 to 64
def compute_function(i: int, array: np.ndarray, params: dict):
new_shape = params['new_shape']
mode = params['mode']
array[i] = resize(array[i], output_shape=new_shape, mode=mode, preserve_range=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    def compute_function(i: int, arrays: list[np.ndarray], params: dict):
        new_shape = params['new_shape']
        mode = params['mode']
        input_array, output_array = arrays
        output_array[i] = resize(input_array[i], output_shape=new_shape, mode=mode, preserve_range=True)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AttributeError: 'numpy.ndarray' object has no attribute 'has_shared_memory'
i have changed the code to fix this

@samtygier-stfc
Copy link
Collaborator

Split into other PRs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants