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

Function back_broadcast

python/singa/autograd.py:52–68  ·  view source on GitHub ↗

for a brodcasted tensor, restore its shape of x from y_shape to x_shape Args: y_shape: the shape of result x_shape: the shape of x x: the input Return: a tensor

(y_shape, x_shape, x)

Source from the content-addressed store, hash-verified

50
51
52def back_broadcast(y_shape, x_shape, x):
53 """
54 for a brodcasted tensor, restore its shape of x from y_shape to x_shape
55 Args:
56 y_shape: the shape of result
57 x_shape: the shape of x
58 x: the input
59 Return:
60 a tensor
61 """
62 if y_shape != x_shape:
63 x = tensor.from_raw_tensor(x)
64 axis = axis_helper(y_shape, x_shape)
65 x = tensor.sum(x, axis)
66 x = tensor.reshape(x, x_shape)
67 x = x.data
68 return x
69
70
71def infer_dependency(op):

Callers 7

backwardMethod · 0.85
backwardMethod · 0.85
backwardMethod · 0.85
backwardMethod · 0.85
backwardMethod · 0.85
backwardMethod · 0.85
backwardMethod · 0.85

Calls 2

axis_helperFunction · 0.70
reshapeMethod · 0.45

Tested by

no test coverage detected