# Path: sprocket/util/delta.py
# def delta(data, win=[-1.0, 1.0, 0]):
#     """Calculate delta component
# 
#     Parameters
#     ----------
#     data : array, shape (`T`, `dim`)
#         Array of static matrix sequence.
#     win: array, optional, shape (`3`)
#         The shape of window matrix.
#         Default set to [-1.0, 1.0, 0].
# 
#     Returns
#     -------
#     delta : array, shape (`T`, `dim`)
#         Array delta matrix sequence.
# 
#     """
# 
#     if data.ndim == 1:
#         # change vector into 1d-array
#         T = len(data)
#         dim = data.ndim
#         data = data.reshape(T, dim)
#     else:
#         T, dim = data.shape
# 
#     win = np.array(win, dtype=np.float64)
#     delta = np.zeros((T, dim))
# 
#     delta[0] = win[0] * data[0] + win[1] * data[1]
#     delta[-1] = win[0] * data[-2] + win[1] * data[-1]
# 
#     for i in range(len(win)):
#         delta[1:T - 1] += win[i] * data[i:T - 2 + i]
# 
#     return delta
# 
# def construct_static_and_delta_matrix(T, D, win=[-1.0, 1.0, 0]):
#     """Calculate static and delta transformation matrix
# 
#     Parameters
#     ----------
#     T : scala, `T`
#         Scala of time length
#     D : scala, `D`
#         Scala of the number of dimentsion
#     win: array, optional, shape (`3`)
#         The shape of window matrix for delta.
#         Default set to [-1.0, 1.0, 0].
# 
#     Returns
#     -------
#     W : array, shape (`2 * D * T`, `D * T`)
#         Array of static and delta transformation matrix.
# 
#     """
# 
#     static = [0, 1, 0]
#     delta = win
#     assert len(static) == len(delta)
# 
#     # generate full W
#     DT = D * T
#     ones = np.ones(DT)
#     row = np.arange(2 * DT).reshape(2 * T, D)
#     static_row = row[::2]
#     delta_row = row[1::2]
#     col = np.arange(DT)
# 
#     data = np.array([ones * static[0], ones * static[1],
#                      ones * static[2], ones * delta[0],
#                      ones * delta[1], ones * delta[2]]).flatten()
#     row = np.array([[static_row] * 3,  [delta_row] * 3]).flatten()
#     col = np.array([[col - D, col, col + D] * 2]).flatten()
# 
#     # remove component at first and end frame
#     valid_idx = np.logical_not(np.logical_or(col < 0, col >= DT))
# 
#     W = scipy.sparse.csr_matrix(
#         (data[valid_idx], (row[valid_idx], col[valid_idx])), shape=(2 * DT, DT))
#     W.eliminate_zeros()
# 
#     return W


import unittest
import numpy as np
from sprocket.util.delta import delta, construct_static_and_delta_matrix
from __future__ import division, print_function, absolute_import




class DeltaFunctionsTest(unittest.TestCase):

    def test_delta(self):
        data1d = np.random.rand(100)
        delta1d = delta(data1d)
        assert len(data1d) == len(delta1d)

        data2d = data1d.reshape(50, 2)

# Path: sprocket/util/delta.py
# def delta(data, win=[-1.0, 1.0, 0]):
#     """Calculate delta component
# 
#     Parameters
#     ----------
#     data : array, shape (`T`, `dim`)
#         Array of static matrix sequence.
#     win: array, optional, shape (`3`)
#         The shape of window matrix.
#         Default set to [-1.0, 1.0, 0].
# 
#     Returns
#     -------
#     delta : array, shape (`T`, `dim`)
#         Array delta matrix sequence.
# 
#     """
# 
#     if data.ndim == 1:
#         # change vector into 1d-array
#         T = len(data)
#         dim = data.ndim
#         data = data.reshape(T, dim)
#     else:
#         T, dim = data.shape
# 
#     win = np.array(win, dtype=np.float64)
#     delta = np.zeros((T, dim))
# 
#     delta[0] = win[0] * data[0] + win[1] * data[1]
#     delta[-1] = win[0] * data[-2] + win[1] * data[-1]
# 
#     for i in range(len(win)):
#         delta[1:T - 1] += win[i] * data[i:T - 2 + i]
# 
#     return delta
# 
# def construct_static_and_delta_matrix(T, D, win=[-1.0, 1.0, 0]):
#     """Calculate static and delta transformation matrix
# 
#     Parameters
#     ----------
#     T : scala, `T`
#         Scala of time length
#     D : scala, `D`
#         Scala of the number of dimentsion
#     win: array, optional, shape (`3`)
#         The shape of window matrix for delta.
#         Default set to [-1.0, 1.0, 0].
# 
#     Returns
#     -------
#     W : array, shape (`2 * D * T`, `D * T`)
#         Array of static and delta transformation matrix.
# 
#     """
# 
#     static = [0, 1, 0]
#     delta = win
#     assert len(static) == len(delta)
# 
#     # generate full W
#     DT = D * T
#     ones = np.ones(DT)
#     row = np.arange(2 * DT).reshape(2 * T, D)
#     static_row = row[::2]
#     delta_row = row[1::2]
#     col = np.arange(DT)
# 
#     data = np.array([ones * static[0], ones * static[1],
#                      ones * static[2], ones * delta[0],
#                      ones * delta[1], ones * delta[2]]).flatten()
#     row = np.array([[static_row] * 3,  [delta_row] * 3]).flatten()
#     col = np.array([[col - D, col, col + D] * 2]).flatten()
# 
#     # remove component at first and end frame
#     valid_idx = np.logical_not(np.logical_or(col < 0, col >= DT))
# 
#     W = scipy.sparse.csr_matrix(
#         (data[valid_idx], (row[valid_idx], col[valid_idx])), shape=(2 * DT, DT))
#     W.eliminate_zeros()
# 
#     return W


# Path: sprocket/util/tests/test_delta.py
import unittest
import numpy as np
from sprocket.util.delta import delta, construct_static_and_delta_matrix

from __future__ import division, print_function, absolute_import




class DeltaFunctionsTest(unittest.TestCase):

    def test_delta(self):
        data1d = np.random.rand(100)
        delta1d = delta(data1d)
        assert len(data1d) == len(delta1d)

        data2d = data1d.reshape(50, 2)

        delta2d = delta(data2d)