From 4671953808f87daa6c8355bdd961242290aab80f Mon Sep 17 00:00:00 2001 From: Vijay Vasudevan Date: Fri, 18 Mar 2016 19:38:21 -0800 Subject: Re-rollback of "TensorFlow: move eigen some NN code from our third_party/eigen3 copy to being part of TF, add tests." Change: 117608627 --- tensorflow/core/kernels/eigen_attention_test.cc | 107 ------------------------ 1 file changed, 107 deletions(-) delete mode 100644 tensorflow/core/kernels/eigen_attention_test.cc (limited to 'tensorflow/core/kernels/eigen_attention_test.cc') diff --git a/tensorflow/core/kernels/eigen_attention_test.cc b/tensorflow/core/kernels/eigen_attention_test.cc deleted file mode 100644 index 7d5e0b71b5..0000000000 --- a/tensorflow/core/kernels/eigen_attention_test.cc +++ /dev/null @@ -1,107 +0,0 @@ -/* Copyright 2015 Google Inc. 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. -==============================================================================*/ - -#include "tensorflow/core/kernels/eigen_attention.h" -#include "tensorflow/core/framework/types.h" -#include "tensorflow/core/platform/test.h" - -namespace Eigen { - -namespace { -void EigenApprox(float a, float b) { - ASSERT_TRUE(std::abs(a - b) <= std::min(std::abs(a), std::abs(b)) * 1e-3); -} -} - -TEST(EigenAttentionTest, Simple) { - const ptrdiff_t depth = 3; - const ptrdiff_t batch = 10; - const ptrdiff_t rows = 32; - const ptrdiff_t cols = 48; - const ptrdiff_t glimpse_rows = 8; - const ptrdiff_t glimpse_cols = 6; - - Tensor input(depth, rows, cols, batch); - input.setRandom(); - - std::vector> offsets; - offsets.resize(batch); - for (int i = 0; i < batch; ++i) { - offsets[i].first = (-5 + i) / 10.0f; - offsets[i].second = (5 - i) / 10.0f; - } - - Tensor result(depth, glimpse_rows, glimpse_cols, batch); - result = ExtractGlimpses(input, glimpse_rows, glimpse_cols, offsets); - - for (int b = 0; b < batch; ++b) { - for (int c = 0; c < glimpse_cols; ++c) { - ptrdiff_t source_c = - c + ((1.0f + offsets[b].second) * cols - glimpse_cols) / 2; - for (int r = 0; r < glimpse_rows; ++r) { - ptrdiff_t source_r = - r + ((1.0f + offsets[b].first) * rows - glimpse_rows) / 2; - for (int d = 0; d < depth; ++d) { - EigenApprox(result(d, r, c, b), input(d, source_r, source_c, b)); - } - } - } - } -} - -TEST(EigenAttentionTest, OutOfBoundsGlimpse) { - const ptrdiff_t depth = 3; - const ptrdiff_t batch = 10; - const ptrdiff_t rows = 32; - const ptrdiff_t cols = 48; - const ptrdiff_t glimpse_rows = 8; - const ptrdiff_t glimpse_cols = 6; - - Tensor input(depth, rows, cols, batch); - input.setRandom(); - - std::vector> offsets; - offsets.resize(batch); - for (int i = 0; i < batch; ++i) { - offsets[i].first = (-5 + i) / 2.0f; - offsets[i].second = (5 - i) / 2.0f; - } - - Tensor result(depth, glimpse_rows, glimpse_cols, batch); - result = ExtractGlimpses(input, glimpse_rows, glimpse_cols, offsets); - - for (int b = 0; b < batch; ++b) { - for (int c = 0; c < glimpse_cols; ++c) { - ptrdiff_t source_c = - c + ((1.0f + offsets[b].second) * cols - glimpse_cols) / 2; - if (source_c < glimpse_cols / 2 || source_c >= cols - glimpse_cols / 2) { - continue; - } - for (int r = 0; r < glimpse_rows; ++r) { - ptrdiff_t source_r = - r + ((1.0f + offsets[b].first) * rows - glimpse_rows) / 2; - if (source_r < glimpse_rows / 2 || - source_r >= rows - glimpse_rows / 2) { - continue; - } - for (int d = 0; d < depth; ++d) { - EigenApprox(result(d, r, c, b), input(d, source_r, source_c, b)); - } - } - } - } -} - -} // namespace Eigen -- cgit v1.2.3