From 8ba23b88d66f5d2ee85d47fba114abccb383b8c3 Mon Sep 17 00:00:00 2001 From: holl- Date: Tue, 16 Jan 2024 14:59:19 +0100 Subject: [PATCH] Improved gather error message --- phiml/math/_ops.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phiml/math/_ops.py b/phiml/math/_ops.py index ab1e152d..49bfc4cd 100644 --- a/phiml/math/_ops.py +++ b/phiml/math/_ops.py @@ -2429,6 +2429,8 @@ def gather(values, indices: Tensor, dims: Union[DimFilter, None] = None): assert dims, f"No indexing dimensions for tensor {values.shape} given indices {indices.shape}" if dims not in values.shape: return expand(values, non_channel(indices)) + assert channel(indices).rank == 1, f"indices must have a single channel dimension listing the indexed dims {dims} but got {indices.shape}." + assert channel(indices).volume == len(dims), f"channel dimension of indices must have size equal to the number of indexed dims {dims} but got {channel(indices)}" if values._is_tracer or is_sparse(values): if not channel(indices): indices = expand(indices, channel(gather=dims))