def test_raises_when_positive(self): with self.test_session(): doug = tf.constant([1, 2], name="doug") with tf.control_dependencies([tf.assert_negative(doug)]): out = tf.identity(doug) with self.assertRaisesOpError("doug"): out.eval()
def test_raises_when_zero(self): with self.test_session(): claire = tf.constant([0], name="claire") with tf.control_dependencies([tf.assert_negative(claire)]): out = tf.identity(claire) with self.assertRaisesOpError("claire"): out.eval()
def test_raises_when_zero(self): with self.test_session(): claire = tf.constant([0], name="claire") with tf.control_dependencies([tf.assert_negative(claire)]): out = tf.identity(claire) with self.assertRaisesOpError("claire"): out.eval()
def test_raises_when_positive(self): with self.test_session(): doug = tf.constant([1, 2], name="doug") with tf.control_dependencies([tf.assert_negative(doug)]): out = tf.identity(doug) with self.assertRaisesOpError("doug"): out.eval()
def test_empty_tensor_doesnt_raise(self): # A tensor is negative when it satisfies: # For every element x_i in x, x_i < 0 # and an empty tensor has no elements, so this is trivially satisfied. # This is standard set theory. with self.test_session(): empty = tf.constant([], name="empty") with tf.control_dependencies([tf.assert_negative(empty)]): out = tf.identity(empty) out.eval()
def test_empty_tensor_doesnt_raise(self): # A tensor is negative when it satisfies: # For every element x_i in x, x_i < 0 # and an empty tensor has no elements, so this is trivially satisfied. # This is standard set theory. with self.test_session(): empty = tf.constant([], name="empty") with tf.control_dependencies([tf.assert_negative(empty)]): out = tf.identity(empty) out.eval()
matrix1 = tf.constant([[3., 3.]]) matrix2 = tf.constant([[2.], [2.]]) product = tf.matmul(matrix1, matrix2) result = sess.run([product]) print(result) print(result[0][0][0]) input1 = tf.constant(3.0) input2 = tf.constant(2.0) input3 = tf.constant(5.0) intermed = tf.add(input2, input3) mul = tf.multiply(input1, intermed) with tf.Session() as sess: result = sess.run([mul, intermed]) print(result[0]) print(result[1]) in1 = tf.placeholder(tf.float32) in2 = tf.placeholder(tf.float32) output = tf.multiply(in1, in2) with tf.Session() as sess: result = sess.run([output], feed_dict={in1: [7.], in2: [2.]}) print(result) print(result[0]) x = -1 with tf.control_dependencies([tf.assert_negative(x)]): output = tf.reduce_sum(x) print(output)
def test_doesnt_raise_when_negative(self): with self.test_session(): frank = tf.constant([-1, -2], name="frank") with tf.control_dependencies([tf.assert_negative(frank)]): out = tf.identity(frank) out.eval()
def test_doesnt_raise_when_negative(self): with self.test_session(): frank = tf.constant([-1, -2], name="frank") with tf.control_dependencies([tf.assert_negative(frank)]): out = tf.identity(frank) out.eval()