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

Fix for remove_outlier3d #622 #623

Merged
merged 10 commits into from Sep 28, 2023
Merged

Fix for remove_outlier3d #622 #623

merged 10 commits into from Sep 28, 2023

Conversation

dkazanc
Copy link
Contributor

@dkazanc dkazanc commented Sep 24, 2023

The main issue was around memcpy seg faulting, possibly when the total index size overflows int.

But in fact, there were multiple issues:

  • as previously the index could overflow I introduced size_t data type, which should work well across different OS.
  • In the wrapper there was np.ascontiguousarray(arr), out but should be np.ascontiguousarray(arr), np.ascontiguousarray(out).
  • Removed memcpy in the C code and copied array directly in the Python wrapper.

The combination of above seemed solved the problem.

Fixes #622
Closes #624

@pep8speaks
Copy link

pep8speaks commented Sep 24, 2023

Hello @dkazanc! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 445:1: W293 blank line contains whitespace

Comment last updated at 2023-09-28 15:42:00 UTC

source/tomopy/misc/corr.py Outdated Show resolved Hide resolved
@@ -98,7 +100,8 @@ medfilt3D_float(float* Input, float* Output, int radius, int sizefilter_total,
k1 = k + k_m;
if((k1 < 0) || (k1 >= dimZ))
k1 = k;
ValVec[counter] = Input[(dimX * dimY) * k1 + j1 * dimX + i1];
index1 = (size_t)(dimX * dimY * k1 ) + (size_t)(j1 * dimX + i1);
Copy link
Member

Choose a reason for hiding this comment

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

What's the pro/con of using size_t for all indexing and size variables instead of a mix of long and size_t with casting? Do some of these indexing variable need to represent negative integers?

My concern with mixing types and casting on lines like this is that it might still overflow before the cast to size_t? Because the order of operations is to perform the computation inside the parenthesis before casting.

Maybe it should be something like this? Where everything that is not cast is already size_t? This way the multiplications are computed using types that are already size_t.

Suggested change
index1 = (size_t)(dimX * dimY * k1 ) + (size_t)(j1 * dimX + i1);
index1 = dimX * dimY * (size_t)k1 + (size_t)j1 * dimX + (size_t)i1;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, makes total sense. I guess (size_t)(dimX * dimY * k1 ) could overflow before getting converted to size_t. will try to fix...

@carterbox
Copy link
Member

Thanks for starting a fix for this @dkazanc! I was waiting for confirmation that the problem was reproducable with arbitrary arrays. Questions/comments above.

@dkazanc
Copy link
Contributor Author

dkazanc commented Sep 26, 2023

@carterbox are you OK with the corrections? thx

We want to use size_t as much as possible when computing sizes
and linear offsets, but we don't want to break backward compatability
with the ABI.
Faster solves prevent CI from running out of time

CI: Just add solver argument

Remove dead code
Copy link
Member

@carterbox carterbox left a comment

Choose a reason for hiding this comment

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

Thanks, @dkazanc! Sorry for the broken CI stuff.

@carterbox carterbox merged commit 32b6497 into tomopy:master Sep 28, 2023
6 checks passed
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.

Access Violation Error on remove_outlier3d
3 participants