# Path: sprocket/util/distance.py
# def melcd(array1, array2):
#     """Calculate mel-cepstrum distortion
# 
#     Calculate mel-cepstrum distortion between the arrays.
#     This function assumes the shapes of arrays are same.
# 
#     Parameters
#     ----------
#     array1, array2 : array, shape (`T`, `dim`) or shape (`dim`)
#         Arrays of original and target.
# 
#     Returns
#     -------
#     mcd : scala, number > 0
#         Scala of mel-cepstrum distortion
# 
#     """
#     if array1.shape != array2.shape:
#         raise ValueError(
#             "The shapes of both arrays are different \
#             : {} / {}".format(array1.shape, array2.shape))
# 
#     if array1.ndim == 2:
#         # array based melcd calculation
#         diff = array1 - array2
#         mcd = 10.0 / np.log(10) \
#             * np.mean(np.sqrt(2.0 * np.sum(diff ** 2, axis=1)))
#     elif array1.ndim == 1:
#         diff = array1 - array2
#         mcd = 10.0 / np.log(10) * np.sqrt(2.0 * np.sum(diff ** 2))
#     else:
#         raise ValueError("Dimension mismatch")
# 
#     return mcd


import numpy as np
from dtw import dtw
from fastdtw import fastdtw
from dtw_c import dtw_c
from sprocket.util import melcd


def estimate_twf(orgdata, tardata, distance='melcd', fast=True, otflag=None):
    """time warping function estimator

    Parameters
    ---------
    orgdata : array, shape(`T_org`, `dim`)
        Array of source feature
    tardata : array, shape(`T_tar`, `dim`)
        Array of target feature
    distance : str, optional
        distance function
        `melcd` : mel-cepstrum distortion
    fast : bool, optional
        Use fastdtw instead of dtw
        Default set to `True`
    otflag : str,
        Perform alignment into either original or target length
        `org` : align into original length
        `tar` : align into target length
        Default set to None

    Returns
    ---------
    twf : array, shape(`2`, `T`)
        Time warping function between original and target
    """

    if distance == 'melcd':

# Path: sprocket/util/distance.py
# def melcd(array1, array2):
#     """Calculate mel-cepstrum distortion
# 
#     Calculate mel-cepstrum distortion between the arrays.
#     This function assumes the shapes of arrays are same.
# 
#     Parameters
#     ----------
#     array1, array2 : array, shape (`T`, `dim`) or shape (`dim`)
#         Arrays of original and target.
# 
#     Returns
#     -------
#     mcd : scala, number > 0
#         Scala of mel-cepstrum distortion
# 
#     """
#     if array1.shape != array2.shape:
#         raise ValueError(
#             "The shapes of both arrays are different \
#             : {} / {}".format(array1.shape, array2.shape))
# 
#     if array1.ndim == 2:
#         # array based melcd calculation
#         diff = array1 - array2
#         mcd = 10.0 / np.log(10) \
#             * np.mean(np.sqrt(2.0 * np.sum(diff ** 2, axis=1)))
#     elif array1.ndim == 1:
#         diff = array1 - array2
#         mcd = 10.0 / np.log(10) * np.sqrt(2.0 * np.sum(diff ** 2))
#     else:
#         raise ValueError("Dimension mismatch")
# 
#     return mcd


# Path: sprocket/util/twf.py
import numpy as np
from dtw import dtw
from fastdtw import fastdtw
from dtw_c import dtw_c
from sprocket.util import melcd



def estimate_twf(orgdata, tardata, distance='melcd', fast=True, otflag=None):
    """time warping function estimator

    Parameters
    ---------
    orgdata : array, shape(`T_org`, `dim`)
        Array of source feature
    tardata : array, shape(`T_tar`, `dim`)
        Array of target feature
    distance : str, optional
        distance function
        `melcd` : mel-cepstrum distortion
    fast : bool, optional
        Use fastdtw instead of dtw
        Default set to `True`
    otflag : str,
        Perform alignment into either original or target length
        `org` : align into original length
        `tar` : align into target length
        Default set to None

    Returns
    ---------
    twf : array, shape(`2`, `T`)
        Time warping function between original and target
    """

    if distance == 'melcd':

        def distance_func(x, y): return melcd(x, y)