def _test64BitOutput(self): with self.test_session(): inp = tf.zeros([2**31]) num_elements = array_ops.size_internal( inp, optimize=False, out_type=tf.int64) self.assertEqual(2**31, num_elements.eval()) # Too large for tf.int32 output. with self.assertRaises(tf.errors.InvalidArgumentError): with self.test_session(): inp = tf.zeros([2**31]) num_elements = array_ops.size_internal( inp, optimize=False, out_type=tf.int32) self.assertEqual(2**31, num_elements.eval())
def _test64BitOutput(self): with self.cached_session(): inp = array_ops.zeros([2**31]) num_elements = array_ops.size_internal( inp, optimize=False, out_type=dtypes.int64) self.assertEqual(2**31, self.evaluate(num_elements)) # Too large for tf.int32 output. with self.assertRaises(errors_impl.InvalidArgumentError): with self.cached_session(): inp = array_ops.zeros([2**31]) num_elements = array_ops.size_internal( inp, optimize=False, out_type=dtypes.int32) self.assertEqual(2**31, self.evaluate(num_elements))
def _test64BitOutput(self): with self.test_session(): inp = tf.zeros([2**31]) num_elements = array_ops.size_internal(inp, optimize=False, out_type=tf.int64) self.assertEqual(2**31, num_elements.eval()) # Too large for tf.int32 output. with self.assertRaises(tf.errors.InvalidArgumentError): with self.test_session(): inp = tf.zeros([2**31]) num_elements = array_ops.size_internal(inp, optimize=False, out_type=tf.int32) self.assertEqual(2**31, num_elements.eval())
def testSize(self): size_op = lambda x: array_ops.size_internal(x, optimize=False) for dtype in self.numeric_types: self._testUnary(size_op, dtype(7), expected=np.int32(1)) self._testUnary( size_op, np.array([[], []], dtype=dtype), expected=np.int32(0)) self._testUnary( size_op, np.array([-1, 1], dtype=dtype), expected=np.int32(2)) self._testUnary( size_op, np.array([[-1, 1]], dtype=dtype), expected=np.int32(2)) self._testUnary( size_op, np.array([[-1], [1], [4]], dtype=dtype), expected=np.int32(3))
def testSize(self): size_op = lambda x: array_ops.size_internal(x, optimize=False) for dtype in self.numeric_types: self._assertOpOutputMatchesExpected( size_op, dtype(7), expected=np.int32(1)) self._assertOpOutputMatchesExpected( size_op, np.array([[], []], dtype=dtype), expected=np.int32(0)) self._assertOpOutputMatchesExpected( size_op, np.array([-1, 1], dtype=dtype), expected=np.int32(2)) self._assertOpOutputMatchesExpected( size_op, np.array([[-1, 1]], dtype=dtype), expected=np.int32(2)) self._assertOpOutputMatchesExpected( size_op, np.array([[-1], [1], [4]], dtype=dtype), expected=np.int32(3))
def size_op(x): return array_ops.size_internal(x, optimize=False, out_type=np.int64)