def test_reduce_batch_minus_min_and_max_per_key(self, placeholder_fn, value, expected_result): x = placeholder_fn() key = tf.constant(['a', 'a', 'a', 'b']) batch_keys, batch_minus_min, batch_max = ( tf_utils.reduce_batch_minus_min_and_max_per_key(x, key)) with tf.compat.v1.Session() as sess: result = sess.run([batch_keys, batch_minus_min, batch_max], feed_dict={x: value}) self.assertAllEqual(result[0], expected_result[0]) self.assertAllEqual(result[1:], expected_result[1:])
def test_sparse_indices(self): exception_cls = tf.errors.InvalidArgumentError error_string = 'Condition x == y did not hold element-wise:' value = tf.compat.v1.SparseTensorValue( indices=[[0, 0], [1, 1], [2, 2], [3, 1]], values=[3, 2, -1, 3], dense_shape=[4, 5]) key_value = tf.compat.v1.SparseTensorValue( indices=[[0, 0], [1, 2], [2, 2], [3, 1]], values=['a', 'a', 'a', 'b'], dense_shape=[4, 5]) with tf.compat.v1.Graph().as_default(): x = tf.compat.v1.sparse_placeholder(tf.int64, shape=[None, None]) key = tf.compat.v1.sparse_placeholder(tf.string, shape=[None, None]) with tf.compat.v1.Session() as sess: with self.assertRaisesRegexp(exception_cls, error_string): sess.run(tf_utils.reduce_batch_minus_min_and_max_per_key(x, key), feed_dict={x: value, key: key_value})
def _reduce_batch_minus_min_and_max_per_key(x, key): return tf_utils.reduce_batch_minus_min_and_max_per_key(x, key)