import torch


def batchwise_outer(x1, x2):
    """Batchwise outer product between two 2D tensors.

    Takes two tensors of shape ``(batch_size, N)`` and returns the outer
    product of shape ``(batch_size, N, N)``.

    """
    return torch.matmul(x1[:, :, None], x2[:, None, :])