def testMultiStack(self): with self.test_session(), self.test_scope(): v = array_ops.placeholder(dtypes.float32) h1 = gen_data_flow_ops._stack_v2(5, dtypes.float32, stack_name="foo") c1 = gen_data_flow_ops._stack_push_v2(h1, v) with ops.control_dependencies([c1]): c1 = gen_data_flow_ops._stack_pop_v2(h1, dtypes.float32) h2 = gen_data_flow_ops._stack_v2(5, dtypes.float32, stack_name="bar") c2 = gen_data_flow_ops._stack_push_v2(h2, 5.0) with ops.control_dependencies([c2]): c2 = gen_data_flow_ops._stack_pop_v2(h2, dtypes.float32) r = c1 + c2 self.assertAllClose(9.0, r.eval({v: 4.0}))
def _testMultiStack(self, use_gpu): with self.test_session(use_gpu=use_gpu): h1 = gen_data_flow_ops._stack_v2( -1, elem_type=dtypes.float32, stack_name="foo") c1 = gen_data_flow_ops._stack_push_v2(h1, 4.0) with ops.control_dependencies([c1]): c1 = gen_data_flow_ops._stack_pop_v2(h1, dtypes.float32) h2 = gen_data_flow_ops._stack_v2( -1, elem_type=dtypes.float32, stack_name="bar") c2 = gen_data_flow_ops._stack_push_v2(h2, 5.0) with ops.control_dependencies([c2]): c2 = gen_data_flow_ops._stack_pop_v2(h2, dtypes.float32) r = c1 + c2 self.assertAllClose(9.0, r.eval())
def _testStackWhileSwap(self, use_gpu): with self.test_session(use_gpu=use_gpu): n = constant_op.constant(0) h = gen_data_flow_ops._stack_v2( -1, elem_type=dtypes.float32, stack_name="foo") def c(x): return math_ops.less(x, 10) def b(x): with ops.control_dependencies([x]): a = constant_op.constant(np.ones(2000), dtype=dtypes.float32) v = gen_data_flow_ops._stack_push_v2(h, a, swap_memory=True) with ops.control_dependencies([v]): return math_ops.add(x, 1) r = control_flow_ops.while_loop(c, b, [n]) v = constant_op.constant(np.zeros(2000), dtype=dtypes.float32) def c1(x, y): del y return math_ops.greater(x, 0) def b1(x, y): nx = math_ops.subtract(x, 1) ny = y + gen_data_flow_ops._stack_pop_v2(h, dtypes.float32) return [nx, ny] _, ry = control_flow_ops.while_loop( c1, b1, [r, v], [r.get_shape(), tensor_shape.unknown_shape()]) self.assertAllClose(np.ones(2000) * 10.0, ry.eval())
def _testCloseStack(self, use_gpu): with self.test_session(use_gpu=use_gpu) as sess: h = gen_data_flow_ops._stack_v2(-1, elem_type=dtypes.float32, stack_name="foo") c1 = gen_data_flow_ops._stack_close_v2(h) sess.run(c1)
def _testMultiStack(self, use_gpu): with self.test_session(use_gpu=use_gpu): h1 = gen_data_flow_ops._stack_v2(-1, elem_type=dtypes.float32, stack_name="foo") c1 = gen_data_flow_ops._stack_push_v2(h1, 4.0) with ops.control_dependencies([c1]): c1 = gen_data_flow_ops._stack_pop_v2(h1, dtypes.float32) h2 = gen_data_flow_ops._stack_v2(-1, elem_type=dtypes.float32, stack_name="bar") c2 = gen_data_flow_ops._stack_push_v2(h2, 5.0) with ops.control_dependencies([c2]): c2 = gen_data_flow_ops._stack_pop_v2(h2, dtypes.float32) r = c1 + c2 self.assertAllClose(9.0, r.eval())
def testPushCloseStack(self): with self.test_session() as sess, self.test_scope(): v = array_ops.placeholder(dtypes.float32) h = gen_data_flow_ops._stack_v2(5, dtypes.float32, stack_name="foo") c = gen_data_flow_ops._stack_push_v2(h, v) with ops.control_dependencies([c]): c1 = gen_data_flow_ops._stack_close_v2(h) sess.run(c1, {v: [[4.0, 5.0]]})
def testCloseStack(self): with self.test_session() as sess, self.test_scope(): size = array_ops.placeholder(dtypes.int32) h = gen_data_flow_ops._stack_v2(size, dtypes.float32, stack_name="foo") c1 = gen_data_flow_ops._stack_close_v2(h) sess.run(c1, {size: 5})
def testMultiStack(self): with self.test_session(), self.test_scope(): v = array_ops.placeholder(dtypes.float32) h1 = gen_data_flow_ops._stack_v2(5, dtypes.float32, stack_name="foo") c1 = gen_data_flow_ops._stack_push_v2(h1, v) with ops.control_dependencies([c1]): c1 = gen_data_flow_ops._stack_pop_v2(h1, dtypes.float32) h2 = gen_data_flow_ops._stack_v2(5, dtypes.float32, stack_name="bar") c2 = gen_data_flow_ops._stack_push_v2(h2, 5.0) with ops.control_dependencies([c2]): c2 = gen_data_flow_ops._stack_pop_v2(h2, dtypes.float32) r = c1 + c2 self.assertAllClose(9.0, r.eval({v: 4.0}))
def _testStackPushPop(self, use_gpu): with self.test_session(use_gpu=use_gpu): h = gen_data_flow_ops._stack_v2( -1, elem_type=dtypes.float32, stack_name="foo") c = gen_data_flow_ops._stack_push_v2(h, [[4.0, 5.0]]) with ops.control_dependencies([c]): c1 = gen_data_flow_ops._stack_pop_v2(h, dtypes.float32) self.assertAllClose([[4.0, 5.0]], c1.eval())
def _testPushCloseStack(self, use_gpu): with self.test_session(use_gpu=use_gpu) as sess: h = gen_data_flow_ops._stack_v2( -1, elem_type=dtypes.float32, stack_name="foo") c = gen_data_flow_ops._stack_push_v2(h, [[4.0, 5.0]]) with ops.control_dependencies([c]): c1 = gen_data_flow_ops._stack_close_v2(h) sess.run(c1)
def testSameNameStacks(self): """Different stacks with the same name do not interfere.""" with self.test_session() as sess, self.test_scope(): v1 = array_ops.placeholder(dtypes.float32) v2 = array_ops.placeholder(dtypes.float32) h1 = gen_data_flow_ops._stack_v2(5, dtypes.float32, stack_name="foo") h2 = gen_data_flow_ops._stack_v2(5, dtypes.float32, stack_name="foo") c1 = gen_data_flow_ops._stack_push_v2(h1, v1) with ops.control_dependencies([c1]): c2 = gen_data_flow_ops._stack_push_v2(h2, v2) with ops.control_dependencies([c2]): pop1 = gen_data_flow_ops._stack_pop_v2(h1, dtypes.float32) pop2 = gen_data_flow_ops._stack_pop_v2(h2, dtypes.float32) out1, out2 = sess.run([pop1, pop2], {v1: 4.0, v2: 5.0}) self.assertAllClose(out1, 4.0) self.assertAllClose(out2, 5.0)
def testStackPushPopSwap(self): with self.test_session(), self.test_scope(): a = np.arange(2000) x = array_ops.placeholder(dtypes.float32) h = gen_data_flow_ops._stack_v2(5, dtypes.float32, stack_name="foo") c = gen_data_flow_ops._stack_push_v2(h, x, swap_memory=True) with ops.control_dependencies([c]): c1 = gen_data_flow_ops._stack_pop_v2(h, dtypes.float32) self.assertAllClose(a, c1.eval({x: a}))
def testStackPushPop(self): with self.test_session(), self.test_scope(): size = array_ops.placeholder(dtypes.int32) v = array_ops.placeholder(dtypes.float32) h = gen_data_flow_ops._stack_v2(size, dtypes.float32, stack_name="foo") c = gen_data_flow_ops._stack_push_v2(h, v) with ops.control_dependencies([c]): c1 = gen_data_flow_ops._stack_pop_v2(h, dtypes.float32) self.assertAllClose([[4.0, 5.0]], c1.eval({size: 5, v: [[4.0, 5.0]]}))
def _testSameNameStacks(self, use_gpu): """Different stacks with the same name do not interfere.""" with self.test_session(use_gpu=use_gpu) as sess: h1 = gen_data_flow_ops._stack_v2( -1, elem_type=dtypes.float32, stack_name="foo") h2 = gen_data_flow_ops._stack_v2( -1, elem_type=dtypes.float32, stack_name="foo") c1 = gen_data_flow_ops._stack_push_v2(h1, 4.0) with ops.control_dependencies([c1]): c2 = gen_data_flow_ops._stack_push_v2(h2, 5.0) with ops.control_dependencies([c2]): pop1 = gen_data_flow_ops._stack_pop_v2(h1, dtypes.float32) pop2 = gen_data_flow_ops._stack_pop_v2(h2, dtypes.float32) out1, out2 = sess.run([pop1, pop2]) self.assertAllClose(out1, 4.0) self.assertAllClose(out2, 5.0)
def _testStackPushPop(self, use_gpu): with self.test_session(use_gpu=use_gpu): h = gen_data_flow_ops._stack_v2(-1, elem_type=dtypes.float32, stack_name="foo") c = gen_data_flow_ops._stack_push_v2(h, [[4.0, 5.0]]) with ops.control_dependencies([c]): c1 = gen_data_flow_ops._stack_pop_v2(h, dtypes.float32) self.assertAllClose([[4.0, 5.0]], c1.eval())
def _testPushCloseStack(self, use_gpu): with self.test_session(use_gpu=use_gpu) as sess: h = gen_data_flow_ops._stack_v2(-1, elem_type=dtypes.float32, stack_name="foo") c = gen_data_flow_ops._stack_push_v2(h, [[4.0, 5.0]]) with ops.control_dependencies([c]): c1 = gen_data_flow_ops._stack_close_v2(h) sess.run(c1)
def _testStackPushPopSwap(self, use_gpu): with self.test_session(use_gpu=use_gpu): a = np.arange(2000) x = constant_op.constant(a, dtype=dtypes.float32) h = gen_data_flow_ops._stack_v2( -1, elem_type=dtypes.float32, stack_name="foo") c = gen_data_flow_ops._stack_push_v2(h, x, swap_memory=True) with ops.control_dependencies([c]): c1 = gen_data_flow_ops._stack_pop_v2(h, dtypes.float32) self.assertAllClose(a, c1.eval())
def testPushCloseStack(self): with self.test_session() as sess, self.test_scope(): v = array_ops.placeholder(dtypes.float32) h = gen_data_flow_ops._stack_v2(5, dtypes.float32, stack_name="foo") c = gen_data_flow_ops._stack_push_v2(h, v) with ops.control_dependencies([c]): c1 = gen_data_flow_ops._stack_close_v2(h) sess.run(c1, {v: [[4.0, 5.0]]})
def testStackPushPopSwap(self): with self.test_session(), self.test_scope(): a = np.arange(2000) x = array_ops.placeholder(dtypes.float32) h = gen_data_flow_ops._stack_v2(5, dtypes.float32, stack_name="foo") c = gen_data_flow_ops._stack_push_v2(h, x, swap_memory=True) with ops.control_dependencies([c]): c1 = gen_data_flow_ops._stack_pop_v2(h, dtypes.float32) self.assertAllClose(a, c1.eval({x: a}))
def _testStackPushPopSwap(self, use_gpu): with self.test_session(use_gpu=use_gpu): a = np.arange(2000) x = constant_op.constant(a, dtype=dtypes.float32) h = gen_data_flow_ops._stack_v2(-1, elem_type=dtypes.float32, stack_name="foo") c = gen_data_flow_ops._stack_push_v2(h, x, swap_memory=True) with ops.control_dependencies([c]): c1 = gen_data_flow_ops._stack_pop_v2(h, dtypes.float32) self.assertAllClose(a, c1.eval())
def _testSameNameStacks(self, use_gpu): """Different stacks with the same name do not interfere.""" with self.test_session(use_gpu=use_gpu) as sess: h1 = gen_data_flow_ops._stack_v2(-1, elem_type=dtypes.float32, stack_name="foo") h2 = gen_data_flow_ops._stack_v2(-1, elem_type=dtypes.float32, stack_name="foo") c1 = gen_data_flow_ops._stack_push_v2(h1, 4.0) with ops.control_dependencies([c1]): c2 = gen_data_flow_ops._stack_push_v2(h2, 5.0) with ops.control_dependencies([c2]): pop1 = gen_data_flow_ops._stack_pop_v2(h1, dtypes.float32) pop2 = gen_data_flow_ops._stack_pop_v2(h2, dtypes.float32) out1, out2 = sess.run([pop1, pop2]) self.assertAllClose(out1, 4.0) self.assertAllClose(out2, 5.0)
def testSameNameStacks(self): """Different stacks with the same name do not interfere.""" with self.test_session() as sess, self.test_scope(): v1 = array_ops.placeholder(dtypes.float32) v2 = array_ops.placeholder(dtypes.float32) h1 = gen_data_flow_ops._stack_v2(5, dtypes.float32, stack_name="foo") h2 = gen_data_flow_ops._stack_v2(5, dtypes.float32, stack_name="foo") c1 = gen_data_flow_ops._stack_push_v2(h1, v1) with ops.control_dependencies([c1]): c2 = gen_data_flow_ops._stack_push_v2(h2, v2) with ops.control_dependencies([c2]): pop1 = gen_data_flow_ops._stack_pop_v2(h1, dtypes.float32) pop2 = gen_data_flow_ops._stack_pop_v2(h2, dtypes.float32) out1, out2 = sess.run([pop1, pop2], {v1: 4.0, v2: 5.0}) self.assertAllClose(out1, 4.0) self.assertAllClose(out2, 5.0)
def testStackPushPop(self): with self.test_session(), self.test_scope(): size = array_ops.placeholder(dtypes.int32) v = array_ops.placeholder(dtypes.float32) h = gen_data_flow_ops._stack_v2(size, dtypes.float32, stack_name="foo") c = gen_data_flow_ops._stack_push_v2(h, v) with ops.control_dependencies([c]): c1 = gen_data_flow_ops._stack_pop_v2(h, dtypes.float32) self.assertAllClose([[4.0, 5.0]], c1.eval({ size: 5, v: [[4.0, 5.0]] }))
def _testStackWhileSwap(self, use_gpu): with self.test_session(use_gpu=use_gpu): n = constant_op.constant(0) h = gen_data_flow_ops._stack_v2(-1, elem_type=dtypes.float32, stack_name="foo") def c(x): return math_ops.less(x, 10) def b(x): with ops.control_dependencies([x]): a = constant_op.constant(np.ones(2000), dtype=dtypes.float32) v = gen_data_flow_ops._stack_push_v2(h, a, swap_memory=True) with ops.control_dependencies([v]): return math_ops.add(x, 1) r = control_flow_ops.while_loop(c, b, [n]) v = constant_op.constant(np.zeros(2000), dtype=dtypes.float32) def c1(x, y): del y return math_ops.greater(x, 0) def b1(x, y): nx = math_ops.subtract(x, 1) ny = y + gen_data_flow_ops._stack_pop_v2(h, dtypes.float32) return [nx, ny] _, ry = control_flow_ops.while_loop( c1, b1, [r, v], [r.get_shape(), tensor_shape.unknown_shape()]) self.assertAllClose(np.ones(2000) * 10.0, ry.eval())
def testCloseStack(self): with self.test_session() as sess, self.test_scope(): size = array_ops.placeholder(dtypes.int32) h = gen_data_flow_ops._stack_v2(size, dtypes.float32, stack_name="foo") c1 = gen_data_flow_ops._stack_close_v2(h) sess.run(c1, {size: 5})
def _testCloseStack(self, use_gpu): with self.test_session(use_gpu=use_gpu) as sess: h = gen_data_flow_ops._stack_v2( -1, elem_type=dtypes.float32, stack_name="foo") c1 = gen_data_flow_ops._stack_close_v2(h) sess.run(c1)