def generate_bins_generic(values, binner, closed):
lenidx = len(values)<EOL>lenbin = len(binner)<EOL>if lenidx <= <NUM_LIT:0> or lenbin <= <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if values[<NUM_LIT:0>] < binner[<NUM_LIT:0>]:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if values[lenidx - <NUM_LIT:1>] > binner[lenbin - <NUM_LIT:1>]:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>bins = np.empty(lenbin - <NUM_LIT:1>, dtype=np.int64)<EOL>j = <NUM_LIT:0>  <EOL>bc = <NUM_LIT:0>  <EOL>for i in range(<NUM_LIT:0>, lenbin - <NUM_LIT:1>):<EOL><INDENT>r_bin = binner[i + <NUM_LIT:1>]<EOL>while j < lenidx and (values[j] < r_bin or<EOL>(closed == '<STR_LIT:right>' and values[j] == r_bin)):<EOL><INDENT>j += <NUM_LIT:1><EOL><DEDENT>bins[bc] = j<EOL>bc += <NUM_LIT:1><EOL><DEDENT>return bins<EOL>
Generate bin edge offsets and bin labels for one array using another array
which has bin edge values. Both arrays must be sorted.

Parameters
----------
values : array of values
binner : a comparable array of values representing bins into which to bin
    the first array. Note, 'values' end-points must fall within 'binner'
    end-points.
closed : which end of bin is closed; left (default), right

Returns
-------
bins : array of offsets (into 'values' argument) of bins.
    Zero and last edge are excluded in result, so for instance the first
    bin is values[0:bin[0]] and the last is values[bin[-1]:]