Skip to main content

parse_fold_axis

Function parse_fold_axis 

Source
pub fn parse_fold_axis(axis: &str) -> Result<Vec<i64>, String>
Expand description

Port of CLI/Utils.py::parse_fold_axis.

Translates a 1-indexed --axis value to 0-indexed axes:

  • "1" / "1-2" / "1,3" → rangeset axes, x - 1 for each x > 0 (axis 0 is ignored, like upstream).
  • "-1" → negative axis index (only a single number supported), resolved modulo the dimension count at fold time.

Returns the raw axis list; callers treat an empty list like Python’s empty tuple assigned to DEFAULTS.fold_axis (falsy → fold along all axes).

§Errors

Returns a RangeSet parse error string for malformed rangeset input, or an invalid literal style error for malformed negative input, mirroring the upstream RangeSetParseError / ValueError split.