Description
Describe the bug
The normalize function does not properly constrain values to the [0, 1] range. If data contains values outside the provided or calculated min/max bounds, the resulting normalized values can fall below 0 or exceed 1. This can lead to downstream errors in functions that expect strictly normalized input.
To Reproduce
Steps to reproduce the behavior:
- Call normalize() with a scalar or array that falls outside the [min_val, max_val] range.
- Observe that the output is not bounded between 0 and 1.
Example:
normalize(20, min_val=0, max_val=10) # Returns: 2.0
Expected behavior
The function should always return values clipped to the [0, 1] range. Any values below 0 should be set to 0, and any values above 1 should be set to 1.
Screenshots
N/A
Desktop (please complete the following information):
- OS: Linux
- Version: latest commit on main
Additional context
I've implemented a fix that ensures the returned array is clipped using normed[normed < 0] = 0 and normed[normed > 1] = 1, and that scalar values are safely handled using np.array().
I will submit a PR with this fix shortly.