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 join_segmentations dtype error for np.uint #7292

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

aeisenbarth
Copy link
Contributor

@aeisenbarth aeisenbarth commented Jan 11, 2024

Description

When the input arrays are of type uint64, adding a builtin type like 1 produces a float64. This change casts the result back to the input dtype.

Fixes #7291

Checklist

Release note

Summarize the introduced changes in the code block below in one or a few sentences. The
summary will be included in the next release notes automatically:

...

@aeisenbarth
Copy link
Contributor Author

I am wondering whether it's better to cast 1 to the matching dtype before doing the addition, rather than correcting the result afterward. If I knew the dtype, I could do np.uint64(1). But I don't know a way to cast a scalar to a variable type, like "1.astype(s2.dtype)".

Maybe double casting: np.uint(1).astype(s2.dtype)

Copy link
Member

@lagru lagru left a comment

Choose a reason for hiding this comment

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

Thanks @aeisenbarth! This already looks like an improvement.

skimage/segmentation/_join.py Show resolved Hide resolved
@lagru lagru added the 🩹 type: Bug fix Fixes unexpected or incorrect behavior label Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🩹 type: Bug fix Fixes unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

join_segmentations dtype error for np.uint
2 participants