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

Method testReshape

tensorflow/compiler/tests/jit_test.py:283–308  ·  view source on GitHub ↗

Tests an operator with compile-time constant and non-constant inputs.

(self)

Source from the content-addressed store, hash-verified

281 """Tests for auto-compilation on CPU/GPU devices."""
282
283 def testReshape(self):
284 """Tests an operator with compile-time constant and non-constant inputs."""
285
286 with self.session(config=NoRewriteSessionConfig()) as sess:
287 x = array_ops.placeholder(dtypes.float32)
288 y = array_ops.placeholder(dtypes.int32)
289 with jit_scope():
290 # Reshape's first argument is non-constant in the JIT, but its second
291 # (shape) argument will be treated as a compile-time constant for
292 # each JIT compilation.
293 # We do not use a tf.const() argument since we want to ensure the
294 # shape is still a run-time argument to the JIT, and not
295 # statically known as part of the JIT compilation's input graph.
296 z = array_ops.reshape(x, y)
297 run_metadata = config_pb2.RunMetadata()
298 out = test_utils.RunWithWarmup(
299 sess,
300 z, {
301 x: np.array([1, 2, 3, 4, 5, 6], np.float32),
302 y: [-1, 3]
303 },
304 run_metadata=run_metadata,
305 options=config_pb2.RunOptions(
306 trace_level=config_pb2.RunOptions.FULL_TRACE))
307 self.assert_(MetadataHasXlaRunOp(run_metadata))
308 self.assertAllClose(np.array([[1, 2, 3], [4, 5, 6]], np.float32), out)
309
310 def testIgnoredArguments(self):
311 """Tests that JIT computations can ignore formal parameters."""

Callers

nothing calls this directly

Calls 7

NoRewriteSessionConfigFunction · 0.85
MetadataHasXlaRunOpFunction · 0.85
reshapeMethod · 0.80
RunMetadataMethod · 0.80
sessionMethod · 0.45
placeholderMethod · 0.45
assertAllCloseMethod · 0.45

Tested by

no test coverage detected