1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "ArithmeticOperationConverter.h" 18 19 #include <vector> 20 21 #include "OperationConverterResolver.h" 22 #include "SubGraphContext.h" 23 24 namespace android { 25 namespace nn { 26 getArithmeticInputs(const Operation & operation,SubGraphContext * context) const27Result<std::vector<int32_t>> ArithmeticOperationConverterBase::getArithmeticInputs( 28 const Operation& operation, SubGraphContext* context) const { 29 NN_TRY(context->createTensorFlatbufferFromOperand(operation.inputs[kInput1TensorIdx])); 30 NN_TRY(context->createTensorFlatbufferFromOperand(operation.inputs[kInput2TensorIdx])); 31 std::vector<int32_t> inputs{ 32 context->getTensorIdxFromOperandIdx(operation.inputs[kInput1TensorIdx]), 33 context->getTensorIdxFromOperandIdx(operation.inputs[kInput2TensorIdx])}; 34 return inputs; 35 } 36 getArithmeticOutputs(const Operation & operation,SubGraphContext * context) const37Result<std::vector<int32_t>> ArithmeticOperationConverterBase::getArithmeticOutputs( 38 const Operation& operation, SubGraphContext* context) const { 39 NN_TRY(context->createTensorFlatbufferFromOperand(operation.outputs[kOutputTensorIdx])); 40 std::vector<int32_t> outputs{ 41 context->getTensorIdxFromOperandIdx(operation.outputs[kOutputTensorIdx])}; 42 return outputs; 43 } 44 45 } // namespace nn 46 } // namespace android