2019-12-27 22:16:57 +08:00
|
|
|
//
|
|
|
|
// ShapeScatterNd.cpp
|
|
|
|
// MNN
|
|
|
|
//
|
|
|
|
// Created by MNN on 2019/11/27.
|
|
|
|
// Copyright © 2018, Alibaba Group Holding Limited
|
|
|
|
//
|
|
|
|
|
|
|
|
|
2020-11-05 16:41:56 +08:00
|
|
|
#include "shape/SizeComputer.hpp"
|
2019-12-27 22:16:57 +08:00
|
|
|
#include "core/Macro.h"
|
|
|
|
|
|
|
|
namespace MNN {
|
|
|
|
// Size Computer
|
|
|
|
class ShapeScatterNd : public SizeComputer {
|
|
|
|
bool onComputeSize(const MNN::Op *op, const std::vector<Tensor *> &inputs,
|
|
|
|
const std::vector<Tensor *> &outputs) const override {
|
2022-02-18 11:30:27 +08:00
|
|
|
MNN_ASSERT(3 <= inputs.size());
|
2019-12-27 22:16:57 +08:00
|
|
|
auto indices = inputs[0];
|
|
|
|
auto updates = inputs[1];
|
|
|
|
auto shape = inputs[2];
|
|
|
|
auto output = outputs[0];
|
2023-10-18 10:31:02 +08:00
|
|
|
//MNN_CHECK(shape->dimensions() == 1, "shape rank should be one");
|
2019-12-27 22:16:57 +08:00
|
|
|
const int indicesDimension = indices->dimensions();
|
2020-11-05 16:41:56 +08:00
|
|
|
//MNN_CHECK(indices->length(indicesDimension - 1) == 1, "indices.shape[-1] = shape.rank");
|
2019-12-27 22:16:57 +08:00
|
|
|
|
|
|
|
const int outerDims = indicesDimension - 1;
|
|
|
|
const int dimension = shape->length(0);
|
2023-10-18 10:31:02 +08:00
|
|
|
//MNN_CHECK(updates->dimensions() == dimension, "updates dimension should be equal to given shape");
|
2019-12-27 22:16:57 +08:00
|
|
|
|
|
|
|
output->buffer().dimensions = dimension;
|
|
|
|
|
|
|
|
auto shapeData = shape->host<int>();
|
|
|
|
for (int i = 0; i < dimension; ++i) {
|
|
|
|
output->setLength(i, shapeData[i]);
|
|
|
|
}
|
|
|
|
output->buffer().type = updates->buffer().type;
|
|
|
|
|
|
|
|
TensorUtils::getDescribe(output)->dimensionFormat = TensorUtils::getDescribe(updates)->dimensionFormat;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
REGISTER_SHAPE_INPUTS(ShapeScatterNd, OpType_ScatterNd, (std::vector<int>{2}));
|
|
|
|
} // namespace MNN
|