reduce.py 7.08 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
"""Reduce operators."""
# pylint: disable=redefined-builtin

from . import _make

def argmax(data, axis=None, keepdims=False, exclude=False):
    """Returns the indices of the maximum values along an axis.

    Parameters
    ----------
    data : relay.Expr
        The input data

    axis : None or int or tuple of int
15 16
        Axis or axes along which a argmax operation is performed.
        The default, axis=None, will find the indices of the maximum element of the elements of
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
        the input array. If axis is negative it counts from the last to the first axis.

    keepdims : bool
        If this is set to True, the axes which are reduced are left in the result as dimensions
        with size one.
        With this option, the result will broadcast correctly against the input array.

    exclude : bool
        If `exclude` is true, reduction will be performed on the axes that are
      NOT in axis instead.

    Returns
    -------
    result : relay.Expr
        The computed result.
    """
33
    axis = [axis] if isinstance(axis, int) else axis
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
    return _make.argmax(data, axis, keepdims, exclude)

def argmin(data, axis=None, keepdims=False, exclude=False):
    """Returns the indices of the minimum values along an axis.

    Parameters
    ----------
    data : relay.Expr
        The input data

    axis : None or int or tuple of int
        Axis or axes along which a argmin operation is performed.
        The default, axis=None, will find the indices of minimum element all of the elements of
        the input array. If axis is negative it counts from the last to the first axis.

    keepdims : bool
        If this is set to True, the axes which are reduced are left in the result as dimensions
        with size one.
        With this option, the result will broadcast correctly against the input array.

    exclude : bool
        If `exclude` is true, reduction will be performed on the axes that are
      NOT in axis instead.

    Returns
    -------
    result : relay.Expr
        The computed result.
    """
63
    axis = [axis] if isinstance(axis, int) else axis
64
    return _make.argmin(data, axis, keepdims, exclude)
65 66 67 68 69 70 71 72 73 74 75


def sum(data, axis=None, keepdims=False, exclude=False):
    """Computes the sum of array elements over given axes.

    Parameters
    ----------
    data : relay.Expr
        The input data

    axis : None or int or tuple of int
76 77 78
        Axis or axes along which a sum is performed. The default, axis=None,
        will sum all of the elements of the input array. If axis is
        negative it counts from the last to the first axis.
79 80

    keepdims : bool
81 82 83
        If this is set to True, the axes which are reduced are left in the result as
        dimensions with size one. With this option, the result will broadcast
        correctly against the input array.
84 85 86 87 88 89 90 91 92 93

    exclude : bool
        If `exclude` is true, reduction will be performed on the axes that are
      NOT in axis instead.

    Returns
    -------
    result : relay.Expr
        The computed result.
    """
94
    axis = [axis] if axis and isinstance(axis, int) else axis
95 96 97 98 99 100 101 102 103 104 105 106
    return _make.sum(data, axis, keepdims, exclude)


def max(data, axis=None, keepdims=False, exclude=False):
    """ Computes the max of array elements over given axes.

    Parameters
    ----------
    data : relay.Expr
        The input data

    axis : None or int or tuple of int
107 108 109
        Axis or axes along which the max operation is performed.
        The default, axis=None, will find the max element from all of the elements of the input
        array. If axis is negative it counts from the last to the first axis.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124

    keepdims : bool
        If this is set to True, the axes which are reduced are left in the result as dimensions
        with size one.
        With this option, the result will broadcast correctly against the input array.

    exclude : bool
        If `exclude` is true, reduction will be performed on the axes that are
      NOT in axis instead.

    Returns
    -------
    result : relay.Expr
        The computed result.
    """
125
    axis = [axis] if isinstance(axis, int) else axis
126 127 128 129 130 131 132 133 134 135 136 137
    return _make.max(data, axis, keepdims, exclude)


def min(data, axis=None, keepdims=False, exclude=False):
    """Computes the min of array elements over given axes.

    Parameters
    ----------
    data : relay.Expr
        The input data

    axis : None or int or tuple of int
138 139 140 141
        Axis or axes along which a minimum operation is performed.
        The default, axis=None, will find the minimum element from all
        of the elements of the input array. If axis is negative it counts from
        the last to the first axis.
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156

    keepdims : bool
        If this is set to True, the axes which are reduced are left in the result as dimensions
        with size one.
        With this option, the result will broadcast correctly against the input array.

    exclude : bool
        If `exclude` is true, reduction will be performed on the axes that are
      NOT in axis instead.

    Returns
    -------
    result : relay.Expr
        The computed result.
    """
157
    axis = [axis] if isinstance(axis, int) else axis
158 159 160 161 162 163 164 165 166 167 168 169
    return _make.min(data, axis, keepdims, exclude)


def mean(data, axis=None, keepdims=False, exclude=False):
    """Computes the mean of array elements over given axes.

    Parameters
    ----------
    data : relay.Expr
        The input data

    axis : None or int or tuple of int
170
        Axis or axes along which a mean operation is performed.
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
        The default, axis=None, will find the indices of minimum element all of the elements of
        the input array. If axis is negative it counts from the last to the first axis.

    keepdims : bool
        If this is set to True, the axes which are reduced are left in the result as dimensions
        with size one.
        With this option, the result will broadcast correctly against the input array.

    exclude : bool
        If `exclude` is true, reduction will be performed on the axes that are
      NOT in axis instead.

    Returns
    -------
    result : relay.Expr
        The computed result.
    """
188
    axis = [axis] if isinstance(axis, int) else axis
189 190 191 192 193 194 195 196 197 198 199 200
    return _make.mean(data, axis, keepdims, exclude)


def prod(data, axis=None, keepdims=False, exclude=False):
    """Computes the products of array elements over given axes.

    Parameters
    ----------
    data : relay.Expr
        The input data

    axis : None or int or tuple of int
201
        Axis or axes along which a product is performed.
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
        The default, axis=None, will find the indices of minimum element all of the elements of
        the input array. If axis is negative it counts from the last to the first axis.

    keepdims : bool
        If this is set to True, the axes which are reduced are left in the result as dimensions
        with size one.
        With this option, the result will broadcast correctly against the input array.

    exclude : bool
        If `exclude` is true, reduction will be performed on the axes that are
      NOT in axis instead.

    Returns
    -------
    result : relay.Expr
        The computed result.
    """
219
    axis = [axis] if isinstance(axis, int) else axis
220
    return _make.prod(data, axis, keepdims, exclude)