feature_mask#

bayesflow.utils.feature_mask(mask: Tensor | None, x: Tensor) Tensor | None[source]#

Convert a feature mask to shape (batch, features, 1).

Parameters:
maskTensor or None

A binary feature mask. Supports unbatched masks of shape (features,), batched masks of shape (batch, features), and masks with a trailing singleton or feature axis.

xTensor

Reference tensor whose dtype and rank determine the returned mask shape.

Returns:
Tensor or None

The mask cast to x.dtype and expanded to (batch, features, 1), or None if no mask is passed.