As documentation says:
Replaces elements of this tensor with other in the lanes where mask is true .
DOC: Swift for TensorFlow
But using it it seems to replace values where mask is false:
import TensorFlow
typealias TF = Tensor<Float>
// Initialize random numbers
let rr = TF(randomNormal: [10,5])
print("rr = ",rr)
// Create a mask
let mask = rr.<(0-1.0)
print("mask = ", mask)
// Replaced
let replaced = rr.replacing(with: TF(0).broadcast(like: rr), where: mask)
print("replaced = ",replaced)
returns:
rr = [[ -0.2687458, 1.6474121, -0.061800487, -1.7457179, -0.3315584],
[ 1.3515772, 0.6790431, 0.14319876, 1.7425705, -1.9664636],
[ -0.32543635, 0.75455797, 0.9851794, -0.12352676, 0.029595692],
[ 0.54839504, -0.30570582, 1.7317035, 0.45856386, 0.8892455],
[ 0.14538142, -0.0019000744, -0.2195302, -0.3196175, -0.02673261],
[ -0.60845137, -0.36677366, 1.3494298, -1.3287013, -1.6256953],
[ 0.8583815, 1.1418674, -0.6815512, 1.0948774, 0.20448415],
[ -0.68553835, -0.9695941, -0.50244117, 1.037796, 0.70121026],
[ -0.5385072, 1.1612647, 1.7953675, 0.65119404, 1.5617983],
[ -1.237274, 1.0212688, -0.5734267, 0.91085374, 0.3272885]]
mask = [[false, false, false, true, false],
[false, false, false, false, true],
[false, false, false, false, false],
[false, false, false, false, false],
[false, false, false, false, false],
[false, false, false, true, true],
[false, false, false, false, false],
[false, false, false, false, false],
[false, false, false, false, false],
[ true, false, false, false, false]]
replaced = [[ 0.0, 0.0, 0.0, -1.7457179, 0.0],
[ 0.0, 0.0, 0.0, 0.0, -1.9664636],
[ 0.0, 0.0, 0.0, 0.0, 0.0],
[ 0.0, 0.0, 0.0, 0.0, 0.0],
[ 0.0, 0.0, 0.0, 0.0, 0.0],
[ 0.0, 0.0, 0.0, -1.3287013, -1.6256953],
[ 0.0, 0.0, 0.0, 0.0, 0.0],
[ 0.0, 0.0, 0.0, 0.0, 0.0],
[ 0.0, 0.0, 0.0, 0.0, 0.0],
[ -1.237274, 0.0, 0.0, 0.0, 0.0]]
THE API I WOULD LIKE
rr[mask] = TF(123)
// or inline
rr[rr.<(0-1.0)] = TF(123)
Probably a new TensorRange case is needed for that…