Helper function for unsorted segment ops. Returns a mask of where 'ids' are positive, reshaped so that it will be broadcastable to the result shape of gathering params by ids.
| 1260 | // Returns a mask of where 'ids' are positive, reshaped so that it will be |
| 1261 | // broadcastable to the result shape of gathering params by ids. |
| 1262 | Output GetIsPositive(const Scope& scope, const Output& params, |
| 1263 | const Output& ids) { |
| 1264 | Output is_positive = GreaterEqual(scope, ids, ZerosLike(scope, ids)); |
| 1265 | // tf.where(condition, x, y) requires condition to have the same shape as x |
| 1266 | // and y. |
| 1267 | Output is_positive_shape = Shape(scope, is_positive); |
| 1268 | Output ones = |
| 1269 | Tile(scope, Const(scope, {1}), Subtract(scope, Rank(scope, params), {1})); |
| 1270 | auto broadcastable_shape = Concat(scope, {is_positive_shape, ones}, |
| 1271 | /*axis=*/0); |
| 1272 | is_positive = Reshape(scope, is_positive, broadcastable_shape); |
| 1273 | is_positive = LogicalAnd(scope, is_positive, OnesLike(scope, is_positive)); |
| 1274 | return is_positive; |
| 1275 | } |
| 1276 | |
| 1277 | // Helper function for unsorted segment ops. |
| 1278 | // Gathers params for positive segment ids and gathers 0 for inputs with |