File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed
Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -965,13 +965,15 @@ class Variable {
965965
966966 for (size_t idx = 0 ; idx < labels.size (); ++idx) {
967967 if (labels[idx] == desc.label ) {
968- // Clamp the descriptor to the domain.
969- return {desc.label , // label
970- desc.start < domain.origin ()[idx] ? domain.origin ()[idx]
971- : desc.start , // start
972- desc.stop > domain.shape ()[idx] ? domain.shape ()[idx]
973- : desc.stop , // stop
974- desc.step }; // step
968+ // Clamp the descriptor to the domain using absolute coordinates.
969+ // NOTE: domain.shape()[idx] is a size, not an absolute upper bound when
970+ // the origin is non-zero. The correct exclusive upper bound is
971+ // origin + shape.
972+ Index dim_origin = domain.origin ()[idx];
973+ Index dim_upper = dim_origin + domain.shape ()[idx]; // exclusive
974+ Index clamped_start = desc.start < dim_origin ? dim_origin : desc.start ;
975+ Index clamped_stop = desc.stop > dim_upper ? dim_upper : desc.stop ;
976+ return {desc.label , clamped_start, clamped_stop, desc.step };
975977 }
976978 }
977979 // We don't slice along a dimension that doesn't exist, so the descriptor is
You can’t perform that action at this time.
0 commit comments