Class UFuncTypeError
- Namespace
- NumSharp
- Assembly
- NumSharp.dll
NumPy's numpy._core._exceptions.UFuncTypeError: the base of the errors a ufunc raises when it cannot run
for its operands' dtypes — no loop for them (UFuncNoLoopError), two operands it cannot combine
(UFuncBinaryResolutionError), or a cast its casting= rule forbids
(UFuncInputCastingError, UFuncOutputCastingError).
public class UFuncTypeError : TypeError, ISerializable, INumSharpException
- Inheritance
-
UFuncTypeError
- Implements
- Derived
- Inherited Members
Remarks
A subclass of TypeError, as NumPy's is, so catch (TypeError) catches every ufunc refusal
(NumPy advises catching TypeError or UFuncTypeError: its subclasses are private and its traceback
shows each as UFuncTypeError). NumSharp names the subclasses without NumPy's leading underscore, since
a C# class cannot hide behind _display_as_base; footgun: an MSTest Assert.ThrowsException<TypeError>
(an exact-type check) no longer matches a ufunc refusal, which now throws the subclass.
ufunc is the ufunc's NAME (add): NumSharp has no ufunc objects, and NumPy's errors only ever
print the name. A dtype-like value (dtypes, from_,
to) is a DType instance (printed dtype('float64')), a
DTypeMeta class (printed <class 'numpy.dtypes.StrDType'>) or null (None), as
NumPy's resolver hands them over; where NumPy names its object dtype, which NumSharp has no descriptor for, it is
a placeholder whose ToString() is NumPy's text.
Every class of the family also takes .NET's standard (message, innerException), which keeps the message
verbatim and leaves the attributes empty (null, no dtypes, index 0): for code that wraps a failure in NumPy's
class without a ufunc at hand. NumSharp's own raise sites always use NumPy's arguments.
Constructors
UFuncTypeError(string)
NumPy's UFuncTypeError(ufunc): the message is the ufunc's str(), <ufunc 'add'>
(NumPy's base class prints its lone argument).
public UFuncTypeError(string ufunc)
Parameters
ufuncstringThe ufunc's name.
Remarks
Footgun: the lone string is the ufunc's NAME, not a message (new UFuncTypeError("add") reads
<ufunc 'add'>), while the two-argument UFuncTypeError(string, Exception) takes a
message.
Exceptions
- ArgumentNullException
ufuncis null.
UFuncTypeError(string, Exception)
Creates the error from a message and the exception that caused it, .NET's standard constructor every NumSharp exception has: the message is kept verbatim and ufunc is null.
public UFuncTypeError(string message, Exception innerException)
Parameters
messagestringThe verbatim message.
innerExceptionExceptionThe exception that led to this one, or null for none.
Remarks
Python has no such constructor (NumPy's UFuncTypeError takes the ufunc alone). Footgun: here the
string is the MESSAGE, while the one-argument UFuncTypeError(string) takes the ufunc's name;
new UFuncTypeError("add", null) reads add.
UFuncTypeError(string, string)
The subclasses' form: the ufunc and the subclass's own text (NumPy's subclasses override str).
protected UFuncTypeError(string ufunc, string message)
Parameters
Exceptions
- ArgumentNullException
ufuncis null.
Properties
ufunc
The ufunc's name (NumPy's ufunc attribute holds the ufunc object; NumSharp, which has none, keeps its
name: add, str_len, modf). Null when the error was built from a message alone
(UFuncTypeError(string, Exception) and its subclasses' twins).
public string ufunc { get; }