chromium/third_party/tflite/src/tensorflow/lite/kernels/lsh_projection.cc

/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

// LSH Projection projects an input to a bit vector via locality sensitive
// hashing.
//
// Options:
//   Sparse:
//     Computed bit vector is considered to be sparse.
//     Each output element is an int32 made up by multiple bits computed from
// hash functions.
//
//   Dense:
//     Computed bit vector is considered to be dense. Each output element is
// either 0 or 1 that represents a bit.
//
// Input:
//   Tensor[0]: Hash functions. Dim.size == 2, DataType: Float.
//              Tensor[0].Dim[0]: Num of hash functions. Must be at least 1.
//              Tensor[0].Dim[1]: Num of projected output bits generated by
//                                each hash function.
//   In sparse case, Tensor[0].Dim[1] + ceil( log2(Tensor[0].Dim[0] )) <= 32.
//
//   Tensor[1]: Input. Dim.size >= 1, No restriction on DataType.
//   Tensor[2]: Optional, Weight. Dim.size == 1, DataType: Float.
//              If not set, each element of input is considered to have same
// weight of 1.0 Tensor[1].Dim[0] == Tensor[2].Dim[0]
//
// Output:
//   Sparse:
//     Output.Dim == { Tensor[0].Dim[0] }
//     A tensor of int32 that represents hash signatures,
//
//     NOTE: To avoid collisions across hash functions, an offset value of
//     k * (1 << Tensor[0].Dim[1]) will be added to each signature,
//     k is the index of the hash function.
//   Dense:
//     Output.Dim == { Tensor[0].Dim[0] * Tensor[0].Dim[1] }
//     A flattened tensor represents projected bit vectors.

#include <stddef.h>
#include <stdint.h>

#include <cstring>
#include <memory>

#include "tensorflow/lite/core/c/builtin_op_data.h"
#include "tensorflow/lite/core/c/common.h"
#include "tensorflow/lite/kernels/internal/tensor_ctypes.h"
#include "tensorflow/lite/kernels/kernel_util.h"
#include <farmhash.h>

namespace tflite {
namespace ops {
namespace builtin {
namespace lsh_projection {

TfLiteStatus Resize(TfLiteContext* context, TfLiteNode* node) {}

// Compute sign bit of dot product of hash(seed, input) and weight.
// NOTE: use float as seed, and convert it to double as a temporary solution
//       to match the trained model. This is going to be changed once the new
//       model is trained in an optimized method.
//
int RunningSignBit(const TfLiteTensor* input, const TfLiteTensor* weight,
                   float seed) {}

void SparseLshProjection(const TfLiteTensor* hash, const TfLiteTensor* input,
                         const TfLiteTensor* weight, int32_t* out_buf) {}

void DenseLshProjection(const TfLiteTensor* hash, const TfLiteTensor* input,
                        const TfLiteTensor* weight, int32_t* out_buf) {}

TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {}
}  // namespace lsh_projection

TfLiteRegistration* Register_LSH_PROJECTION() {}

}  // namespace builtin
}  // namespace ops
}  // namespace tflite