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

MAINT: Upcast to int_ instead of int64 to avoid bincount issue. #383

Merged
merged 1 commit into from
Oct 31, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions chaco/tests/test_image_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ def calculate_rms(image_result, expected_image):
"""
# calculate the per-pixel errors, then compute the root mean square error
num_values = np.prod(expected_image.shape)
# Cast to int64 to reduce likelihood of over-/under-flow.
abs_diff_image = abs(np.int64(expected_image) - np.int64(image_result))
# Images may be e.g. 8-bit unsigned integer; upcast to default integer size
# (32 or 64 bit) to reduce likelihood of over-/under-flow.
abs_diff_image = abs(np.int_(expected_image) - np.int_(image_result))

histogram = np.bincount(abs_diff_image.ravel(), minlength=256)
sum_of_squares = np.sum(histogram * np.arange(len(histogram))**2)
sum_of_squares = np.sum(np.int64(histogram) * np.arange(len(histogram))**2)
rms = np.sqrt(float(sum_of_squares) / num_values)
return rms

Expand Down