batch_size = 3
input_size = 4
expected_state_c = np.array(
- [[6.450831e-04, 4.697885e-04], [9.862894e-05, 7.212213e-04],
- [4.401947e-04, 9.143004e-04]],
+ [[0.00072015, 0.00036633], [0.00083481, 0.00047266],
+ [0.00085111, 0.00053054]],
dtype=np.float32)
expected_state_h = np.array(
- [[4.621217e-04, 3.365449e-04], [7.438179e-05, 5.439147e-04],
- [3.347936e-04, 6.953785e-04]],
+ [[0.0005159, 0.00026243], [0.00062958, 0.00035646],
+ [0.00064732, 0.00040351]],
dtype=np.float32)
with variable_scope.variable_scope(
"root", initializer=init_ops.constant_initializer(0.5)):
# pylint: enable=invalid-name
+def _constant_if_small(value, shape, dtype, name):
+ try:
+ if np.prod(shape) < 1000:
+ return constant(value, shape=shape, dtype=dtype, name=name)
+ except TypeError:
+ # Happens when shape is a Tensor, list with Tensor elements, etc.
+ pass
+ return None
+
+
@tf_export("zeros")
def zeros(shape, dtype=dtypes.float32, name=None):
"""Creates a tensor with all elements set to zero.
zero = ""
else:
zero = 0
+
if not isinstance(shape, ops.Tensor):
try:
+ # Create a constant if it won't be very big. Otherwise create a fill op
+ # to prevent serialized GraphDefs from becoming too large.
+ output = _constant_if_small(zero, shape, dtype, name)
+ if output is not None:
+ return output
+
# Go through tensor shapes to get int64-if-needed semantics
shape = constant_op._tensor_shape_tensor_conversion_function(
tensor_shape.TensorShape(shape))
one = True if dtype == dtypes.bool else 1
if not isinstance(shape, ops.Tensor):
try:
+ # Create a constant if it won't be very big. Otherwise create a fill op
+ # to prevent serialized GraphDefs from becoming too large.
+ output = _constant_if_small(one, shape, dtype, name)
+ if output is not None:
+ return output
+
# Go through tensor shapes to get int64-if-needed semantics
shape = constant_op._tensor_shape_tensor_conversion_function(
tensor_shape.TensorShape(shape))