#include <algorithm>
#include <cmath>
#include <cstdint>
#include <random>
#include "tensorflow/lite/core/c/builtin_op_data.h"
#include "tensorflow/lite/kernels/internal/tensor_ctypes.h"
#include "tensorflow/lite/kernels/kernel_util.h"
#include "tsl/lib/random/philox_random.h"
#include "tsl/lib/random/random_distributions_utils.h"
namespace tflite {
namespace ops {
namespace builtin {
namespace random {
namespace {
Generator;
enum RandomType { … };
struct OpData { … };
void InitializeOpData(TfLiteNode* node) { … }
void GenerateRandomUniformNumbers(
Generator& rng, float* buffer, size_t buffer_size) { … }
void GenerateRandomStandardNormalNumbers(
Generator& rng, float* buffer, size_t buffer_size) { … }
template <typename IntType>
void GenerateMultinomialNumbers(Generator& rng, int batch_size,
const float* logits, size_t logits_size,
IntType* output, size_t num_samples) { … }
}
void* Init(TfLiteContext* context, const char* buffer, size_t length) { … }
void Free(TfLiteContext* context, void* buffer) { … }
TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) { … }
TfLiteStatus PrepareMultinomial(TfLiteContext* context, TfLiteNode* node) { … }
TfLiteStatus EvalRandomType(
TfLiteContext* context, TfLiteNode* node, RandomType random_type) { … }
template <RandomType rtype>
TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) { … }
TfLiteStatus EvalMultinomial(TfLiteContext* context, TfLiteNode* node) { … }
}
TfLiteRegistration* Register_RANDOM_UNIFORM() { … }
TfLiteRegistration* Register_RANDOM_STANDARD_NORMAL() { … }
TfLiteRegistration* Register_MULTINOMIAL() { … }
}
}
}