Add an reduction operation to do along a dimension. It is implemented using the IReduceLayer from TensorRT. Parameters: input : Tensor The input tensor. op : trt.ReduceOperation The reduction operation to perform. Options: SUM, PROD
(input: Tensor,
op: trt.ReduceOperation,
dim: Union[int, Tuple[int]],
keepdim: bool = False)
| 3158 | |
| 3159 | |
| 3160 | def reduce(input: Tensor, |
| 3161 | op: trt.ReduceOperation, |
| 3162 | dim: Union[int, Tuple[int]], |
| 3163 | keepdim: bool = False) -> Tensor: |
| 3164 | ''' |
| 3165 | Add an reduction operation to do along a dimension. |
| 3166 | |
| 3167 | It is implemented using the IReduceLayer from TensorRT. |
| 3168 | |
| 3169 | Parameters: |
| 3170 | input : Tensor |
| 3171 | The input tensor. |
| 3172 | |
| 3173 | op : trt.ReduceOperation |
| 3174 | The reduction operation to perform. |
| 3175 | Options: SUM, PROD, MAX, MIN, AVG |
| 3176 | |
| 3177 | dim : int |
| 3178 | The dimension along which the reduction is performed. |
| 3179 | |
| 3180 | keepdim : bool |
| 3181 | Is the dimension kept in the reduced tensor? When True the |
| 3182 | dimension is kept, it is removed from the shape otherwise. |
| 3183 | |
| 3184 | Returns: |
| 3185 | The tensor produced by this reduction operation. |
| 3186 | ''' |
| 3187 | dim = dim_resolve_negative(dim, input.ndim()) |
| 3188 | axes = dim_to_trt_axes(dim) |
| 3189 | |
| 3190 | layer = default_trtnet().add_reduce(input.trt_tensor, |
| 3191 | op, |
| 3192 | axes, |
| 3193 | keep_dims=keepdim) |
| 3194 | return _create_tensor(layer.get_output(0), layer) |
| 3195 | |
| 3196 | |
| 3197 | prod = partial(reduce, op=trt.ReduceOperation.PROD) |
no test coverage detected