Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions tensorflow/lite/kernels/internal/reference/floor.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ namespace tflite {

namespace reference_ops {

inline void Floor(const RuntimeShape& input_shape, const float* input_data,
const RuntimeShape& output_shape, float* output_data) {
template <typename T>
inline void Floor(const RuntimeShape& input_shape, const T* input_data,
const RuntimeShape& output_shape, T* output_data) {
const int flat_size = MatchingFlatSize(input_shape, output_shape);

for (int i = 0; i < flat_size; i++) {
int offset = i;
output_data[offset] = std::floor(input_data[offset]);
output_data[offset] =
static_cast<T>(std::floor(static_cast<float>(input_data[offset])));
}
}

Expand Down
9 changes: 5 additions & 4 deletions tensorflow/lite/kernels/internal/reference/logistic.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ limitations under the License.
namespace tflite {
namespace reference_ops {

inline void Logistic(const RuntimeShape& input_shape, const float* input_data,
const RuntimeShape& output_shape, float* output_data) {
template <typename T>
inline void Logistic(const RuntimeShape& input_shape, const T* input_data,
const RuntimeShape& output_shape, T* output_data) {
const float cutoff_upper = 16.619047164916992188f;
const float cutoff_lower = -9.f;

Expand All @@ -43,7 +44,7 @@ inline void Logistic(const RuntimeShape& input_shape, const float* input_data,
// optimized kernels. (check the definition of scalar_logistic_op<float>)

for (int i = 0; i < flat_size; i++) {
float val = input_data[i];
T val = input_data[i];
float result;
if (val > cutoff_upper) {
result = 1.0f;
Expand All @@ -52,7 +53,7 @@ inline void Logistic(const RuntimeShape& input_shape, const float* input_data,
} else {
result = 1.f / (1.f + std::exp(-val));
}
output_data[i] = result;
output_data[i] = static_cast<T>(result);
}
}

Expand Down
7 changes: 4 additions & 3 deletions tensorflow/lite/kernels/internal/reference/round.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@ inline float RoundToNearest(float value) {
}
}

inline void Round(const RuntimeShape& input_shape, const float* input_data,
const RuntimeShape& output_shape, float* output_data) {
template <typename Scalar>
inline void Round(const RuntimeShape& input_shape, const Scalar* input_data,
const RuntimeShape& output_shape, Scalar* output_data) {
const int flat_size = MatchingFlatSize(input_shape, output_shape);
for (int i = 0; i < flat_size; ++i) {
// Note that this implementation matches that of tensorFlow tf.round
// and corresponds to the bankers rounding method.
// cfenv (for fesetround) is not yet supported universally on Android, so
// using a work around.
output_data[i] = RoundToNearest(input_data[i]);
output_data[i] = static_cast<Scalar>(RoundToNearest(input_data[i]));
}
}

Expand Down
9 changes: 4 additions & 5 deletions tensorflow/lite/kernels/internal/reference/tanh.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ limitations under the License.
namespace tflite {
namespace reference_ops {

inline void Tanh(const RuntimeShape& input_shape, const float* input_data,
const RuntimeShape& output_shape, float* output_data) {
template <typename T>
inline void Tanh(const RuntimeShape& input_shape, const T* input_data,
const RuntimeShape& output_shape, T* output_data) {
const int flat_size = MatchingFlatSize(input_shape, output_shape);

for (int i = 0; i < flat_size; i++) {
float val = input_data[i];
float result = std::tanh(val);
output_data[i] = result;
output_data[i] = static_cast<T>(std::tanh(input_data[i]));
}
}

Expand Down
Loading