1 /*
2  * Copyright (C) 2019 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 #define LOG_TAG "Operations"
18 
19 #include "Rank.h"
20 
21 #include "LegacyUtils.h"
22 #include "OperationResolver.h"
23 #include "OperationsExecutionUtils.h"
24 
25 namespace android {
26 namespace nn {
27 namespace rank_op {
28 
prepare(IOperationExecutionContext * context)29 bool prepare(IOperationExecutionContext* context) {
30     Shape output = context->getOutputShape(kOutputScalar);
31     return context->setOutputShape(kOutputScalar, output);
32 }
33 
execute(IOperationExecutionContext * context)34 bool execute(IOperationExecutionContext* context) {
35     *context->getOutputBuffer<int32_t>(kOutputScalar) =
36             getNumberOfDimensions(context->getInputShape(kInputTensor));
37     return true;
38 }
39 
40 }  // namespace rank_op
41 
42 NN_REGISTER_OPERATION_DEFAULT_VALIDATION(RANK, rank_op::prepare, rank_op::execute);
43 
44 }  // namespace nn
45 }  // namespace android
46