MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / GetBatchIndices

Function GetBatchIndices

tensorflow/cc/gradients/array_grad.cc:621–647  ·  view source on GitHub ↗

Adds the batch offsets to the given indices and returns the results.

Source from the content-addressed store, hash-verified

619
620// Adds the batch offsets to the given indices and returns the results.
621Output GetBatchIndices(const Scope& scope, const Output& params_shape,
622 const Output& indices, int batch_dims) {
623 Output batch_indices = indices;
624 auto indices_ndims = Rank(scope, indices);
625 auto casted_params_shape = Cast(scope, params_shape, indices.type());
626 Output accum_dim_value = ConstHelper(scope, 1, indices.type());
627 for (int dim = batch_dims; dim > 0; dim--) {
628 Output dim_value = Slice(scope, casted_params_shape, {dim - 1}, {1});
629 accum_dim_value = Multiply(scope, accum_dim_value,
630 Slice(scope, casted_params_shape, {dim}, {1}));
631 auto start = ConstHelper(scope, 0, indices.type());
632 auto step = ConstHelper(scope, 1, indices.type());
633 Output dim_indices = Range(scope, start, Squeeze(scope, dim_value), step);
634 dim_indices = Multiply(scope, dim_indices, accum_dim_value);
635 auto one = Cast(scope, Const(scope, {1}), indices.type());
636 auto dim_shape = Concat(
637 scope,
638 {Output(Tile(scope, one, Const(scope, {dim - 1}))), dim_value,
639 Output(Tile(scope, one,
640 ExpandDims(scope, Sub(scope, indices_ndims, dim), 0)))},
641 /*axis=*/0);
642 batch_indices =
643 Add(scope, batch_indices, Reshape(scope, dim_indices, dim_shape));
644 }
645
646 return batch_indices;
647}
648
649Output BatchGatherGrad(const Scope& scope, Output params_shape, Output values,
650 Output indices, int batch_dims, Output gather_dim_size) {

Callers 1

BatchGatherGradFunction · 0.85

Calls 15

ConstHelperFunction · 0.70
typeMethod · 0.65
RankFunction · 0.50
CastFunction · 0.50
SliceClass · 0.50
MultiplyClass · 0.50
RangeClass · 0.50
SqueezeFunction · 0.50
ConstFunction · 0.50
ConcatFunction · 0.50
OutputClass · 0.50
TileClass · 0.50

Tested by

no test coverage detected