Every line of 'tensorflow reduce_sum' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
176 def reduce_sum(input_tensor, axis=None, keep_dims=False, name=None, reduction_indices=None): 177 tf.reduce_sum(input_tensor, axis, keep_dims, name, reduction_indices)
614 def sum(self, x: BKTensor, *args: Any, **kwargs: Any) -> BKTensor: 615 return self.tf.reduce_sum(x, *args, **kwargs)
557 def sum(x, axis=None, keepdims=False): 558 """Sum of the values in a tensor, alongside the specified axis. 559 """ 560 return T.sum(x, axis=axis, keepdims=keepdims)
37 @ops.RegisterGradient("Sum") 38 def _SumGrad(op, grad): 39 """Gradient for Sum.""" 40 # Fast path for when reducing to a scalar and ndims is known: adds only 41 # Reshape and Tile ops (and possibly a Shape). 42 if (op.inputs[0].get_shape().ndims is not None and 43 op.inputs[1].op.type == "Const"): 44 rank = op.inputs[0].get_shape().ndims 45 axes = tensor_util.MakeNdarray(op.inputs[1].op.get_attr("value")) 46 if np.array_equal(axes, np.arange(rank)): # Reduce all dims. 47 grad = array_ops.reshape(grad, [1] * rank) 48 # If shape is not fully defined (but rank is), we use Shape. 49 if op.inputs[0].get_shape().is_fully_defined(): 50 input_shape = op.inputs[0].get_shape().as_list() 51 else: 52 input_shape = array_ops.shape(op.inputs[0]) 53 return [array_ops.tile(grad, input_shape), None] 54 55 input_shape = array_ops.shape(op.inputs[0]) 56 output_shape_kept_dims = math_ops.reduced_shape(input_shape, op.inputs[1]) 57 tile_scaling = _safe_shape_div(input_shape, output_shape_kept_dims) 58 grad = array_ops.reshape(grad, output_shape_kept_dims) 59 return [array_ops.tile(grad, tile_scaling), None]