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

Function zeros_like_impl

tensorflow/python/ops/array_ops.py:2426–2454  ·  view source on GitHub ↗

Internal implementation for the v1/v2 zeros_like API calls.

(tensor, dtype, name, optimize=True)

Source from the content-addressed store, hash-verified

2424
2425
2426def zeros_like_impl(tensor, dtype, name, optimize=True):
2427 """Internal implementation for the v1/v2 zeros_like API calls."""
2428 with ops.name_scope(name, "zeros_like", [tensor]) as name:
2429 if not tensor_util.is_tensor(tensor):
2430 tensor = ops.convert_to_tensor(tensor, name="tensor")
2431 tensor_shape = tensor.shape
2432 tensor_dtype = tensor.dtype
2433
2434 if context.executing_eagerly():
2435 if dtype is not None and dtype != tensor_dtype:
2436 return zeros(
2437 shape_internal(tensor, optimize=optimize), dtype=dtype, name=name)
2438 with ops.device(tensor.device):
2439 return gen_array_ops.zeros_like(tensor, name=name)
2440
2441 # For now, variant types must be created via zeros_like; as we need to
2442 # pass the input variant object to the proper zeros callback.
2443
2444 if (optimize and tensor_shape.is_fully_defined() and
2445 tensor_dtype != dtypes.variant):
2446 # We can produce a zeros tensor independent of the value of 'tensor',
2447 # since the shape is known statically.
2448 return zeros(tensor_shape, dtype=dtype or tensor_dtype, name=name)
2449
2450 if dtype is not None and dtype != tensor_dtype and dtype != dtypes.variant:
2451 return zeros(
2452 shape_internal(tensor, optimize=optimize), dtype=dtype, name=name)
2453 else:
2454 return gen_array_ops.zeros_like(tensor, name=name)
2455
2456
2457@tf_export(v1=["ones_like"])

Callers 2

zeros_likeFunction · 0.85
zeros_like_v2Function · 0.85

Calls 7

shape_internalFunction · 0.85
is_tensorMethod · 0.80
executing_eagerlyMethod · 0.80
is_fully_definedMethod · 0.80
zerosFunction · 0.70
name_scopeMethod · 0.45
deviceMethod · 0.45

Tested by

no test coverage detected