MCPcopy
hub / github.com/dmlc/dgl / _scatter_add

Function _scatter_add

python/dgl/_sparse_ops.py:694–720  ·  view source on GitHub ↗

r"""Scatter add operator (on first dimension) implementation. Math: y[idx[i], *] += x[i, *] Parameters ---------- x : Tensor The input feature. idx : Tensor The indices array. m : int The length of output. Returns ------- Tensor

(x, idx, m)

Source from the content-addressed store, hash-verified

692
693
694def _scatter_add(x, idx, m):
695 r"""Scatter add operator (on first dimension) implementation.
696
697 Math: y[idx[i], *] += x[i, *]
698
699 Parameters
700 ----------
701 x : Tensor
702 The input feature.
703 idx : Tensor
704 The indices array.
705 m : int
706 The length of output.
707
708 Returns
709 -------
710 Tensor
711 The output tensor.
712 """
713 out_shp = (m,) + F.shape(x)[1:]
714 ctx = F.context(x)
715 dtype = F.dtype(x)
716 out = F.zeros(out_shp, dtype, ctx)
717 _CAPI_DGLKernelScatterAdd(
718 to_dgl_nd(x), to_dgl_nd(idx), to_dgl_nd_for_write(out)
719 )
720 return out
721
722
723def _update_grad_minmax_hetero(

Callers 3

forwardMethod · 0.50
scatter_add_realFunction · 0.50
forwardMethod · 0.50

Calls 5

to_dgl_nd_for_writeFunction · 0.85
contextMethod · 0.80
to_dgl_ndFunction · 0.70
shapeMethod · 0.45
dtypeMethod · 0.45

Tested by

no test coverage detected