r"""Calculates the product of tensor elements over a given axis (or axes). Args: inp: input tensor. Should have a numeric data type. axis: axis or axes along which products must be computed. By default, the product must be computed over the entire tensor.
(
inp: Tensor, axis: Optional[Union[int, Sequence[int]]] = None, keepdims=False
)
| 209 | |
| 210 | |
| 211 | def prod( |
| 212 | inp: Tensor, axis: Optional[Union[int, Sequence[int]]] = None, keepdims=False |
| 213 | ) -> Tensor: |
| 214 | r"""Calculates the product of tensor elements over a given axis (or axes). |
| 215 | |
| 216 | Args: |
| 217 | inp: input tensor. Should have a numeric data type. |
| 218 | axis: axis or axes along which products must be computed. |
| 219 | By default, the product must be computed over the entire tensor. |
| 220 | If a sequence of integers, products must be computed over multiple axes. |
| 221 | keepdims: if ``True``, the reduced axes (dimensions) must be included in the result as singleton dimensions, |
| 222 | and, accordingly, the result must be compatible with the input tensor (see :ref:`broadcasting-rule`). |
| 223 | Otherwise, if ``False``, the reduced axes (dimensions) must not be included in the result. |
| 224 | |
| 225 | Returns: |
| 226 | if the product was computed over the entire tensor, a zero-dimensional tensor containing the products; |
| 227 | otherwise, a non-zero-dimensional tensor containing the products. |
| 228 | The returned tensor must have a data type determined by :ref:`dtype-promotion`. |
| 229 | |
| 230 | .. admonition:: Special Cases |
| 231 | |
| 232 | Let ``N`` equal the number of elements over which to compute the product. |
| 233 | |
| 234 | * If ``N`` is 0, the product is ``1`` (i.e., the empty product). |
| 235 | * If :math:`x_i` is ``NaN``, the product is ``NaN`` (i.e., ``NaN`` values propagate). |
| 236 | |
| 237 | .. warning:: |
| 238 | |
| 239 | Arithmetic is modular when using integer types, and no error is raised on overflow: |
| 240 | |
| 241 | >>> x = Tensor([536870910, 536870910, 536870910, 536870910]) |
| 242 | >>> F.prod(x) |
| 243 | Tensor(16, dtype=int32, device=xpux:0) |
| 244 | |
| 245 | Examples: |
| 246 | |
| 247 | The product of an empty tensor is the neutral element 1: |
| 248 | |
| 249 | >>> F.prod(Tensor([])) |
| 250 | Tensor(1.0, device=xpux:0) |
| 251 | |
| 252 | Normal case: |
| 253 | |
| 254 | >>> F.prod(Tensor([1, 2, 3])) |
| 255 | Tensor(6, dtype=int32, device=xpux:0) |
| 256 | >>> F.prod(Tensor([0.5, 1.5])) |
| 257 | Tensor(0.75, device=xpux:0) |
| 258 | |
| 259 | Along an axis: |
| 260 | |
| 261 | >>> F.prod(Tensor([[1, 2, 3], [4, 5, 6]]), axis=0) |
| 262 | Tensor([ 4 10 18], dtype=int32, device=xpux:0) |
| 263 | >>> F.prod(Tensor([[1, 2, 3], [4, 5, 6]]), axis=1) |
| 264 | Tensor([ 6 120], dtype=int32, device=xpux:0) |
| 265 | |
| 266 | """ |
| 267 | return inp.prod(axis=axis, keepdims=keepdims) |
| 268 |
no test coverage detected