Skip to content

Rewrite homogenous repeat vector #1620

@ricardoV94

Description

@ricardoV94

Description

If the number of repetitions in pt.repeat is homogeneous, we could replace it by repeat(x, unique_value). Under the hood this ends up as an alloc, skipping the non-C Op altogether

import numpy as np

x = np.arange(600)
r1 = np.array(2, dtype=int)
r2 = np.array([2] * 600, dtype=int)
np.testing.assert_allclose(np.repeat(x, r1), np.repeat(x, r2))
%timeit np.repeat(x, r1)  # 1.32 μs ± 3.21 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
%timeit np.repeat(x, r2)  # 1.85 μs ± 3.69 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)

Not a high priority issue

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions