diff --git a/python/paddle/fluid/layers/tensor.py b/python/paddle/fluid/layers/tensor.py index da066c34bdeba1f1b76f8d1cafd9244b2f7708fa..3ce0adbb77c6fabd7e4b8421be7b9281b46c5eb3 100644 --- a/python/paddle/fluid/layers/tensor.py +++ b/python/paddle/fluid/layers/tensor.py @@ -32,6 +32,7 @@ __all__ = [ 'fill_constant', 'ones', 'zeros', + 'scatter', ] @@ -364,6 +365,27 @@ def zeros(shape, dtype, force_cpu=False): return fill_constant(value=0.0, **locals()) +def scatter(input, index, updates): + """ + Scatter input through the index + Out[Index] = Ref[Index] + Updates + + Args: + input(variable): The Tensor/LoDTensor to be scatterd. + index(variable): The index input of scatter op where Ref will be updated. + updates(variable): The updated value to be added to the output. + """ + helper = LayerHelper("scatter", **locals()) + out = helper.create_tmp_variable(dtype=dtype) + helper.append_op( + type='scatter', + inputs={'Ref': input, + 'Index': index, + 'Updates': updates}, + outputs={'Out': [out]}) + return out + + def save(x, file_path, overwrite=True): """ Saves a variable as a file.