When I added unpack_buffer_archive, in code review people said
it was redundant with unpack_buffer and they should be merged.
I said merging was too annoying. They were right. This merges
the functions together into a function with a 38 line docstring
and a 18 line implementation.
Merge together unpack_buffer and unpack_buffer_archive. When I added unpack_buffer_archive, in code review people said
it was redundant with unpack_buffer and they should be merged.
I said merging was too annoying. They were right. This merges
the functions together into a function with a 38 line docstring
and a 18 line implementation.
# http://stackoverflow.com/questions/14553331/how-to-improve-numpy-performance-in-this-short-code
# pythran export repeating(float[], int)
# setup: import numpy as np ; a = np.random.rand(10000)
# run: repeating(a, 20)

import numpy as np


def repeating(x, nvar_y):
    nvar_x = x.shape[0]
    y = np.empty(nvar_x * (1 + nvar_y))
    y[0:nvar_x] = x[0:nvar_x]
    y[nvar_x:] = np.repeat(x, nvar_y)
    return y

# http://stackoverflow.com/questions/14553331/how-to-improve-numpy-performance-in-this-short-code
# pythran export repeating(float[], int)
# setup: import numpy as np ; a = np.random.rand(10000)
# run: repeating(a, 20)

import numpy as np


def repeating(x, nvar_y):
    nvar_x = x.shape[0]
    y = np.empty(nvar_x * (1 + nvar_y))
    y[0:nvar_x] = x[0:nvar_x]
    y[nvar_x:] = np.repeat(x, nvar_y)
    return y
