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

Move operations to compute_function style #2051

Closed
samtygier-stfc opened this issue Feb 16, 2024 · 0 comments · Fixed by #2125 · May be fixed by #2223
Closed

Move operations to compute_function style #2051

samtygier-stfc opened this issue Feb 16, 2024 · 0 comments · Fixed by #2125 · May be fixed by #2223

Comments

@samtygier-stfc
Copy link
Collaborator

Most of our operations use the partial function style, e.g. in mantidimaging/core/operations/gaussian/gaussian.py

f = ps.create_partial(scipy_ndimage.gaussian_filter, ps.return_to_self, sigma=size, mode=mode, order=order)
...
ps.execute(f, [images.shared_array], images.data.shape[0], progress, msg="Gaussian filter")

We would like to move them to the Compute Function style e.g. in mantidimaging/core/operations/arithmetic/arithmetic.py

ps.run_compute_func(cls.compute_function, images.data.shape[0], images.shared_array, params, progress)
...
    def compute_function(i: int, array: np.ndarray, params: Dict[str, float]):
        array[i] = array[i] * (params["mult"] / params["div"]) + (params["add"] - params["sub"])

The operations_tests.py script is good for checking that the output from the change is not effected. Most operations will need some examples added to the test_cases.json.

See d703d22 for example of changing from partial to compute

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
2 participants