<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def histogram1d(x, bins, range, weights=None):
 """ Compute a 1D histogram assuming equally spaced bins. Parameters x : `~numpy.ndarray` The position of the points to bin in the 1D histogram bins : int The number of bins range : iterable The range as a tuple of (xmin, xmax) weights : `~numpy.ndarray` The weights of the points in the 1D histogram Returns ------- array : `~numpy.ndarray` The 1D histogram array """


    nx = bins

    if not np.isscalar(bins):
        raise TypeError('bins should be an integer')

    xmin, xmax = range

    if not np.isfinite(xmin):
        raise ValueError("xmin should be finite")

    if not np.isfinite(xmax):
        raise ValueError("xmax should be finite")

    if xmax <= xmin:
        raise ValueError("xmax should be greater than xmin")

    if nx <= 0:
        raise ValueError("nx should be strictly positive")

    if weights is None:
        return _histogram1d(x, nx, xmin, xmax)
    else:
        return _histogram1d_weighted(x, weights, nx, xmin, xmax)