def _dtw_region(x=None, y=None, dist='square', region=None,
                precomputed_cost=None, return_cost=False,
                return_accumulated=False, return_path=False):
    """Dynamic Time Warping (DTW) distance with a constraint region.

    This version of DTW allows users to provide their own constraint region.
    If not provided, no constraint region is used, which is exactly the
    classic DTW.

    Options
    -------
    region : None or array-like, shape = (2, n_timestamps_1) (default = None)
        Constraint region. If None, no constraint region is used. Otherwise,
        the first row consists of the starting indices (included) and the
        second row consists of the ending indices (excluded) of the valid rows
        for each column.

    """
    x, y, precomputed_cost, n_timestamps_1, n_timestamps_2 = \
        _check_input_dtw(x, y, precomputed_cost, dist, method="region")
    cost_mat = _input_to_cost(x, y, dist, precomputed_cost, region=region)
    acc_cost_mat = accumulated_cost_matrix(cost_mat, region)
    dtw_dist = acc_cost_mat[-1, -1]
    if dist == 'square':
        dtw_dist = sqrt(dtw_dist)

    res = _return_results(dtw_dist, cost_mat, acc_cost_mat,
                          return_cost, return_accumulated, return_path)
    return res
Dynamic Time Warping (DTW) distance with a constraint region.

    This version of DTW allows users to provide their own constraint region.
    If not provided, no constraint region is used, which is exactly the
    classic DTW.

    Options
    -------
    region : None or array-like, shape = (2, n_timestamps_1) (default = None)
        Constraint region. If None, no constraint region is used. Otherwise,
        the first row consists of the starting indices (included) and the
        second row consists of the ending indices (excluded) of the valid rows
        for each column.

    
pyts/metrics/dtw.py