Is there an out-of-place equivalent to boolean indexing assignment?

Is there an out-of-place equivalent to boolean indexing assignment A[M] = B?

For example:

import torch

A = torch.arange(10)
M = A % 2 == 0
B = torch.full_like(A, 10)[M]

# Can I do this out of place?
A[M] = B

# is there a function like C = foo(A, M, B)
# note that A and B don't have the same shape, so I can't use torch.where