code: def diff(x, lag=1, differences=1):
      """Difference an array.
  
      A python implementation of the R ``diff`` function [1]. This computes lag
      differences from an array given a ``lag`` and ``differencing`` term.
  
      If ``x`` is a vector of length :math:`n`, ``lag=1`` and ``differences=1``,
      then the computed result is equal to the successive differences
      ``x[lag:n] - x[:n-lag]``.
  
      Examples
      --------
      Where ``lag=1`` and ``differences=1``:
  
      >>> x = c(10, 4, 2, 9, 34)
      >>> diff(x, 1, 1)
      array([ -6.,  -2.,   7.,  25.], dtype=float32)
  
      Where ``lag=1`` and ``differences=2``:
  
      >>> x = c(10, 4, 2, 9, 34)
      >>> diff(x, 1, 2)
      array([  4.,   9.,  18.], dtype=float32)
  
      Where ``lag=3`` and ``differences=1``:
  
      >>> x = c(10, 4, 2, 9, 34)
      >>> diff(x, 3, 1)
      array([ -1.,  30.], dtype=float32)
  
      Where ``lag=6`` (larger than the array is) and ``differences=1``:
  
      >>> x = c(10, 4, 2, 9, 34)
      >>> diff(x, 6, 1)
      array([], dtype=float32)
  
      For a 2d array with ``lag=1`` and ``differences=1``:
  
      >>> import numpy as np
      >>>
      >>> x = np.arange(1, 10).reshape((3, 3)).T
      >>> diff(x, 1, 1)
      array([[ 1.,  1.,  1.],
             [ 1.,  1.,  1.]], dtype=float32)
  
      Parameters
      ----------
      x : array-like, shape=(n_samples, [n_features])
          The array to difference.
  
      lag : int, optional (default=1)
          An integer > 0 indicating which lag to use.
  
      differences : int, optional (default=1)
          An integer > 0 indicating the order of the difference.
  
      Returns
      -------
      res : np.ndarray, shape=(n_samples, [n_features])
          The result of the differenced arrays.
  
      References
      ----------
      .. [1] https://stat.ethz.ch/R-manual/R-devel/library/base/html/diff.html
      """
      if any(v < 1 for v in (lag, differences)):
          raise ValueError(
              "lag and differences must be positive (> 0) integers"
          )
  
      x = skval.check_array(x, ensure_2d=False, dtype=DTYPE, copy=False)
      fun = _diff_vector if x.ndim == 1 else _diff_matrix
      res = x
  
      # "recurse" over range of differences
      for i in range(differences):
          res = fun(res, lag)
          # if it ever comes back empty, just return it as is
          if not res.shape[0]:
              return res
  
      return res
  
file_path: pmdarima/pmdarima/utils/array.py
imports: from sklearn.utils import validation
  import numpy
  import pandas
  from ..compat import DTYPE
  from ._array import C_intgrt_vec
label_desc: Use image node_id 7 for calling a global function with example usage: diff(x, lag, differences) and returns: res, res