def binary_search_1d(x, bins_1d, left_idx=0, right_idx=-1):
    """
    1-dimensional binary search

    Input: 
        x (double): value to be searched
        bins_1d:    numpy array or tuple representing the bins
    Output:
        Index of x in the partition defined by the bins. Returns -1 if x is not in the partition.
    """
    if(right_idx == -1):
        right_idx = len(bins_1d) - 1
    if(right_idx > left_idx):
        mid = left_idx + (right_idx-left_idx) // 2
        if(bins_1d[mid] <= x and bins_1d[mid+1]>x):
            return mid 
        if (x >= bins_1d[mid+1]):
            return binary_search_1d(x, bins_1d, mid+1, right_idx)
        if (x < bins_1d[mid]):
            return binary_search_1d(x, bins_1d, left_idx, mid)
    return -1