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

RuntimeWarning: overflow encountered in scalar subtract #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aghaeifar
Copy link
Contributor

In the following method (file map_twix.py):

def par_offset(self):
    offset = 0
    if self.hdr is not None and self.flags['zf_missing_lines'] and self.base_size['Par']//2 > self.kspace_center_lin + 1:
        offset = self.base_size['Par'] - 2 * self.kspace_center_par
    return offset

The values in the dictionary self.base_size are of type uint16. When performing operations with int32 variables, an overflow can occur.

For example, in the method par_offset, I encountered the following case when reconstructing an mprage data:

  • self.base_size['Par'] was 255.
  • self.kspace_center_par was 128.

The subtraction result should be -1; however, due to self.base_size['Par'] being uint16, the result is interpreted as 65535 (=2^16 - 1). Consequently, I observed the following runtime warning:

twixtools/map_twix.py:377: RuntimeWarning: overflow encountered in scalar subtract
  offset = self.base_size['Par'] - 2 * self.kspace_center_par

Proposed Solution

To avoid such overflows, I suggest changing the type of self.base_size values from uint16 to int16. This modification ensures that subtraction results are correctly interpreted as negative when applicable.

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.

1 participant