Will this inplace assignment propagate gradient correctly?

Hello,

In my code I need to do something like this

. . . 
# a (n_a, n_features)
# b (n_b, n_features)
# some_indices (n_a,) long

result = b.clone()
result[some_indices, :] = a
return result

Will this propagate gradients correctly for a and b ?
(ie the gradient of result for some_indices propagated to a, and for all the other indices, they are propagated to b)
I am a bit scared of the inplace operation, I couldn’t find explanations of where they’re safe or not for the autograd engine.

Usually I would use a torch.where, but a doesn’t have the same shape as b, so that would require me to get a to that same size, which would also require an assignment…

Thank you for the help

I would expect to see a RuntimeError if the inplace operation is disallowed and would result in wrong gradient calculations. If you are not seeing such an error in your code it should be fine.

Oh so if there is no error, I can expect the gradients to be correct? That is great!
Thanks!