Class AxisError
- Namespace
- NumSharp
- Assembly
- NumSharp.dll
NumPy-compatible AxisError exception. Raised when an axis argument is out of bounds for the array's dimensions.
public class AxisError : ArgumentOutOfRangeException, ISerializable, INumSharpException
- Inheritance
-
AxisError
- Implements
- Inherited Members
Remarks
Mirrors numpy.exceptions.AxisError. Its text is NumPy's AxisError.__str__:
"axis {axis} is out of bounds for array of dimension {ndim}", preceded by "{msg_prefix}: " when
the raising function names the argument (np.moveaxis's source / destination,
np.swapaxes' axis1 / axis2, np.cross' axisa, np.average's
axis). NumPy raises it from normalize_axis_index (C: check_and_adjust_axis_msg), so every
NumSharp function that normalizes an axis raises it through
check_and_adjust_axis(int, int, string).
It derives from ArgumentOutOfRangeException, so a handler written for
ArgumentOutOfRangeException or ArgumentException still catches it. The .NET base
appends " (Parameter '…')" and an "Actual value was …" line to Message;
NumPy's text is the part before them. The axis reaches that line as invariant TEXT
(ActualValue is the string "-3", Axis the
number): the base formats a number with the current culture, which made the line read -3 under ar-SA
and −3 under sv-SE (parity QA-41).
Constructors
AxisError()
An AxisError with no text: an empty Message (the parameterless form .NET
serialization and reflection expect; Python's AxisError requires an axis, and its other errors'
bare form reads '').
public AxisError()
Remarks
Not .NET's ArgumentOutOfRangeException default, "Specified argument was out of the range of valid values.", which no NumPy error prints.
AxisError(int, int)
NumPy's AxisError(axis, ndim): "axis {axis} is out of bounds for array of dimension {ndim}".
public AxisError(int axis, int ndim)
Parameters
AxisError(int, int, string)
NumPy's AxisError(axis, ndim, msg_prefix): the out-of-bounds text preceded by
"{msgPrefix}: ", as NumPy raises it for a named argument.
public AxisError(int axis, int ndim, string msgPrefix)
Parameters
axisintThe axis as the caller gave it.
ndimintThe rank it was checked against.
msgPrefixstringThe argument name NumPy puts in front of the text (
"source","axis1"), ornullfor none. It is also the exception's ParamName ("axis"without a prefix).
Remarks
An empty prefix is not the same as none: NumPy tests msg_prefix is not None, so "" gives
": axis 5 is …", which this constructor reproduces.
AxisError(string)
NumPy's message-only AxisError(msg) (for example np.rollaxis' "'start' arg requires … but … was
passed in"): the text is message verbatim.
public AxisError(string message)
Parameters
messagestringThe whole text.
AxisError(string, Exception)
NumPy's message-only AxisError(msg) with the exception that caused it (Python's raise AxisError(msg)
from innerException): the text is message verbatim and Axis /
NDim are 0.
public AxisError(string message, Exception innerException)
Parameters
messagestringThe whole text.
innerExceptionExceptionThe exception that led to this one, or null for none.
Remarks
Footgun: unlike AxisError(string), Message carries no
" (Parameter 'axis')" suffix and ParamName is null, because the
.NET base has no constructor that takes a parameter name together with an inner exception. The text is then
NumPy's alone.
Properties
Axis
The axis as the caller gave it (negative values are not wrapped); 0 for a message-only error.
public int Axis { get; }
Property Value
NDim
The rank the axis was checked against; 0 for a message-only error.
public int NDim { get; }