MCPcopy Create free account
hub / github.com/apache/singa / forward

Method forward

python/singa/autograd.py:4097–4123  ·  view source on GitHub ↗

forward of ReduceMean Args: x (CTensor): input tensor. Returns: the output CTensor.

(self, x)

Source from the content-addressed store, hash-verified

4095 self.keepdims = keepdims
4096
4097 def forward(self, x):
4098 """
4099 forward of ReduceMean
4100 Args:
4101 x (CTensor): input tensor.
4102 Returns:
4103 the output CTensor.
4104 """
4105 _x = tensor.from_raw_tensor(x)
4106 x_shape = list(_x.shape)
4107 # handle the special axes
4108 if self.axes is None:
4109 self.axes = [i for i in range(len(x_shape))] # axes = None
4110 else:
4111 self.axes = [i if i >= 0 else len(x_shape) + i for i in self.axes
4112 ] # axes has negative
4113 self.axes.sort(reverse=True)
4114 for axis in self.axes:
4115 _x = tensor.sum(_x, axis)
4116 x_shape[axis] = 1
4117 if self.keepdims == 1:
4118 _x = tensor.reshape(_x, x_shape)
4119 self.cache = (x_shape, x)
4120 scale = np.prod(x_shape) / np.prod(x.shape())
4121 self.scale = scale
4122 _x = singa.MultFloat(_x.data, scale)
4123 return _x
4124
4125 def backward(self, dy):
4126 """

Callers

nothing calls this directly

Calls 2

shapeMethod · 0.80
reshapeMethod · 0.45

Tested by

no test coverage detected