def hilbert(x, _cache=_cache):
tmp = asarray(x)<EOL>if iscomplexobj(tmp):<EOL><INDENT>return hilbert(tmp.real)+<NUM_LIT>*hilbert(tmp.imag)<EOL><DEDENT>n = len(x)<EOL>omega = _cache.get(n)<EOL>if omega is None:<EOL><INDENT>if len(_cache) > <NUM_LIT:20>:<EOL><INDENT>while _cache:<EOL><INDENT>_cache.popitem()<EOL><DEDENT><DEDENT>def kernel(k):<EOL><INDENT>if k > <NUM_LIT:0>:<EOL><INDENT>return <NUM_LIT:1.0><EOL><DEDENT>elif k < <NUM_LIT:0>:<EOL><INDENT>return -<NUM_LIT:1.0><EOL><DEDENT>return <NUM_LIT:0.0><EOL><DEDENT>omega = convolve.init_convolution_kernel(n,kernel,d=<NUM_LIT:1>)<EOL>_cache[n] = omega<EOL><DEDENT>overwrite_x = _datacopied(tmp, x)<EOL>return convolve.convolve(tmp,omega,swap_real_imag=<NUM_LIT:1>,overwrite_x=overwrite_x)<EOL>
Return Hilbert transform of a periodic sequence x.

If x_j and y_j are Fourier coefficients of periodic functions x
and y, respectively, then::

  y_j = sqrt(-1)*sign(j) * x_j
  y_0 = 0

Parameters
----------
x : array_like
    The input array, should be periodic.
_cache : dict, optional
    Dictionary that contains the kernel used to do a convolution with.

Returns
-------
y : ndarray
    The transformed input.

Notes
-----
If ``sum(x, axis=0) == 0`` then ``hilbert(ihilbert(x)) == x``.

For even len(x), the Nyquist mode of x is taken zero.

The sign of the returned transform does not have a factor -1 that is more
often than not found in the definition of the Hilbert transform.  Note also
that ``scipy.signal.hilbert`` does have an extra -1 factor compared to this
function.