async function booleanMaskAsync_(tensor, mask, axis) {
    const $tensor = (0, _tensorUtilEnv.convertToTensor)(tensor, "tensor", "boolMask");
    const $mask = (0, _tensorUtilEnv.convertToTensor)(mask, "mask", "boolMask", "bool");
    const axisFrom = axis == null ? 0 : axis;
    const maskDim = $mask.rank;
    const tensorShape = $tensor.shape;
    _util.assert(maskDim > 0, ()=>"mask cannot be scalar");
    _util.assertShapesMatch(tensorShape.slice(axisFrom, axisFrom + maskDim), $mask.shape, `mask's shape must match the first K dimensions of tensor's shape,`);
    let leadingSize = 1;
    for(let i = axisFrom; i < axisFrom + maskDim; i++)leadingSize *= tensorShape[i];
    const targetTensorShape = tensorShape.slice(0, axisFrom).concat([
        leadingSize
    ], tensorShape.slice(axisFrom + maskDim));
    const reshapedTensor = (0, _reshape.reshape)($tensor, targetTensorShape);
    const reshapedMask = (0, _reshape.reshape)($mask, [
        -1
    ]);
    const positivePositions = await (0, _whereAsync.whereAsync)(reshapedMask);
    const indices = (0, _squeeze.squeeze)(positivePositions, [
        1
    ]);
    const res = (0, _gather.gather)(reshapedTensor, indices, axisFrom);
    // Ensure no memory leak.
    if (tensor !== $tensor) $tensor.dispose();
    if (mask !== $mask) $mask.dispose();
    indices.dispose();
    reshapedTensor.dispose();
    reshapedMask.dispose();
    positivePositions.dispose();
    return res;
}
Apply boolean mask to tensor.

```js
const tensor = tf.tensor2d([1, 2, 3, 4, 5, 6], [3, 2]);
const mask = tf.tensor1d([1, 0, 1], 'bool');
const result = await tf.booleanMaskAsync(tensor, mask);
result.print();
```

@param tensor N-D tensor.
@param mask K-D boolean tensor, K <= N and K must be known statically.
@param axis A 0-D int Tensor representing the axis in tensor to mask from.
    By default, axis is 0 which will mask from the first dimension.
    Otherwise K + axis <= N.

@doc {heading: 'Tensors', subheading: 'Slicing and Joining'}