Skip to content

Conversation

@guptaaditya746
Copy link

Title:

Fix: Correct TypeError in EvoUtils.(Line 351) py for random.randint


Description:

This pull request resolves a TypeError that occurs when calling random.randint with a numpy.float64 argument.

The Problem

In the file EvoUtils.py, the window size is calculated using np.floor(), which returns a numpy.float64 type. This float value is then passed directly to random.randint().

Modern versions of NumPy and Python's random library enforce strict type checking, and random.randint() requires integer arguments. This mismatch causes a TypeError, crashing the execution.

  • Before:
    window = random.randint(1, np.floor(0.5 * np.array(ind1).shape[-1]))

The Solution

The fix is to explicitly cast the result of the np.floor() operation to an integer using int() before passing it to random.randint. This ensures the function receives arguments of the correct type.

  • After:
    window = random.randint(1, int(np.floor(0.5 * np.array(ind1).shape[-1])))

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