aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/kernels/eigen_attention_test.cc
diff options
context:
space:
mode:
authorGravatar Vijay Vasudevan <vrv@google.com>2016-03-18 19:38:21 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2016-03-18 22:02:47 -0700
commit4671953808f87daa6c8355bdd961242290aab80f (patch)
tree2bfbf9bb34c8501bb2470994a73d108b76b43ec3 /tensorflow/core/kernels/eigen_attention_test.cc
parentedf3586caf997d94175a21b5561dbcfaaf9de9ac (diff)
Re-rollback of "TensorFlow: move eigen some NN code from our third_party/eigen3 copy
to being part of TF, add tests." Change: 117608627
Diffstat (limited to 'tensorflow/core/kernels/eigen_attention_test.cc')
-rw-r--r--tensorflow/core/kernels/eigen_attention_test.cc107
1 files changed, 0 insertions, 107 deletions
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<float, 4> input(depth, rows, cols, batch);
- input.setRandom();
-
- std::vector<IndexPair<float>> 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<float, 4> 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<float, 4> input(depth, rows, cols, batch);
- input.setRandom();
-
- std::vector<IndexPair<float>> 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<float, 4> 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