MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _testOneThreadHelper

Method _testOneThreadHelper

tensorflow/python/training/input_test.py:464–514  ·  view source on GitHub ↗
(self, use_dict)

Source from the content-addressed store, hash-verified

462class BatchTest(test_lib.TestCase):
463
464 def _testOneThreadHelper(self, use_dict):
465 with self.cached_session() as sess:
466 batch_size = 10
467 num_batches = 3
468 zero64 = constant_op.constant(0, dtype=dtypes.int64)
469 examples = variables.Variable(zero64)
470 counter = examples.count_up_to(num_batches * batch_size)
471 sparse_counter = sparse_tensor.SparseTensor(
472 indices=array_ops.reshape(
473 array_ops.stack([zero64, zero64 + 1]), [2, 1]),
474 values=math_ops.cast(
475 array_ops.stack([counter, -counter]), dtypes.float32),
476 dense_shape=[2])
477 if use_dict:
478 batched = inp.batch(
479 {
480 "c": counter,
481 "s": sparse_counter,
482 "S": "string"
483 },
484 batch_size=batch_size)
485 batched_fetch = [batched["c"], batched["s"], batched["S"]]
486 else:
487 batched = inp.batch(
488 [counter, sparse_counter, "string"], batch_size=batch_size)
489 batched_fetch = batched
490 self.evaluate(variables.global_variables_initializer())
491 variables.local_variables_initializer().run()
492 threads = queue_runner_impl.start_queue_runners()
493
494 for i in range(num_batches):
495 results = self.evaluate(batched_fetch)
496 self.assertAllEqual(results[0],
497 np.arange(i * batch_size, (i + 1) * batch_size))
498 self.assertAllEqual(
499 results[1].indices,
500 np.vstack((
501 np.arange(2 * batch_size) // 2, # 0, 0, 1, 1, ...
502 [0, 1] * batch_size)).T)
503 # [x, -x, x+1, -(x+1), ...]
504 expected = np.arange(2 * i * batch_size, 2 * (i + 1) * batch_size) // 2
505 expected *= ([1, -1] * batch_size) # mult by [1, -1, 1, -1, ...]
506 self.assertAllEqual(results[1].values, expected)
507 self.assertAllEqual(results[1].dense_shape, [batch_size, 2])
508 self.assertAllEqual(results[2], [b"string"] * batch_size)
509
510 # Reached the limit.
511 with self.assertRaises(errors_impl.OutOfRangeError):
512 self.evaluate(batched_fetch)
513 for thread in threads:
514 thread.join()
515
516 @test_util.run_deprecated_v1
517 def testOneThread(self):

Callers 2

testOneThreadMethod · 0.95
testOneThreadDictMethod · 0.95

Calls 14

count_up_toMethod · 0.95
VariableMethod · 0.80
reshapeMethod · 0.80
rangeFunction · 0.50
cached_sessionMethod · 0.45
constantMethod · 0.45
stackMethod · 0.45
castMethod · 0.45
batchMethod · 0.45
evaluateMethod · 0.45
runMethod · 0.45
start_queue_runnersMethod · 0.45

Tested by

no test coverage detected