code: static double computeDynamicTimeWarpingDistance(
      	DoubleTuple u, DoubleTuple v)
      {
          int m = u.getSize();
          int n = v.getSize();
          double matrix[][] = threadLocalMatrix.get();
          if (matrix.length < m || matrix[0].length < n)
          {
          	matrix = new double[m][n];
          	threadLocalMatrix.set(matrix);
          }
          double u0 = u.get(0);
          double v0 = v.get(0);
          matrix[0][0] = Math.abs(u0-v0);
          for (int j=1; j<n; j++)
          {
              matrix[0][j] = Math.abs(u0-v.get(j)) + matrix[0][j-1];
          }
          for (int i=1; i<m; i++)
          {
             matrix[i][0] = Math.abs(u.get(i)-v0) + matrix[i-1][0];
          }
          for (int i = 1; i < m; i++)
          {
              double ui = u.get(i);
              for (int j = 1; j < n; j++)
              {
                  double vj = v.get(j);
                  double min = matrix[i - 1][j - 1];
                  min = min(min, matrix[i][j - 1]);
                  min = min(min, matrix[i - 1][j]);
                  double d = ui - vj;
                  matrix[i][j] = min + (d < 0 ? -d : d);
              }
          }
          return matrix[m-1][n-1];
      }
docs: Performs the computation of the dynamic time warping distance
  between the given {@link DoubleTuple}s
  
  @param u The first {@link DoubleTuple}
  @param v The second {@link DoubleTuple}
  @return The dynamic time warping distance