Skip to content

Consider Replacing np.round() with np.rint() for Simpler and Faster Integer Rounding #6

@SaFE-APIOpt

Description

@SaFE-APIOpt

n_train = int(numpy.round(n_samples * (1. - valid_portion)))

In this line:
n_train = int(np.round(n_samples * (1. - valid_portion)))
Since the rounding here is simply to get the nearest integer (not rounding to specific decimal places), you might consider using:
n_train = int(np.rint(n_samples * (1. - valid_portion)))
np.rint() is a lightweight function that directly wraps the C standard library's rint() function. It performs the same rounding behavior (round half to even), but is more efficient and has less overhead compared to np.round(), which is a higher-level wrapper designed to support decimals.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions