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

Method construct_dx

python/singa/autograd.py:4490–4506  ·  view source on GitHub ↗
(dy, axis, indices, _shape)

Source from the content-addressed store, hash-verified

4488 _shape = self.x_shape[self.axis]
4489
4490 def construct_dx(dy, axis, indices, _shape):
4491 dys = []
4492 data_idx = 0
4493 data_idxes = tuple(indices)
4494 for step_idx in range(_shape):
4495 if step_idx in data_idxes:
4496 tmp_tensor = singa.SliceOn(dy, data_idx, data_idx + 1, axis)
4497 data_idx += 1
4498 else:
4499 tmp_shape = list(dy.shape())
4500 tmp_shape[axis] = 1
4501 tmp_tensor = singa.Tensor(tmp_shape, dy.device())
4502 tmp_tensor.SetFloatValue(0.)
4503 dys.append(tmp_tensor)
4504 dys = singa.VecTensor(dys)
4505 dy = singa.ConcatOn(dys, axis)
4506 return dy
4507
4508 if isinstance(self.indices[0], tuple) or isinstance(
4509 self.indices[0], list):

Callers

nothing calls this directly

Calls 5

shapeMethod · 0.80
TensorMethod · 0.80
deviceMethod · 0.80
appendMethod · 0.80
tupleFunction · 0.50

Tested by

no test coverage detected