• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 #ifndef ANDROID_FRAMEWORKS_ML_NN_COMMON_OPERATIONS_MULTINOMIAL_H
18 #define ANDROID_FRAMEWORKS_ML_NN_COMMON_OPERATIONS_MULTINOMIAL_H
19 
20 #include <algorithm>
21 #include <cmath>
22 #include <vector>
23 
24 #include "nnapi/Types.h"
25 
26 namespace android {
27 namespace nn {
28 
29 struct RunTimeOperandInfo;
30 struct Shape;
31 
32 class Multinomial {
33    public:
34     Multinomial(const Operation& operation, RunTimeOperandInfo* operands);
35 
36     static bool Prepare(const Operation& operation, RunTimeOperandInfo* operands,
37                         Shape* outputShape);
38     bool Eval();
39 
40     static constexpr int kInputTensor = 0;
41     static constexpr int kSampleCountParam = 1;
42     static constexpr int kRandomSeedsTensor = 2;
43 
44     static constexpr int kOutputTensor = 0;
45 
46    private:
47     void EvalFloat32(const float* inputData);
48 
49     RunTimeOperandInfo* input_;
50     int sample_count_;
51     RunTimeOperandInfo* random_seeds_;
52 
53     RunTimeOperandInfo* output_;
54 };
55 
56 }  // namespace nn
57 }  // namespace android
58 
59 #endif  // ANDROID_FRAMEWORKS_ML_NN_COMMON_OPERATIONS_MULTINOMIAL_H
60