| // |
| // This confidential and proprietary software may be used only as |
| // authorised by a licensing agreement from ARM Limited |
| // (C) COPYRIGHT 2020-2023 ARM Limited |
| // ALL RIGHTS RESERVED |
| // The entire notice above must be reproduced on all authorised |
| // copies and copies may only be made to the extent permitted |
| // by a licensing agreement from ARM Limited. |
| |
| === Reduction Operators |
| |
| ==== REDUCE_ALL |
| |
| Reduce a tensor along the given axis with a logical AND operation |
| |
| include::{generated}/operators/REDUCE_ALL.adoc[] |
| |
| [source,c] |
| ---- |
| ERROR_IF(axis < 0 || axis >= rank(shape1)); |
| ERROR_IF(shape[axis] != 1); |
| |
| // Initialize output state to true |
| for_each(index in shape) { |
| tensor_write<in_out_t>(output, shape, index, true); |
| } |
| for_each(index in shape1) { |
| dim_t out_index = index; |
| out_index[axis] = 0; |
| in_out_t value = tensor_read<in_out_t>(input, shape1, index); |
| in_out_t state = tensor_read<in_out_t>(output, shape, out_index); |
| state = state && value; |
| tensor_write<in_out_t>(output, shape, out_index, state); |
| } |
| ---- |
| |
| ==== REDUCE_ANY |
| |
| Reduce a tensor along the given axis with a logical OR operation |
| |
| include::{generated}/operators/REDUCE_ANY.adoc[] |
| |
| [source,c] |
| ---- |
| ERROR_IF(axis < 0 || axis >= rank(shape1)); |
| ERROR_IF(shape[axis] != 1); |
| |
| // Initialize output state to false |
| for_each(index in shape) { |
| tensor_write<in_out_t>(output, shape, index, false); |
| } |
| for_each(index in shape1) { |
| dim_t out_index = index; |
| out_index[axis] = 0; |
| in_out_t value = tensor_read<in_out_t>(input, shape1, index); |
| in_out_t state = tensor_read<in_out_t>(output, shape, out_index); |
| state = state || value; |
| tensor_write<in_out_t>(output, shape, out_index, state); |
| } |
| ---- |
| |
| ==== REDUCE_MAX |
| |
| Reduce a tensor along the given axis with a maximum operation |
| |
| include::{generated}/operators/REDUCE_MAX.adoc[] |
| |
| [source,c] |
| ---- |
| ERROR_IF(axis < 0 || axis >= rank(shape1)); |
| ERROR_IF(shape[axis] != 1); |
| for_each(index in shape) { |
| tensor_write<in_out_t>(output, shape, index, minimum<in_out_t>); |
| } |
| for_each(index in shape1) { |
| dim_t out_index = index; |
| out_index[axis] = 0; |
| in_out_t value = tensor_read<in_out_t>(input, shape1, index); |
| in_out_t state = tensor_read<in_out_t>(output, shape, out_index); |
| state = apply_max_s<in_out_t>(state, value); |
| tensor_write<in_out_t>(output, shape, out_index, state); |
| } |
| ---- |
| |
| ==== REDUCE_MIN |
| |
| Reduce a tensor along the given axis with a minimum operation |
| |
| include::{generated}/operators/REDUCE_MIN.adoc[] |
| |
| [source,c] |
| ---- |
| ERROR_IF(axis < 0 || axis >= rank(shape1)); |
| ERROR_IF(shape[axis] != 1); |
| for_each(index in shape) { |
| tensor_write<in_out_t>(output, shape, index, maximum<in_out_t>); |
| } |
| for_each(index in shape1) { |
| dim_t out_index = index; |
| out_index[axis] = 0; |
| in_out_t value = tensor_read<in_out_t>(input, shape1, index); |
| in_out_t state = tensor_read<in_out_t>(output, shape, out_index); |
| state = apply_min_s<in_out_t>(state, value); |
| tensor_write<in_out_t>(output, shape, out_index, state); |
| } |
| ---- |
| |
| ==== REDUCE_PRODUCT |
| |
| Reduce a tensor along the given axis by computing the product of the axis. |
| |
| include::{generated}/operators/REDUCE_PRODUCT.adoc[] |
| |
| [source,c] |
| ---- |
| ERROR_IF(axis < 0 || axis >= rank(shape1)); |
| ERROR_IF(shape[axis] != 1); |
| for_each(index in shape) { |
| tensor_write<in_out_t>(output, shape, index, 1.0); |
| } |
| for_each(index in shape1) { |
| dim_t out_index = index; |
| out_index[axis] = 0; |
| in_out_t value = tensor_read<in_out_t>(input, shape1, index); |
| in_out_t state = tensor_read<in_out_t>(output, shape, out_index); |
| state = apply_mul_s<in_out_t>(state, value); |
| tensor_write<in_out_t>(output, shape, out_index, state); |
| } |
| ---- |
| |
| ==== REDUCE_SUM |
| |
| Reduce a tensor along the given axis by computing the sum of the axis. |
| |
| include::{generated}/operators/REDUCE_SUM.adoc[] |
| |
| [source,c] |
| ---- |
| ERROR_IF(axis < 0 || axis >= rank(shape1)); |
| ERROR_IF(shape[axis] != 1); |
| for_each(index in shape) { |
| tensor_write<in_out_t>(output, shape, index, 0); |
| } |
| for_each(index in shape1) { |
| dim_t out_index = index; |
| out_index[axis] = 0; |
| in_out_t value = tensor_read<in_out_t>(input, shape1, index); |
| in_out_t state = tensor_read<in_out_t>(output, shape, out_index); |
| state = apply_add_s<in_out_t>(state, value); |
| tensor_write<in_out_t>(output, shape, out_index, state); |
| } |
| ---- |