#define NNCC_IR_NODE_DOT_BUILDER_H
#include "core/modelIR/Shape.h"
-#include "core/modelIR/operations/common.h"
+#include "core/modelIR/operations/CommonProps.h"
#include "core/modelIR/operations/PoolOp.h"
namespace nnc
* limitations under the License.
*/
-#ifndef _NNC_CORE_IR_MODEL_COMMON_H_
-#define _NNC_CORE_IR_MODEL_COMMON_H_
+#ifndef _NNC_CORE_IR_MODEL_COMMON_PROPS_H_
+#define _NNC_CORE_IR_MODEL_COMMON_PROPS_H_
namespace nnc {
namespace mir {
} // namespace mir
} // namespace nnc
-#endif //_NNC_CORE_IR_MODEL_COMMOND_H_
+#endif //_NNC_CORE_IR_MODEL_COMMON_PROPS_H_
#include <vector>
#include "core/modelIR/Operation.h"
-#include "core/modelIR/operations/common.h"
+#include "core/modelIR/operations/CommonProps.h"
#include "core/modelIR/TensorVariant.h"
namespace nnc {
#define _NNC_CORE_IR_MODEL_DECONV_2D_H_
#include "core/modelIR/Operation.h"
-#include "core/modelIR/operations/common.h"
+#include "core/modelIR/operations/CommonProps.h"
#include "core/modelIR/TensorVariant.h"
namespace nnc {
#include "core/modelIR/Operation.h"
#include "core/modelIR/TensorVariant.h"
-#include "core/modelIR/operations/common.h"
+#include "core/modelIR/operations/CommonProps.h"
namespace nnc {
namespace mir {
#define _NNC_CORE_IR_MODEL_POOL_H_
#include "core/modelIR/Operation.h"
-#include "core/modelIR/operations/common.h"
+#include "core/modelIR/operations/CommonProps.h"
#include <vector>
#include <cmath>
FuncType func_type)
: Operation(Type::reduceF, {arg}), _reduceDims(reduce_dims), _keepDims(keep_dims),
_funcType(func_type) {
+
// Infer output shapes.
const auto& input_shape = getInputShape(0);
const auto& red_dims = getReductionDims();
Shape output_shape;
+
if (getKeepDims()) {
output_shape = input_shape;
for (auto red_axis: red_dims) {
output_shape.dim(red_axis) = 1;
}
} else {
+ // This mask contains true for axis indexes that should be reduced
+ // for example, if we want to reduce 1 and 3 axes, with total number of dims 4
+ // mask will contain: [false, true, false, true]
+ std::vector<bool> reduce_axis_mask(input_shape.rank(), false);
+ for (auto axis: red_dims)
+ reduce_axis_mask[axis] = true;
+
+ // Actual shape inference
std::vector<int32_t> out_dims;
out_dims.reserve(input_shape.rank() - red_dims.size());
- auto red_axis = red_dims.begin();
for (int32_t axis_id = 0; axis_id < input_shape.rank(); axis_id++) {
- if (axis_id == (*red_axis)) {
- red_axis++;
- } else {
+ if (!reduce_axis_mask[axis_id])
out_dims.emplace_back(input_shape.dim(axis_id));
- }
}
output_shape = Shape(out_dims);
}
#include "core/modelIR/Graph.h"
#include "core/modelIR/TensorVariant.h"
-#include "core/modelIR/operations/common.h"
+#include "core/modelIR/operations/CommonProps.h"
#include "core/modelIR/Shape.h"
#include "caffe/proto/caffe.pb.h"
#include "OperationImpl.h"
-#include "core/modelIR/operations/common.h"
+#include "core/modelIR/operations/CommonProps.h"
#include "core/modelIR/operations/DepthwiseConv2DOp.h"
namespace nnc
#include "OperationImpl.h"
#include "core/modelIR/operations/PoolOp.h"
-#include "core/modelIR/operations/common.h"
+#include "core/modelIR/operations/CommonProps.h"
namespace nnc
{
out_id.resize(_outputShape.rank());
for (const mir::Index& input_id : mir::ShapeRange(_inShape)) {
int32_t out_idx_id = 0;
- int32_t red_dim = 0;
+
+ // This mask contains true for axis indexes that should be reduced
+ // for example, if we want to reduce 1 and 3 axes, with total number of dims 4
+ // mask will contain: [false, true, false, true]
+ std::vector<bool> reduce_axis_mask(_inShape.rank(), false);
+ for (auto axis: _reductionDims)
+ reduce_axis_mask[axis] = true;
+
// change out id to point to the correct cell
- for (int d = 0; d != _inShape.rank(); ++d) {
- if (d == _reductionDims[red_dim]) {
- red_dim++;
- if (_keepDims)
- out_id.at(out_idx_id++) = 0;
- else
+ if (_keepDims) {
+ for (int32_t d = 0; d < _inShape.rank(); ++d)
+ out_id.at(out_idx_id++) = reduce_axis_mask[d] ? 0 : input_id.at(d);
+ } else {
+ for (int32_t d = 0; d < _inShape.rank(); ++d) {
+ if (reduce_axis_mask[d])
continue;
- } else {
out_id.at(out_idx_id++) = input_id.at(d);
}
}
#include <memory>
#include "core/modelIR/Graph.h"
#include "core/modelIR/TensorVariant.h"
-#include "core/modelIR/operations/common.h"
+#include "core/modelIR/operations/CommonProps.h"
#include "core/modelIR/operations/ElementwiseOp.h"
#include "core/modelIR/Shape.h"
#include "onnx/onnx.pb.h"
#include "core/modelIR/Scalar.h"
#include "core/modelIR/Shape.h"
-#include "core/modelIR/operations/common.h"
+#include "core/modelIR/operations/CommonProps.h"
#include "core/modelIR/operations/ReduceFOp.h"
#include "schema_generated.h"
#include <cassert>
#include "core/modelIR/TensorVariant.h"
-#include "core/modelIR/operations/common.h"
+#include "core/modelIR/operations/CommonProps.h"
#include "core/modelIR/operations/PoolOp.h"
#include "op_info_generated.h"