Пример #1
0
        if isinstance(axis, int):
            axis = (axis, )
        for ax in axis:
            paddings[ax] = [0, 1] if reverse else [1, 0]
        result = np.pad(result,
                        paddings,
                        mode='constant',
                        constant_values=initial_value)
        slices = [slice(None)] * result.ndim
        for ax in axis:
            slices[ax] = slice(1, None) if reverse else slice(None, -1)
        result = result[tuple(slices)]
    return result


_cumprod = utils.partial(_cumop, np.cumprod, initial_value=1.)
_cumsum = utils.partial(_cumop, np.cumsum, initial_value=0.)


def _equal(x, y, name=None):
    del name
    x = _convert_to_tensor(x)
    y = _convert_to_tensor(y)
    return np.equal(x, y)


def _invert_permutation(x, name=None):
    del name
    x = _convert_to_tensor(x, dtype_hint=np.int32)
    return np.argsort(x).astype(x.dtype)
Пример #2
0
    result = _reverse(result, axis)
  if exclusive:
    paddings = [[0, 0]] * result.ndim
    if isinstance(axis, int):
      axis = (axis,)
    for ax in axis:
      paddings[ax] = [0, 1] if reverse else [1, 0]
    result = np.pad(result, paddings, mode='constant',
                    constant_values=initial_value)
    slices = [slice(None)] * result.ndim
    for ax in axis:
      slices[ax] = slice(1, None) if reverse else slice(None, -1)
    result = result[tuple(slices)]
  return result

_cumprod = utils.partial(_cumop, np.cumprod, initial_value=1.)
_cumsum = utils.partial(_cumop, np.cumsum, initial_value=0.)


def _equal(x, y, name=None):
  del name
  x = _convert_to_tensor(x)
  y = _convert_to_tensor(y)
  return np.equal(x, y)


def _invert_permutation(x, name=None):
  del name
  x = _convert_to_tensor(x, dtype_hint=np.int32)
  return np.argsort(x).astype(x.dtype)