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)
| 50 | |
| 51 | |
| 52 | def 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 | |
| 71 | def infer_dependency(op): |