Adds the batch offsets to the given indices and returns the results.
| 619 | |
| 620 | // Adds the batch offsets to the given indices and returns the results. |
| 621 | Output 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 | |
| 649 | Output BatchGatherGrad(const Scope& scope, Output params_shape, Output values, |
| 650 | Output indices, int batch_dims, Output gather_dim_size) { |
no test coverage detected