def dtw(X=None, Y=None, C=None, metric='<STR_LIT>', step_sizes_sigma=None,<EOL>weights_add=None, weights_mul=None, subseq=False, backtrack=True,<EOL>global_constraints=False, band_rad=<NUM_LIT>):
<EOL>if step_sizes_sigma is None:<EOL><INDENT>step_sizes_sigma = np.array([[<NUM_LIT:1>, <NUM_LIT:1>], [<NUM_LIT:0>, <NUM_LIT:1>], [<NUM_LIT:1>, <NUM_LIT:0>]])<EOL><DEDENT>if weights_add is None:<EOL><INDENT>weights_add = np.zeros(len(step_sizes_sigma))<EOL><DEDENT>if weights_mul is None:<EOL><INDENT>weights_mul = np.ones(len(step_sizes_sigma))<EOL><DEDENT>if len(step_sizes_sigma) != len(weights_add):<EOL><INDENT>raise ParameterError('<STR_LIT>')<EOL><DEDENT>if len(step_sizes_sigma) != len(weights_mul):<EOL><INDENT>raise ParameterError('<STR_LIT>')<EOL><DEDENT>if C is None and (X is None or Y is None):<EOL><INDENT>raise ParameterError('<STR_LIT>')<EOL><DEDENT>if C is not None and (X is not None or Y is not None):<EOL><INDENT>raise ParameterError('<STR_LIT>')<EOL><DEDENT>if C is None:<EOL><INDENT>X = np.atleast_2d(X)<EOL>Y = np.atleast_2d(Y)<EOL>try:<EOL><INDENT>C = cdist(X.T, Y.T, metric=metric)<EOL><DEDENT>except ValueError:<EOL><INDENT>msg = ('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL>six.reraise(ParameterError, ParameterError(msg))<EOL><DEDENT>if subseq and (X.shape[<NUM_LIT:1>] > Y.shape[<NUM_LIT:1>]):<EOL><INDENT>C = C.T<EOL><DEDENT><DEDENT>C = np.atleast_2d(C)<EOL>if np.array_equal(step_sizes_sigma, np.array([[<NUM_LIT:1>, <NUM_LIT:1>]])) and (C.shape[<NUM_LIT:0>] > C.shape[<NUM_LIT:1>]):<EOL><INDENT>raise ParameterError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>max_0 = step_sizes_sigma[:, <NUM_LIT:0>].max()<EOL>max_1 = step_sizes_sigma[:, <NUM_LIT:1>].max()<EOL>if global_constraints:<EOL><INDENT>fill_off_diagonal(C, band_rad, value=np.inf)<EOL><DEDENT>D = np.ones(C.shape + np.array([max_0, max_1])) * np.inf<EOL>D[max_0, max_1] = C[<NUM_LIT:0>, <NUM_LIT:0>]<EOL>if subseq:<EOL><INDENT>D[max_0, max_1:] = C[<NUM_LIT:0>, :]<EOL><DEDENT>D_steps = -<NUM_LIT:1> * np.ones(D.shape, dtype=np.int)<EOL>D, D_steps = __dtw_calc_accu_cost(C, D, D_steps,<EOL>step_sizes_sigma,<EOL>weights_mul, weights_add,<EOL>max_0, max_1)<EOL>D = D[max_0:, max_1:]<EOL>D_steps = D_steps[max_0:, max_1:]<EOL>if backtrack:<EOL><INDENT>if subseq:<EOL><INDENT>wp_end_idx = np.argmin(D[-<NUM_LIT:1>, :]) + <NUM_LIT:1><EOL>wp = __dtw_backtracking(D_steps[:, :wp_end_idx], step_sizes_sigma)<EOL><DEDENT>else:<EOL><INDENT>wp = __dtw_backtracking(D_steps, step_sizes_sigma)<EOL><DEDENT>wp = np.asarray(wp, dtype=int)<EOL>if subseq and (X.shape[<NUM_LIT:1>] > Y.shape[<NUM_LIT:1>]):<EOL><INDENT>wp = np.fliplr(wp)<EOL><DEDENT>return D, wp<EOL><DEDENT>else:<EOL><INDENT>return D<EOL><DEDENT>
Dynamic time warping (DTW).

    This function performs a DTW and path backtracking on two sequences.
    We follow the nomenclature and algorithmic approach as described in [1]_.

    .. [1] Meinard Mueller
           Fundamentals of Music Processing — Audio, Analysis, Algorithms, Applications
           Springer Verlag, ISBN: 978-3-319-21944-8, 2015.

    Parameters
    ----------
    X : np.ndarray [shape=(K, N)]
        audio feature matrix (e.g., chroma features)

    Y : np.ndarray [shape=(K, M)]
        audio feature matrix (e.g., chroma features)

    C : np.ndarray [shape=(N, M)]
        Precomputed distance matrix. If supplied, X and Y must not be supplied and
        ``metric`` will be ignored.

    metric : str
        Identifier for the cost-function as documented
        in `scipy.spatial.cdist()`

    step_sizes_sigma : np.ndarray [shape=[n, 2]]
        Specifies allowed step sizes as used by the dtw.

    weights_add : np.ndarray [shape=[n, ]]
        Additive weights to penalize certain step sizes.

    weights_mul : np.ndarray [shape=[n, ]]
        Multiplicative weights to penalize certain step sizes.

    subseq : binary
        Enable subsequence DTW, e.g., for retrieval tasks.

    backtrack : binary
        Enable backtracking in accumulated cost matrix.

    global_constraints : binary
        Applies global constraints to the cost matrix ``C`` (Sakoe-Chiba band).

    band_rad : float
        The Sakoe-Chiba band radius (1/2 of the width) will be
        ``int(radius*min(C.shape))``.

    Returns
    -------
    D : np.ndarray [shape=(N,M)]
        accumulated cost matrix.
        D[N,M] is the total alignment cost.
        When doing subsequence DTW, D[N,:] indicates a matching function.

    wp : np.ndarray [shape=(N,2)]
        Warping path with index pairs.
        Each row of the array contains an index pair n,m).
        Only returned when ``backtrack`` is True.

    Raises
    ------
    ParameterError
        If you are doing diagonal matching and Y is shorter than X or if an incompatible
        combination of X, Y, and C are supplied.
        If your input dimensions are incompatible.

    Examples
    --------
    >>> import numpy as np
    >>> import matplotlib.pyplot as plt
    >>> y, sr = librosa.load(librosa.util.example_audio_file(), offset=10, duration=15)
    >>> X = librosa.feature.chroma_cens(y=y, sr=sr)
    >>> noise = np.random.rand(X.shape[0], 200)
    >>> Y = np.concatenate((noise, noise, X, noise), axis=1)
    >>> D, wp = librosa.sequence.dtw(X, Y, subseq=True)
    >>> plt.subplot(2, 1, 1)
    >>> librosa.display.specshow(D, x_axis='frames', y_axis='frames')
    >>> plt.title('Database excerpt')
    >>> plt.plot(wp[:, 1], wp[:, 0], label='Optimal path', color='y')
    >>> plt.legend()
    >>> plt.subplot(2, 1, 2)
    >>> plt.plot(D[-1, :] / wp.shape[0])
    >>> plt.xlim([0, Y.shape[1]])
    >>> plt.ylim([0, 2])
    >>> plt.title('Matching cost function')
    >>> plt.tight_layout()