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 IdentityNOp.""" 16 17 from __future__ import absolute_import 18 from __future__ import division 19 from __future__ import print_function 20 21 import numpy as np 22 23 from tensorflow.python.framework import constant_op 24 from tensorflow.python.ops import array_ops 25 from tensorflow.python.platform import test 26 27 28 class IdentityNOpTest(test.TestCase): 29 30 def testInt32String_6(self): 31 with self.test_session() as sess: 32 [value0, value1] = sess.run( 33 array_ops.identity_n([[1, 2, 3, 4, 5, 6], 34 [b"a", b"b", b"C", b"d", b"E", b"f", b"g"]])) 35 self.assertAllEqual(np.array([1, 2, 3, 4, 5, 6]), value0) 36 self.assertAllEqual( 37 np.array([b"a", b"b", b"C", b"d", b"E", b"f", b"g"]), value1) 38 39 def testInt32_shapes(self): 40 with self.test_session() as sess: 41 inp0 = constant_op.constant([10, 20, 30, 40, 50, 60], shape=[2, 3]) 42 inp1 = constant_op.constant([11, 21, 31, 41, 51, 61], shape=[3, 2]) 43 inp2 = constant_op.constant( 44 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], shape=[5, 3]) 45 [value0, value1, 46 value2] = sess.run(array_ops.identity_n([inp0, inp1, inp2])) 47 self.assertAllEqual(np.array([[10, 20, 30], [40, 50, 60]]), value0) 48 self.assertAllEqual(np.array([[11, 21], [31, 41], [51, 61]]), value1) 49 self.assertAllEqual( 50 np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15]]), 51 value2) 52 53 def testString(self): 54 source = [b"A", b"b", b"C", b"d", b"E", b"f"] 55 with self.test_session() as sess: 56 [value] = sess.run(array_ops.identity_n([source])) 57 self.assertAllEqual(source, value) 58 59 def testIdentityShape(self): 60 with self.test_session(): 61 shape = [2, 3] 62 array_2x3 = [[1, 2, 3], [6, 5, 4]] 63 tensor = constant_op.constant(array_2x3) 64 self.assertEquals(shape, tensor.get_shape()) 65 self.assertEquals(shape, array_ops.identity_n([tensor])[0].get_shape()) 66 self.assertEquals(shape, array_ops.identity_n([array_2x3])[0].get_shape()) 67 68 69 if __name__ == "__main__": 70 test.main() 71