Skip to content

Commit

Permalink
Move template function
Browse files Browse the repository at this point in the history
  • Loading branch information
daquexian committed Aug 6, 2019
1 parent 5f76678 commit 589611c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
21 changes: 0 additions & 21 deletions dnnlibrary/ModelBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,27 +266,6 @@ ModelBuilder::Shape ModelBuilder::GetBlobDim(uint32_t index) {
throw std::invalid_argument("Wrong index in GetBlobDim");
}

template <typename... OperandTypes>
ModelBuilder::IndexSeq ModelBuilder::AddOperation(
int op, IndexSeq input_indexes, OperandTypes... operand_types) {
using android::nn::wrapper::OperandType;
vector<OperandType> types;
(types.push_back(operand_types), ...);
IndexSeq output_indexes;
for (const auto &type : types) {
auto index = AddNewOperand(type);
output_indexes.push_back(index);
}

THROW_ON_ERROR_WITH_NOTE(
nnapi_->ANeuralNetworksModel_addOperation(
dnn_model_->model_, op, input_indexes.size(), &input_indexes[0],
output_indexes.size(), &output_indexes[0]),
"op = " + std::to_string(op));

return output_indexes;
}

void ModelBuilder::Prepare() {
dnn_model_ = std::unique_ptr<Model>(new Model());
const auto ret = nnapi_->ANeuralNetworksModel_create(&dnn_model_->model_);
Expand Down
22 changes: 22 additions & 0 deletions dnnlibrary/ModelBuilderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,4 +632,26 @@ ModelBuilder::Index ModelBuilder::AddMul(
return AddMul(input1_name, input2_name, ANEURALNETWORKS_FUSED_NONE,
output_name, output_quant_info);
}

template <typename... OperandTypes>
ModelBuilder::IndexSeq ModelBuilder::AddOperation(
int op, IndexSeq input_indexes, OperandTypes... operand_types) {
using android::nn::wrapper::OperandType;
std::vector<OperandType> types;
(types.push_back(operand_types), ...);
IndexSeq output_indexes;
for (const auto &type : types) {
auto index = AddNewOperand(type);
output_indexes.push_back(index);
}

THROW_ON_ERROR_WITH_NOTE(
nnapi_->ANeuralNetworksModel_addOperation(
dnn_model_->model_, op, input_indexes.size(), &input_indexes[0],
output_indexes.size(), &output_indexes[0]),
"op = " + std::to_string(op));

return output_indexes;
}

} // namespace dnn

0 comments on commit 589611c

Please sign in to comment.