1# Copyright 2015 The TensorFlow Authors. All Rights Reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14# ============================================================================== 15"""Tests for tensorflow.ops.nn_ops.Cross.""" 16 17from __future__ import absolute_import 18from __future__ import division 19from __future__ import print_function 20 21from tensorflow.python.ops import array_ops 22from tensorflow.python.ops import gradient_checker 23from tensorflow.python.ops import math_ops 24from tensorflow.python.platform import test 25 26 27class CrossOpTest(test.TestCase): 28 29 def testGradientRandomValues(self): 30 with self.test_session(): 31 us = [2, 3] 32 u = array_ops.reshape( 33 [0.854, -0.616, 0.767, 0.725, -0.927, 0.159], shape=us) 34 v = array_ops.reshape( 35 [-0.522, 0.755, 0.407, -0.652, 0.241, 0.247], shape=us) 36 s = math_ops.cross(u, v) 37 jacob_u, jacob_v = gradient_checker.compute_gradient([u, v], [us, us], s, 38 us) 39 40 self.assertAllClose(jacob_u[0], jacob_u[1], rtol=1e-3, atol=1e-3) 41 self.assertAllClose(jacob_v[0], jacob_v[1], rtol=1e-3, atol=1e-3) 42 43 44if __name__ == "__main__": 45 test.main() 46