Table of Contents

Class Converts

Namespace
NumSharp.Utilities
Assembly
NumSharp.dll

Provides various methods related to Convert.

[SuppressMessage("ReSharper", "MergeConditionalExpression")]
[SuppressMessage("ReSharper", "JoinDeclarationAndInitializer")]
public static class Converts
Inheritance
Converts
Inherited Members

Remarks

Number → text is the NumPy scalar's str() — the text astype('U') writes for the element (NumSharp.Backends.Strings.NDTextFormat): 1.0 → '1.0', 1e20 → '1e+20', NaN → 'nan', a float32 or float16 value with its own shortest digits (np.float32(0.1) → '0.1'), a complex value as '(1+2j)', a bool as 'True' / 'False'. NumSharp's two dtypes without a NumPy analog follow their documented text rules: a decimal is written as the float64 it converts to, and a char (NumSharp's 16-bit code unit, a uint16 in every type rule) as its number ('a' → '97'), as np.array(new[] { 'a' }).astype("U") gives.

Text → number is NumPy's store of a Python str into the dtype (a[0] = '1.5'): CPython 3.12's int() / float() / complex() grammar (whitespace, underscores between digits, non-ASCII decimal digits, inf / nan in any case), NumPy's packing check for an integer target, and NumPy's error texts quoting the str (ParseObject(string, NPTypeCode, byte*)). A bool target takes the str's truth value (any non-empty str is True — 'False' included — as NumPy 2.x's str → bool cast and BOOL_setitem give).

Both directions are culture-invariant: NumPy's text has no culture. These replace the .NET forms the class carried before (double.ToString(CultureInfo.CurrentCulture), int.Parse(s, CurrentCulture)), whose result depended on the machine's culture (under de-DE "1.5" parsed as 15) and differed from every NumPy route NumSharp already runs (astype, setitem, np.array, fill).

Fields

DBNull

public static readonly object DBNull

Field Value

object

Methods

ChangeType(object, NPTypeCode)

Returns an object of the specified type whose value is equivalent to the specified object.

public static object ChangeType(object value, NPTypeCode typeCode)

Parameters

value object

An object that implements the IConvertible interface.

typeCode NPTypeCode

The type of object to return.

Returns

object

An object whose underlying type is typeCode and whose value is equivalent to value. -or- A null reference (Nothing in Visual Basic), if value is null and typeCode is Empty, String, or Object.

Exceptions

InvalidCastException

This conversion is not supported. -or- value is null and typeCode specifies a value type. -or- value does not implement the IConvertible interface.

FormatException

value is not in a format recognized by the typeCode type.

OverflowException

value represents a number that is out of the range of the typeCode type.

ArgumentException

typeCode is invalid.

ChangeType(object, NPTypeCode, IFormatProvider)

Returns an object of the specified type whose value is equivalent to the specified object.

public static object ChangeType(object value, NPTypeCode typeCode, IFormatProvider provider)

Parameters

value object

An object that implements the IConvertible interface.

typeCode NPTypeCode

The type of object to return.

provider IFormatProvider

Returns

object

An object whose underlying type is typeCode and whose value is equivalent to value. -or- A null reference (Nothing in Visual Basic), if value is null and typeCode is Empty, String, or Object.

Exceptions

InvalidCastException

This conversion is not supported. -or- value is null and typeCode specifies a value type. -or- value does not implement the IConvertible interface.

FormatException

value is not in a format recognized by the typeCode type.

OverflowException

value represents a number that is out of the range of the typeCode type.

ArgumentException

typeCode is invalid.

ChangeType(object, TypeCode)

public static object ChangeType(object value, TypeCode typeCode)

Parameters

value object
typeCode TypeCode

Returns

object

ChangeType(object, TypeCode, IFormatProvider)

public static object ChangeType(object value, TypeCode typeCode, IFormatProvider provider)

Parameters

value object
typeCode TypeCode
provider IFormatProvider

Returns

object

ChangeType<TOut>(object)

Returns an object of the specified type whose value is equivalent to the specified object.

public static TOut ChangeType<TOut>(object value)

Parameters

value object

An object that implements the IConvertible interface.

Returns

TOut

An object whose underlying type is typeCode and whose value is equivalent to value. -or- A null reference (Nothing in Visual Basic), if value is null and typeCode is Empty, String, or Object.

Type Parameters

TOut

Exceptions

InvalidCastException

This conversion is not supported. -or- value is null and typeCode specifies a value type. -or- value does not implement the IConvertible interface.

FormatException

value is not in a format recognized by the typeCode type.

OverflowException

value represents a number that is out of the range of the typeCode type.

ArgumentException

typeCode is invalid.

ChangeType<T>(T, NPTypeCode)

Returns an object of the specified type whose value is equivalent to the specified object.

public static object ChangeType<T>(T value, NPTypeCode typeCode)

Parameters

value T

An object that implements the IConvertible interface.

typeCode NPTypeCode

The type of object to return.

Returns

object

An object whose underlying type is typeCode and whose value is equivalent to value. -or- A null reference (Nothing in Visual Basic), if value is null and typeCode is Empty, String, or Object.

Type Parameters

T

Exceptions

InvalidCastException

This conversion is not supported. -or- value is null and typeCode specifies a value type. -or- value does not implement the IConvertible interface.

FormatException

value is not in a format recognized by the typeCode type.

OverflowException

value represents a number that is out of the range of the typeCode type.

ArgumentException

typeCode is invalid.

ChangeType<TIn, TOut>(TIn)

Returns an object of the specified type whose value is equivalent to the specified object.

public static TOut ChangeType<TIn, TOut>(TIn value)

Parameters

value TIn

An object that implements the IConvertible interface.

Returns

TOut

An object whose underlying type is typeCode and whose value is equivalent to value. -or- A null reference (Nothing in Visual Basic), if value is null and typeCode is Empty, String, or Object.

Type Parameters

TIn
TOut

Exceptions

InvalidCastException

This conversion is not supported. -or- value is null and typeCode specifies a value type. -or- value does not implement the IConvertible interface.

FormatException

value is not in a format recognized by the typeCode type.

OverflowException

value represents a number that is out of the range of the typeCode type.

ArgumentException

typeCode is invalid.

FindConverter<TIn, TOut>()

Finds the conversion method from Convert based on TIn and TOut.

public static Func<TIn, TOut> FindConverter<TIn, TOut>()

Returns

Func<TIn, TOut>

Type Parameters

TIn

The type that is expected as input and to be converted from

TOut

The type we expect to convert to.

FromBase64CharArray(char[], int, int)

Converts the specified range of a Char array, which encodes binary data as Base64 digits, to the equivalent byte array.

public static byte[] FromBase64CharArray(char[] inArray, int offset, int length)

Parameters

inArray char[]

Chars representing Base64 encoding characters

offset int

A position within the input array.

length int

Number of element to convert.

Returns

byte[]

The array of bytes represented by the specified Base64 encoding characters.

FromBase64String(string)

Converts the specified string, which encodes binary data as Base64 digits, to the equivalent byte array.

public static byte[] FromBase64String(string s)

Parameters

s string

The string to convert

Returns

byte[]

The array of bytes represented by the specifed Base64 string.

GetTypeCode(object)

[Pure]
public static TypeCode GetTypeCode(object value)

Parameters

value object

Returns

TypeCode

IsDBNull(object)

[Pure]
public static bool IsDBNull(object value)

Parameters

value object

Returns

bool

ToBase64CharArray(byte[], int, int, char[], int)

public static int ToBase64CharArray(byte[] inArray, int offsetIn, int length, char[] outArray, int offsetOut)

Parameters

inArray byte[]
offsetIn int
length int
outArray char[]
offsetOut int

Returns

int

ToBase64CharArray(byte[], int, int, char[], int, Base64FormattingOptions)

[ComVisible(false)]
public static int ToBase64CharArray(byte[] inArray, int offsetIn, int length, char[] outArray, int offsetOut, Base64FormattingOptions options)

Parameters

inArray byte[]
offsetIn int
length int
outArray char[]
offsetOut int
options Base64FormattingOptions

Returns

int

ToBoolean(Char8)

public static bool ToBoolean(Char8 value)

Parameters

value Char8

Returns

bool

ToBoolean(DateTime64)

public static bool ToBoolean(DateTime64 value)

Parameters

value DateTime64

Returns

bool

ToBoolean(NDArray)

public static bool ToBoolean(NDArray nd)

Parameters

nd NDArray

Returns

bool

ToBoolean(bool)

public static bool ToBoolean(bool value)

Parameters

value bool

Returns

bool

ToBoolean(byte)

public static bool ToBoolean(byte value)

Parameters

value byte

Returns

bool

ToBoolean(char)

public static bool ToBoolean(char value)

Parameters

value char

Returns

bool

ToBoolean(DateTime)

public static bool ToBoolean(DateTime value)

Parameters

value DateTime

Returns

bool

ToBoolean(decimal)

public static bool ToBoolean(decimal value)

Parameters

value decimal

Returns

bool

ToBoolean(double)

public static bool ToBoolean(double value)

Parameters

value double

Returns

bool

ToBoolean(Half)

public static bool ToBoolean(Half value)

Parameters

value Half

Returns

bool

ToBoolean(short)

public static bool ToBoolean(short value)

Parameters

value short

Returns

bool

ToBoolean(int)

public static bool ToBoolean(int value)

Parameters

value int

Returns

bool

ToBoolean(long)

public static bool ToBoolean(long value)

Parameters

value long

Returns

bool

ToBoolean(Complex)

public static bool ToBoolean(Complex value)

Parameters

value Complex

Returns

bool

ToBoolean(object)

Converts a boxed value of any NumSharp dtype (or a Python str) to Boolean: a number by NumPy's cast rules (the element astype writes), a string by NumPy's text rules (ToBoolean(string)), anything else through its IConvertible.

public static bool ToBoolean(object value)

Parameters

value object

The value; null gives the default.

Returns

bool

The converted value.

Exceptions

ValueError

A str that is not a literal of the target's kind.

OverflowError

A str holding an integer outside an integer target.

InvalidCastException

A value that is neither a dtype value, a str nor IConvertible.

ToBoolean(object, IFormatProvider)

public static bool ToBoolean(object value, IFormatProvider provider)

Parameters

value object
provider IFormatProvider

Returns

bool

ToBoolean(sbyte)

public static bool ToBoolean(sbyte value)

Parameters

value sbyte

Returns

bool

ToBoolean(float)

public static bool ToBoolean(float value)

Parameters

value float

Returns

bool

ToBoolean(string)

Converts a Python str to a bool as NumPy does (np.array([text]).astype(bool), BOOL_setitem): the str's truth value, True for any non-empty text — "False" and "0" included.

public static bool ToBoolean(string value)

Parameters

value string

The text; null gives false (C#'s "no value", as Convert gives).

Returns

bool

The bool value.

ToBoolean(string, IFormatProvider)

ToBoolean(string): NumPy's text has no culture, so provider is ignored (the parameter keeps Convert's signature).

public static bool ToBoolean(string value, IFormatProvider provider)

Parameters

value string

The text; null gives false.

provider IFormatProvider

Ignored.

Returns

bool

The bool value.

ToBoolean(TimeSpan)

public static bool ToBoolean(TimeSpan value)

Parameters

value TimeSpan

Returns

bool

ToBoolean(ushort)

public static bool ToBoolean(ushort value)

Parameters

value ushort

Returns

bool

ToBoolean(uint)

public static bool ToBoolean(uint value)

Parameters

value uint

Returns

bool

ToBoolean(ulong)

public static bool ToBoolean(ulong value)

Parameters

value ulong

Returns

bool

ToByte(Char8)

public static byte ToByte(Char8 value)

Parameters

value Char8

Returns

byte

ToByte(DateTime64)

public static byte ToByte(DateTime64 value)

Parameters

value DateTime64

Returns

byte

ToByte(NDArray)

public static byte ToByte(NDArray nd)

Parameters

nd NDArray

Returns

byte

ToByte(bool)

public static byte ToByte(bool value)

Parameters

value bool

Returns

byte

ToByte(byte)

public static byte ToByte(byte value)

Parameters

value byte

Returns

byte

ToByte(char)

public static byte ToByte(char value)

Parameters

value char

Returns

byte

ToByte(DateTime)

public static byte ToByte(DateTime value)

Parameters

value DateTime

Returns

byte

ToByte(decimal)

public static byte ToByte(decimal value)

Parameters

value decimal

Returns

byte

ToByte(double)

public static byte ToByte(double value)

Parameters

value double

Returns

byte

ToByte(Half)

public static byte ToByte(Half value)

Parameters

value Half

Returns

byte

ToByte(short)

public static byte ToByte(short value)

Parameters

value short

Returns

byte

ToByte(int)

public static byte ToByte(int value)

Parameters

value int

Returns

byte

ToByte(long)

public static byte ToByte(long value)

Parameters

value long

Returns

byte

ToByte(Complex)

public static byte ToByte(Complex value)

Parameters

value Complex

Returns

byte

ToByte(object)

Converts a boxed value of any NumSharp dtype (or a Python str) to Byte: a number by NumPy's cast rules (the element astype writes), a string by NumPy's text rules (ToByte(string)), anything else through its IConvertible.

public static byte ToByte(object value)

Parameters

value object

The value; null gives the default.

Returns

byte

The converted value.

Exceptions

ValueError

A str that is not a literal of the target's kind.

OverflowError

A str holding an integer outside an integer target.

InvalidCastException

A value that is neither a dtype value, a str nor IConvertible.

ToByte(object, IFormatProvider)

public static byte ToByte(object value, IFormatProvider provider)

Parameters

value object
provider IFormatProvider

Returns

byte

ToByte(sbyte)

public static byte ToByte(sbyte value)

Parameters

value sbyte

Returns

byte

ToByte(float)

public static byte ToByte(float value)

Parameters

value float

Returns

byte

ToByte(string)

Converts a Python str to uint8 as NumPy stores it into a uint8 array (a[0] = text): CPython's int() grammar (whitespace, a sign, underscores between digits, non-ASCII decimal digits), culture-invariant.

public static byte ToByte(string value)

Parameters

value string

The text; null gives 0 (C#'s "no value", as Convert gives).

Returns

byte

The uint8 value.

Exceptions

ValueError

The text is not a literal of the target's kind (CPython's text, quoting the str: invalid literal for int() with base 10: '1.5', could not convert string to float: 'x').

OverflowError

The integer is outside uint8 (NumPy's Python integer 300 out of bounds for uint8, or Python int too large to convert to C long).

ToByte(string, IFormatProvider)

ToByte(string): NumPy's text has no culture, so provider is ignored (the parameter keeps Convert's signature).

public static byte ToByte(string value, IFormatProvider provider)

Parameters

value string

The text; null gives 0.

provider IFormatProvider

Ignored.

Returns

byte

The uint8 value.

Exceptions

ValueError

The text is not a literal of the target's kind (CPython's text, quoting the str: invalid literal for int() with base 10: '1.5', could not convert string to float: 'x').

OverflowError

The integer is outside uint8 (NumPy's Python integer 300 out of bounds for uint8, or Python int too large to convert to C long).

ToByte(TimeSpan)

public static byte ToByte(TimeSpan value)

Parameters

value TimeSpan

Returns

byte

ToByte(ushort)

public static byte ToByte(ushort value)

Parameters

value ushort

Returns

byte

ToByte(uint)

public static byte ToByte(uint value)

Parameters

value uint

Returns

byte

ToByte(ulong)

public static byte ToByte(ulong value)

Parameters

value ulong

Returns

byte

ToByteArray(Char8[])

Converts a Char8[] to byte[].

public static byte[] ToByteArray(Char8[] src)

Parameters

src Char8[]

Returns

byte[]

ToChar(Char8)

public static char ToChar(Char8 value)

Parameters

value Char8

Returns

char

ToChar(DateTime64)

public static char ToChar(DateTime64 value)

Parameters

value DateTime64

Returns

char

ToChar(NDArray)

public static char ToChar(NDArray nd)

Parameters

nd NDArray

Returns

char

ToChar(bool)

public static char ToChar(bool value)

Parameters

value bool

Returns

char

ToChar(byte)

public static char ToChar(byte value)

Parameters

value byte

Returns

char

ToChar(char)

public static char ToChar(char value)

Parameters

value char

Returns

char

ToChar(DateTime)

public static char ToChar(DateTime value)

Parameters

value DateTime

Returns

char

ToChar(decimal)

public static char ToChar(decimal value)

Parameters

value decimal

Returns

char

ToChar(double)

public static char ToChar(double value)

Parameters

value double

Returns

char

ToChar(Half)

public static char ToChar(Half value)

Parameters

value Half

Returns

char

ToChar(short)

public static char ToChar(short value)

Parameters

value short

Returns

char

ToChar(int)

public static char ToChar(int value)

Parameters

value int

Returns

char

ToChar(long)

public static char ToChar(long value)

Parameters

value long

Returns

char

ToChar(Complex)

public static char ToChar(Complex value)

Parameters

value Complex

Returns

char

ToChar(object)

Converts a boxed value of any NumSharp dtype (or a Python str) to Char: a number by NumPy's cast rules (the element astype writes), a string by NumPy's text rules (ToChar(string)), anything else through its IConvertible.

public static char ToChar(object value)

Parameters

value object

The value; null gives the default.

Returns

char

The converted value.

Exceptions

ValueError

A str that is not a literal of the target's kind.

OverflowError

A str holding an integer outside an integer target.

InvalidCastException

A value that is neither a dtype value, a str nor IConvertible.

ToChar(object, IFormatProvider)

public static char ToChar(object value, IFormatProvider provider)

Parameters

value object
provider IFormatProvider

Returns

char

ToChar(sbyte)

public static char ToChar(sbyte value)

Parameters

value sbyte

Returns

char

ToChar(float)

public static char ToChar(float value)

Parameters

value float

Returns

char

ToChar(string)

Converts a Python str to char as NumPy stores it into a char array (a[0] = text): CPython's int() grammar (whitespace, a sign, underscores between digits, non-ASCII decimal digits), culture-invariant. NumSharp's char dtype is a 16-bit code unit that crosses to text as its uint16 number, so the text is a number ("97" → 'a'), as astype of a U array to char reads it.

public static char ToChar(string value)

Parameters

value string

The text; null gives the NUL char (C#'s "no value", as Convert gives).

Returns

char

The char value.

Exceptions

ValueError

The text is not a literal of the target's kind (CPython's text, quoting the str: invalid literal for int() with base 10: '1.5', could not convert string to float: 'x').

OverflowError

The integer is outside char (NumPy's Python integer 300 out of bounds for uint8, or Python int too large to convert to C long).

ToChar(string, IFormatProvider)

ToChar(string): NumPy's text has no culture, so provider is ignored (the parameter keeps Convert's signature).

public static char ToChar(string value, IFormatProvider provider)

Parameters

value string

The text; null gives the NUL char.

provider IFormatProvider

Ignored.

Returns

char

The char value.

Exceptions

ValueError

The text is not a literal of the target's kind (CPython's text, quoting the str: invalid literal for int() with base 10: '1.5', could not convert string to float: 'x').

OverflowError

The integer is outside char (NumPy's Python integer 300 out of bounds for uint8, or Python int too large to convert to C long).

ToChar(TimeSpan)

public static char ToChar(TimeSpan value)

Parameters

value TimeSpan

Returns

char

ToChar(ushort)

public static char ToChar(ushort value)

Parameters

value ushort

Returns

char

ToChar(uint)

public static char ToChar(uint value)

Parameters

value uint

Returns

char

ToChar(ulong)

public static char ToChar(ulong value)

Parameters

value ulong

Returns

char

ToChar8(Char8)

public static Char8 ToChar8(Char8 value)

Parameters

value Char8

Returns

Char8

ToChar8(bool)

public static Char8 ToChar8(bool value)

Parameters

value bool

Returns

Char8

ToChar8(byte)

public static Char8 ToChar8(byte value)

Parameters

value byte

Returns

Char8

ToChar8(char)

public static Char8 ToChar8(char value)

Parameters

value char

Returns

Char8

ToChar8(decimal)

public static Char8 ToChar8(decimal value)

Parameters

value decimal

Returns

Char8

ToChar8(double)

public static Char8 ToChar8(double value)

Parameters

value double

Returns

Char8

ToChar8(short)

public static Char8 ToChar8(short value)

Parameters

value short

Returns

Char8

ToChar8(int)

public static Char8 ToChar8(int value)

Parameters

value int

Returns

Char8

ToChar8(long)

public static Char8 ToChar8(long value)

Parameters

value long

Returns

Char8

ToChar8(object)

Converts any IConvertible-supporting value to Char8. Dispatches on GetTypeCode().

public static Char8 ToChar8(object value)

Parameters

value object

Returns

Char8

ToChar8(object, IFormatProvider)

public static Char8 ToChar8(object value, IFormatProvider provider)

Parameters

value object
provider IFormatProvider

Returns

Char8

ToChar8(sbyte)

public static Char8 ToChar8(sbyte value)

Parameters

value sbyte

Returns

Char8

ToChar8(float)

public static Char8 ToChar8(float value)

Parameters

value float

Returns

Char8

ToChar8(string)

Parses a one-character string as Char8 (Latin-1 decoded). Throws on empty, multi-char, or non-Latin-1.

public static Char8 ToChar8(string value)

Parameters

value string

Returns

Char8

ToChar8(ushort)

public static Char8 ToChar8(ushort value)

Parameters

value ushort

Returns

Char8

ToChar8(uint)

public static Char8 ToChar8(uint value)

Parameters

value uint

Returns

Char8

ToChar8(ulong)

public static Char8 ToChar8(ulong value)

Parameters

value ulong

Returns

Char8

ToChar8Array(byte[])

Converts a byte[] to Char8[] (zero-copy reinterpret would require MemoryMarshal; this one copies).

public static Char8[] ToChar8Array(byte[] src)

Parameters

src byte[]

Returns

Char8[]

ToChar8ArrayFromDouble(double[])

public static Char8[] ToChar8ArrayFromDouble(double[] src)

Parameters

src double[]

Returns

Char8[]

ToChar8ArrayFromInt32(int[])

public static Char8[] ToChar8ArrayFromInt32(int[] src)

Parameters

src int[]

Returns

Char8[]

ToChar8<T>(T)

Converts any NumSharp-supported primitive value to Char8. Dispatches on NPTypeCode.

public static Char8 ToChar8<T>(T value) where T : struct

Parameters

value T

Returns

Char8

Type Parameters

T

ToComplex(DateTime64)

public static Complex ToComplex(DateTime64 value)

Parameters

value DateTime64

Returns

Complex

ToComplex(bool)

public static Complex ToComplex(bool value)

Parameters

value bool

Returns

Complex

ToComplex(byte)

public static Complex ToComplex(byte value)

Parameters

value byte

Returns

Complex

ToComplex(char)

public static Complex ToComplex(char value)

Parameters

value char

Returns

Complex

ToComplex(DateTime)

public static Complex ToComplex(DateTime value)

Parameters

value DateTime

Returns

Complex

ToComplex(decimal)

public static Complex ToComplex(decimal value)

Parameters

value decimal

Returns

Complex

ToComplex(double)

public static Complex ToComplex(double value)

Parameters

value double

Returns

Complex

ToComplex(Half)

float16 → complex128: the real part is the float16 converted exactly to float64 with NumPy's NaN rule (ToDouble(Half) — a signalling NaN stays signalling); the imaginary part is +0.

public static Complex ToComplex(Half value)

Parameters

value Half

The value to convert.

Returns

Complex

The complex value value + 0j.

ToComplex(short)

public static Complex ToComplex(short value)

Parameters

value short

Returns

Complex

ToComplex(int)

public static Complex ToComplex(int value)

Parameters

value int

Returns

Complex

ToComplex(long)

public static Complex ToComplex(long value)

Parameters

value long

Returns

Complex

ToComplex(Complex)

public static Complex ToComplex(Complex value)

Parameters

value Complex

Returns

Complex

ToComplex(object)

Converts a boxed value of any NumSharp dtype (or a Python str) to Complex: a number by NumPy's cast rules (the element astype writes), a string by NumPy's text rules (ToComplex(string)), anything else through its IConvertible.

public static Complex ToComplex(object value)

Parameters

value object

The value; null gives the default.

Returns

Complex

The converted value.

Exceptions

ValueError

A str that is not a literal of the target's kind.

OverflowError

A str holding an integer outside an integer target.

InvalidCastException

A value that is neither a dtype value, a str nor IConvertible.

ToComplex(object, IFormatProvider)

public static Complex ToComplex(object value, IFormatProvider provider)

Parameters

value object
provider IFormatProvider

Returns

Complex

ToComplex(sbyte)

public static Complex ToComplex(sbyte value)

Parameters

value sbyte

Returns

Complex

ToComplex(float)

public static Complex ToComplex(float value)

Parameters

value float

Returns

Complex

ToComplex(string)

Converts a Python str to complex128 as NumPy stores it into a complex128 array (a[0] = text): CPython's complex() grammar ("1+2j", "(1+2j)", "2j", "inf", whitespace around), culture-invariant.

public static Complex ToComplex(string value)

Parameters

value string

The text; null gives zero (C#'s "no value").

Returns

Complex

The complex128 value.

Exceptions

ValueError

The text is not a complex literal (CPython's complex() arg is a malformed string).

ToComplex(string, IFormatProvider)

ToComplex(string): NumPy's text has no culture, so provider is ignored.

public static Complex ToComplex(string value, IFormatProvider provider)

Parameters

value string

The text; null gives zero.

provider IFormatProvider

Ignored.

Returns

Complex

The complex128 value.

Exceptions

ValueError

The text is not a complex literal.

ToComplex(TimeSpan)

public static Complex ToComplex(TimeSpan value)

Parameters

value TimeSpan

Returns

Complex

ToComplex(ushort)

public static Complex ToComplex(ushort value)

Parameters

value ushort

Returns

Complex

ToComplex(uint)

public static Complex ToComplex(uint value)

Parameters

value uint

Returns

Complex

ToComplex(ulong)

uint64 → complex128: the real part is rounded ONCE to nearest-even (ToDouble(ulong) — not .NET 8's double-rounding conversion); the imaginary part is +0.

public static Complex ToComplex(ulong value)

Parameters

value ulong

The value to convert.

Returns

Complex

The complex value nearest value + 0j.

ToDateTime(DateTime64)

public static DateTime ToDateTime(DateTime64 value)

Parameters

value DateTime64

Returns

DateTime

ToDateTime(bool)

public static DateTime ToDateTime(bool value)

Parameters

value bool

Returns

DateTime

ToDateTime(byte)

public static DateTime ToDateTime(byte value)

Parameters

value byte

Returns

DateTime

ToDateTime(char)

public static DateTime ToDateTime(char value)

Parameters

value char

Returns

DateTime

ToDateTime(DateTime)

public static DateTime ToDateTime(DateTime value)

Parameters

value DateTime

Returns

DateTime

ToDateTime(decimal)

public static DateTime ToDateTime(decimal value)

Parameters

value decimal

Returns

DateTime

ToDateTime(double)

public static DateTime ToDateTime(double value)

Parameters

value double

Returns

DateTime

ToDateTime(Half)

public static DateTime ToDateTime(Half value)

Parameters

value Half

Returns

DateTime

ToDateTime(short)

public static DateTime ToDateTime(short value)

Parameters

value short

Returns

DateTime

ToDateTime(int)

public static DateTime ToDateTime(int value)

Parameters

value int

Returns

DateTime

ToDateTime(long)

public static DateTime ToDateTime(long value)

Parameters

value long

Returns

DateTime

ToDateTime(Complex)

public static DateTime ToDateTime(Complex value)

Parameters

value Complex

Returns

DateTime

ToDateTime(object)

public static DateTime ToDateTime(object value)

Parameters

value object

Returns

DateTime

ToDateTime(object, IFormatProvider)

public static DateTime ToDateTime(object value, IFormatProvider provider)

Parameters

value object
provider IFormatProvider

Returns

DateTime

ToDateTime(sbyte)

public static DateTime ToDateTime(sbyte value)

Parameters

value sbyte

Returns

DateTime

ToDateTime(float)

public static DateTime ToDateTime(float value)

Parameters

value float

Returns

DateTime

ToDateTime(string)

public static DateTime ToDateTime(string value)

Parameters

value string

Returns

DateTime

ToDateTime(string, IFormatProvider)

public static DateTime ToDateTime(string value, IFormatProvider provider)

Parameters

value string
provider IFormatProvider

Returns

DateTime

ToDateTime(TimeSpan)

public static DateTime ToDateTime(TimeSpan value)

Parameters

value TimeSpan

Returns

DateTime

ToDateTime(ushort)

public static DateTime ToDateTime(ushort value)

Parameters

value ushort

Returns

DateTime

ToDateTime(uint)

public static DateTime ToDateTime(uint value)

Parameters

value uint

Returns

DateTime

ToDateTime(ulong)

public static DateTime ToDateTime(ulong value)

Parameters

value ulong

Returns

DateTime

ToDateTime64(DateTime64)

public static DateTime64 ToDateTime64(DateTime64 value)

Parameters

value DateTime64

Returns

DateTime64

ToDateTime64(bool)

public static DateTime64 ToDateTime64(bool value)

Parameters

value bool

Returns

DateTime64

ToDateTime64(byte)

public static DateTime64 ToDateTime64(byte value)

Parameters

value byte

Returns

DateTime64

ToDateTime64(char)

public static DateTime64 ToDateTime64(char value)

Parameters

value char

Returns

DateTime64

ToDateTime64(DateTime)

public static DateTime64 ToDateTime64(DateTime value)

Parameters

value DateTime

Returns

DateTime64

ToDateTime64(DateTimeOffset)

public static DateTime64 ToDateTime64(DateTimeOffset value)

Parameters

value DateTimeOffset

Returns

DateTime64

ToDateTime64(decimal)

public static DateTime64 ToDateTime64(decimal value)

Parameters

value decimal

Returns

DateTime64

ToDateTime64(double)

public static DateTime64 ToDateTime64(double value)

Parameters

value double

Returns

DateTime64

ToDateTime64(Half)

public static DateTime64 ToDateTime64(Half value)

Parameters

value Half

Returns

DateTime64

ToDateTime64(short)

public static DateTime64 ToDateTime64(short value)

Parameters

value short

Returns

DateTime64

ToDateTime64(int)

public static DateTime64 ToDateTime64(int value)

Parameters

value int

Returns

DateTime64

ToDateTime64(long)

public static DateTime64 ToDateTime64(long value)

Parameters

value long

Returns

DateTime64

ToDateTime64(Complex)

public static DateTime64 ToDateTime64(Complex value)

Parameters

value Complex

Returns

DateTime64

ToDateTime64(object)

public static DateTime64 ToDateTime64(object value)

Parameters

value object

Returns

DateTime64

ToDateTime64(object, IFormatProvider)

public static DateTime64 ToDateTime64(object value, IFormatProvider provider)

Parameters

value object
provider IFormatProvider

Returns

DateTime64

ToDateTime64(sbyte)

public static DateTime64 ToDateTime64(sbyte value)

Parameters

value sbyte

Returns

DateTime64

ToDateTime64(float)

public static DateTime64 ToDateTime64(float value)

Parameters

value float

Returns

DateTime64

ToDateTime64(string)

Parses a datetime text into a DateTime64, culture-invariant: NumPy's datetime64 text is ISO-8601 and has no culture.

public static DateTime64 ToDateTime64(string value)

Parameters

value string

The text: an ISO-8601 date / time (ToString()'s output), or "NaT".

Returns

DateTime64

The value; NaT for null, the empty string or "NaT" (NumPy's np.datetime64('') is NaT too).

Remarks

This read the text in the CURRENT culture before, so the same text gave another date on another machine ("01/02/2020" is January 2 under en-US and February 1 under de-DE), unlike every other text → number conversion of Converts. A caller that wants a culture passes it to ToDateTime64(string, IFormatProvider).

Exceptions

FormatException

The text is not a date / time the invariant culture reads.

ToDateTime64(string, IFormatProvider)

public static DateTime64 ToDateTime64(string value, IFormatProvider provider)

Parameters

value string
provider IFormatProvider

Returns

DateTime64

ToDateTime64(TimeSpan)

public static DateTime64 ToDateTime64(TimeSpan value)

Parameters

value TimeSpan

Returns

DateTime64

ToDateTime64(ushort)

public static DateTime64 ToDateTime64(ushort value)

Parameters

value ushort

Returns

DateTime64

ToDateTime64(uint)

public static DateTime64 ToDateTime64(uint value)

Parameters

value uint

Returns

DateTime64

ToDateTime64(ulong)

public static DateTime64 ToDateTime64(ulong value)

Parameters

value ulong

Returns

DateTime64

ToDateTimeOffset(DateTime64)

public static DateTimeOffset ToDateTimeOffset(DateTime64 value)

Parameters

value DateTime64

Returns

DateTimeOffset

ToDecimal(Char8)

public static decimal ToDecimal(Char8 value)

Parameters

value Char8

Returns

decimal

ToDecimal(DateTime64)

public static decimal ToDecimal(DateTime64 value)

Parameters

value DateTime64

Returns

decimal

ToDecimal(NDArray)

public static decimal ToDecimal(NDArray nd)

Parameters

nd NDArray

Returns

decimal

ToDecimal(bool)

public static decimal ToDecimal(bool value)

Parameters

value bool

Returns

decimal

ToDecimal(byte)

public static decimal ToDecimal(byte value)

Parameters

value byte

Returns

decimal

ToDecimal(char)

public static decimal ToDecimal(char value)

Parameters

value char

Returns

decimal

ToDecimal(DateTime)

public static decimal ToDecimal(DateTime value)

Parameters

value DateTime

Returns

decimal

ToDecimal(decimal)

public static decimal ToDecimal(decimal value)

Parameters

value decimal

Returns

decimal

ToDecimal(double)

public static decimal ToDecimal(double value)

Parameters

value double

Returns

decimal

ToDecimal(Half)

public static decimal ToDecimal(Half value)

Parameters

value Half

Returns

decimal

ToDecimal(short)

public static decimal ToDecimal(short value)

Parameters

value short

Returns

decimal

ToDecimal(int)

public static decimal ToDecimal(int value)

Parameters

value int

Returns

decimal

ToDecimal(long)

public static decimal ToDecimal(long value)

Parameters

value long

Returns

decimal

ToDecimal(Complex)

public static decimal ToDecimal(Complex value)

Parameters

value Complex

Returns

decimal

ToDecimal(object)

Converts a boxed value of any NumSharp dtype (or a Python str) to Decimal: a number by NumPy's cast rules (the element astype writes), a string by NumPy's text rules (ToDecimal(string)), anything else through its IConvertible.

public static decimal ToDecimal(object value)

Parameters

value object

The value; null gives the default.

Returns

decimal

The converted value.

Exceptions

ValueError

A str that is not a literal of the target's kind.

OverflowError

A str holding an integer outside an integer target.

InvalidCastException

A value that is neither a dtype value, a str nor IConvertible.

ToDecimal(object, IFormatProvider)

public static decimal ToDecimal(object value, IFormatProvider provider)

Parameters

value object
provider IFormatProvider

Returns

decimal

ToDecimal(sbyte)

public static decimal ToDecimal(sbyte value)

Parameters

value sbyte

Returns

decimal

ToDecimal(float)

public static decimal ToDecimal(float value)

Parameters

value float

Returns

decimal

ToDecimal(string)

Converts a Python str to decimal as NumPy stores it into a decimal array (a[0] = text): CPython's float() grammar (whitespace, underscores between digits, inf / nan in any case), culture-invariant. NumSharp's decimal (no NumPy analog) parses as a float64 and converts like the float64 → decimal cast.

public static decimal ToDecimal(string value)

Parameters

value string

The text; null gives 0m (C#'s "no value", as Convert gives).

Returns

decimal

The decimal value.

Exceptions

ValueError

The text is not a literal of the target's kind (CPython's text, quoting the str: invalid literal for int() with base 10: '1.5', could not convert string to float: 'x').

ToDecimal(string, IFormatProvider)

ToDecimal(string): NumPy's text has no culture, so provider is ignored (the parameter keeps Convert's signature).

public static decimal ToDecimal(string value, IFormatProvider provider)

Parameters

value string

The text; null gives 0m.

provider IFormatProvider

Ignored.

Returns

decimal

The decimal value.

Exceptions

ValueError

The text is not a literal of the target's kind (CPython's text, quoting the str: invalid literal for int() with base 10: '1.5', could not convert string to float: 'x').

ToDecimal(TimeSpan)

public static decimal ToDecimal(TimeSpan value)

Parameters

value TimeSpan

Returns

decimal

ToDecimal(ushort)

public static decimal ToDecimal(ushort value)

Parameters

value ushort

Returns

decimal

ToDecimal(uint)

public static decimal ToDecimal(uint value)

Parameters

value uint

Returns

decimal

ToDecimal(ulong)

public static decimal ToDecimal(ulong value)

Parameters

value ulong

Returns

decimal

ToDouble(Char8)

public static double ToDouble(Char8 value)

Parameters

value Char8

Returns

double

ToDouble(DateTime64)

public static double ToDouble(DateTime64 value)

Parameters

value DateTime64

Returns

double

ToDouble(NDArray)

public static double ToDouble(NDArray nd)

Parameters

nd NDArray

Returns

double

ToDouble(bool)

public static double ToDouble(bool value)

Parameters

value bool

Returns

double

ToDouble(byte)

public static double ToDouble(byte value)

Parameters

value byte

Returns

double

ToDouble(char)

public static double ToDouble(char value)

Parameters

value char

Returns

double

ToDouble(DateTime)

public static double ToDouble(DateTime value)

Parameters

value DateTime

Returns

double

ToDouble(decimal)

public static double ToDouble(decimal value)

Parameters

value decimal

Returns

double

ToDouble(double)

public static double ToDouble(double value)

Parameters

value double

Returns

double

ToDouble(Half)

float16 → float64, exact, with NumPy's NaN rule (npy_halfbits_to_doublebits — NumPy converts directly, not through float32): a NaN keeps its sign and payload and a SIGNALLING NaN stays signalling — the BCL cast sets the quiet bit.

public static double ToDouble(Half value)

Parameters

value Half

The value to convert.

Returns

double

The same value as float64 (every float16 is exactly representable).

ToDouble(short)

public static double ToDouble(short value)

Parameters

value short

Returns

double

ToDouble(int)

public static double ToDouble(int value)

Parameters

value int

Returns

double

ToDouble(long)

public static double ToDouble(long value)

Parameters

value long

Returns

double

ToDouble(Complex)

public static double ToDouble(Complex value)

Parameters

value Complex

Returns

double

ToDouble(object)

Converts a boxed value of any NumSharp dtype (or a Python str) to Double: a number by NumPy's cast rules (the element astype writes), a string by NumPy's text rules (ToDouble(string)), anything else through its IConvertible.

public static double ToDouble(object value)

Parameters

value object

The value; null gives the default.

Returns

double

The converted value.

Exceptions

ValueError

A str that is not a literal of the target's kind.

OverflowError

A str holding an integer outside an integer target.

InvalidCastException

A value that is neither a dtype value, a str nor IConvertible.

ToDouble(object, IFormatProvider)

public static double ToDouble(object value, IFormatProvider provider)

Parameters

value object
provider IFormatProvider

Returns

double

ToDouble(sbyte)

public static double ToDouble(sbyte value)

Parameters

value sbyte

Returns

double

ToDouble(float)

public static double ToDouble(float value)

Parameters

value float

Returns

double

ToDouble(string)

Converts a Python str to float64 as NumPy stores it into a float64 array (a[0] = text): CPython's float() grammar (whitespace, underscores between digits, inf / nan in any case), culture-invariant.

public static double ToDouble(string value)

Parameters

value string

The text; null gives 0 (C#'s "no value", as Convert gives).

Returns

double

The float64 value.

Exceptions

ValueError

The text is not a literal of the target's kind (CPython's text, quoting the str: invalid literal for int() with base 10: '1.5', could not convert string to float: 'x').

ToDouble(string, IFormatProvider)

ToDouble(string): NumPy's text has no culture, so provider is ignored (the parameter keeps Convert's signature).

public static double ToDouble(string value, IFormatProvider provider)

Parameters

value string

The text; null gives 0.

provider IFormatProvider

Ignored.

Returns

double

The float64 value.

Exceptions

ValueError

The text is not a literal of the target's kind (CPython's text, quoting the str: invalid literal for int() with base 10: '1.5', could not convert string to float: 'x').

ToDouble(TimeSpan)

public static double ToDouble(TimeSpan value)

Parameters

value TimeSpan

Returns

double

ToDouble(ushort)

public static double ToDouble(ushort value)

Parameters

value ushort

Returns

double

ToDouble(uint)

public static double ToDouble(uint value)

Parameters

value uint

Returns

double

ToDouble(ulong)

uint64 → float64, rounded ONCE to nearest-even as NumPy's C cast does — not .NET 8's conversion, which from 2⁶³ on converts as signed and adds 2⁶⁴, rounding twice (2⁶³ + 1025 → 2⁶³ instead of 2⁶³ + 2048).

public static double ToDouble(ulong value)

Parameters

value ulong

The value to convert.

Returns

double

The float64 nearest value, ties to even.

ToDoubleArray(Char8[])

public static double[] ToDoubleArray(Char8[] src)

Parameters

src Char8[]

Returns

double[]

ToHalf(DateTime64)

public static Half ToHalf(DateTime64 value)

Parameters

value DateTime64

Returns

Half

ToHalf(bool)

public static Half ToHalf(bool value)

Parameters

value bool

Returns

Half

ToHalf(byte)

public static Half ToHalf(byte value)

Parameters

value byte

Returns

Half

ToHalf(char)

public static Half ToHalf(char value)

Parameters

value char

Returns

Half

ToHalf(DateTime)

public static Half ToHalf(DateTime value)

Parameters

value DateTime

Returns

Half

ToHalf(decimal)

public static Half ToHalf(decimal value)

Parameters

value decimal

Returns

Half

ToHalf(double)

float64 → float16, rounded ONCE to nearest-even, with NumPy's NaN rule (npy_doublebits_to_halfbits): a NaN keeps its sign and the top 10 payload bits, a SIGNALLING NaN stays signalling, and one whose kept bits are all zero becomes 0x7C01 — the BCL cast sets the quiet bit (0x7E00 for the latter).

public static Half ToHalf(double value)

Parameters

value double

The value to convert.

Returns

Half

The float16 nearest value (±inf beyond the float16 range).

ToHalf(Half)

public static Half ToHalf(Half value)

Parameters

value Half

Returns

Half

ToHalf(short)

public static Half ToHalf(short value)

Parameters

value short

Returns

Half

ToHalf(int)

public static Half ToHalf(int value)

Parameters

value int

Returns

Half

ToHalf(long)

public static Half ToHalf(long value)

Parameters

value long

Returns

Half

ToHalf(Complex)

complex128 → float16: NumPy takes the real part and converts it as float64 → float16 (ToHalf(double), so a signalling NaN stays signalling).

public static Half ToHalf(Complex value)

Parameters

value Complex

The value to convert.

Returns

Half

The float16 nearest the real part.

ToHalf(object)

Converts a boxed value of any NumSharp dtype (or a Python str) to Half: a number by NumPy's cast rules (the element astype writes), a string by NumPy's text rules (ToHalf(string)), anything else through its IConvertible.

public static Half ToHalf(object value)

Parameters

value object

The value; null gives the default.

Returns

Half

The converted value.

Exceptions

ValueError

A str that is not a literal of the target's kind.

OverflowError

A str holding an integer outside an integer target.

InvalidCastException

A value that is neither a dtype value, a str nor IConvertible.

ToHalf(object, IFormatProvider)

public static Half ToHalf(object value, IFormatProvider provider)

Parameters

value object
provider IFormatProvider

Returns

Half

ToHalf(sbyte)

public static Half ToHalf(sbyte value)

Parameters

value sbyte

Returns

Half

ToHalf(float)

float32 → float16, rounded to nearest-even, with NumPy's NaN rule (npy_floatbits_to_halfbits): a NaN keeps its sign and the top 10 payload bits, a SIGNALLING NaN stays signalling, and one whose kept bits are all zero becomes 0x7C01 — the BCL cast sets the quiet bit (0x7E00 for the latter).

public static Half ToHalf(float value)

Parameters

value float

The value to convert.

Returns

Half

The float16 nearest value (±inf beyond the float16 range).

ToHalf(string)

Converts a Python str to float16 as NumPy stores it into a float16 array (a[0] = text): CPython's float() grammar (whitespace, underscores between digits, inf / nan in any case), culture-invariant. The parsed float64 is rounded once more into float16, as NumPy's store rounds it.

public static Half ToHalf(string value)

Parameters

value string

The text; null gives default (C#'s "no value", as Convert gives).

Returns

Half

The float16 value.

Exceptions

ValueError

The text is not a literal of the target's kind (CPython's text, quoting the str: invalid literal for int() with base 10: '1.5', could not convert string to float: 'x').

ToHalf(string, IFormatProvider)

ToHalf(string): NumPy's text has no culture, so provider is ignored (the parameter keeps Convert's signature).

public static Half ToHalf(string value, IFormatProvider provider)

Parameters

value string

The text; null gives default.

provider IFormatProvider

Ignored.

Returns

Half

The float16 value.

Exceptions

ValueError

The text is not a literal of the target's kind (CPython's text, quoting the str: invalid literal for int() with base 10: '1.5', could not convert string to float: 'x').

ToHalf(TimeSpan)

public static Half ToHalf(TimeSpan value)

Parameters

value TimeSpan

Returns

Half

ToHalf(ushort)

public static Half ToHalf(ushort value)

Parameters

value ushort

Returns

Half

ToHalf(uint)

public static Half ToHalf(uint value)

Parameters

value uint

Returns

Half

ToHalf(ulong)

public static Half ToHalf(ulong value)

Parameters

value ulong

Returns

Half

ToInt16(Char8)

public static short ToInt16(Char8 value)

Parameters

value Char8

Returns

short

ToInt16(DateTime64)

public static short ToInt16(DateTime64 value)

Parameters

value DateTime64

Returns

short

ToInt16(NDArray)

public static short ToInt16(NDArray nd)

Parameters

nd NDArray

Returns

short

ToInt16(bool)

public static short ToInt16(bool value)

Parameters

value bool

Returns

short

ToInt16(byte)

public static short ToInt16(byte value)

Parameters

value byte

Returns

short

ToInt16(char)

public static short ToInt16(char value)

Parameters

value char

Returns

short

ToInt16(DateTime)

public static short ToInt16(DateTime value)

Parameters

value DateTime

Returns

short

ToInt16(decimal)

public static short ToInt16(decimal value)

Parameters

value decimal

Returns

short

ToInt16(double)

public static short ToInt16(double value)

Parameters

value double

Returns

short

ToInt16(Half)

public static short ToInt16(Half value)

Parameters

value Half

Returns

short

ToInt16(short)

public static short ToInt16(short value)

Parameters

value short

Returns

short

ToInt16(int)

public static short ToInt16(int value)

Parameters

value int

Returns

short

ToInt16(long)

public static short ToInt16(long value)

Parameters

value long

Returns

short

ToInt16(Complex)

public static short ToInt16(Complex value)

Parameters

value Complex

Returns

short

ToInt16(object)

Converts a boxed value of any NumSharp dtype (or a Python str) to Int16: a number by NumPy's cast rules (the element astype writes), a string by NumPy's text rules (ToInt16(string)), anything else through its IConvertible.

public static short ToInt16(object value)

Parameters

value object

The value; null gives the default.

Returns

short

The converted value.

Exceptions

ValueError

A str that is not a literal of the target's kind.

OverflowError

A str holding an integer outside an integer target.

InvalidCastException

A value that is neither a dtype value, a str nor IConvertible.

ToInt16(object, IFormatProvider)

public static short ToInt16(object value, IFormatProvider provider)

Parameters

value object
provider IFormatProvider

Returns

short

ToInt16(sbyte)

public static short ToInt16(sbyte value)

Parameters

value sbyte

Returns

short

ToInt16(float)

public static short ToInt16(float value)

Parameters

value float

Returns

short

ToInt16(string)

Converts a Python str to int16 as NumPy stores it into a int16 array (a[0] = text): CPython's int() grammar (whitespace, a sign, underscores between digits, non-ASCII decimal digits), culture-invariant.

public static short ToInt16(string value)

Parameters

value string

The text; null gives 0 (C#'s "no value", as Convert gives).

Returns

short

The int16 value.

Exceptions

ValueError

The text is not a literal of the target's kind (CPython's text, quoting the str: invalid literal for int() with base 10: '1.5', could not convert string to float: 'x').

OverflowError

The integer is outside int16 (NumPy's Python integer 300 out of bounds for uint8, or Python int too large to convert to C long).

ToInt16(string, IFormatProvider)

ToInt16(string): NumPy's text has no culture, so provider is ignored (the parameter keeps Convert's signature).

public static short ToInt16(string value, IFormatProvider provider)

Parameters

value string

The text; null gives 0.

provider IFormatProvider

Ignored.

Returns

short

The int16 value.

Exceptions

ValueError

The text is not a literal of the target's kind (CPython's text, quoting the str: invalid literal for int() with base 10: '1.5', could not convert string to float: 'x').

OverflowError

The integer is outside int16 (NumPy's Python integer 300 out of bounds for uint8, or Python int too large to convert to C long).

ToInt16(TimeSpan)

public static short ToInt16(TimeSpan value)

Parameters

value TimeSpan

Returns

short

ToInt16(ushort)

public static short ToInt16(ushort value)

Parameters

value ushort

Returns

short

ToInt16(uint)

public static short ToInt16(uint value)

Parameters

value uint

Returns

short

ToInt16(ulong)

public static short ToInt16(ulong value)

Parameters

value ulong

Returns

short

ToInt32(Char8)

public static int ToInt32(Char8 value)

Parameters

value Char8

Returns

int

ToInt32(DateTime64)

public static int ToInt32(DateTime64 value)

Parameters

value DateTime64

Returns

int

ToInt32(NDArray)

public static int ToInt32(NDArray nd)

Parameters

nd NDArray

Returns

int

ToInt32(bool)

public static int ToInt32(bool value)

Parameters

value bool

Returns

int

ToInt32(byte)

public static int ToInt32(byte value)

Parameters

value byte

Returns

int

ToInt32(char)

public static int ToInt32(char value)

Parameters

value char

Returns

int

ToInt32(DateTime)

public static int ToInt32(DateTime value)

Parameters

value DateTime

Returns

int

ToInt32(decimal)

public static int ToInt32(decimal value)

Parameters

value decimal

Returns

int

ToInt32(double)

NumPy's float64 → int32 cast: truncation toward zero, and int32.MinValue for NaN, ±Inf and every value whose truncation leaves int32's range. Also the per-element body of the float → {int8, uint8, int16, uint16, char} casts (ToInt16(double) and its siblings narrow its result), which every cast kernel calls on a host without the x86 vector cast (arm64; Mono on Android, iOS and WebAssembly).

public static int ToInt32(double value)

Parameters

value double

The value to convert.

Returns

int

The truncated value, or int32.MinValue when it has none in int32.

Remarks

One range test on the untruncated value decides every case: each double in the open interval (-2^31 - 1, 2^31) truncates into int32's range (2147483647.4 → 2147483647, -2147483648.9 → int.MinValue), every other value is out, and NaN fails both comparisons. Both bounds are exact doubles, and the cast inside the range truncates the same way on every runtime. The result equals the truncate-then-test form this replaced for all 2^32 float32 inputs and the boundary doubles; that form called Truncate(double), which Mono compiles to a call: ~15 ns an element on an arm64 phone, 5x the cost of a plain C# cast loop there.

ToInt32(Half)

public static int ToInt32(Half value)

Parameters

value Half

Returns

int

ToInt32(short)

public static int ToInt32(short value)

Parameters

value short

Returns

int

ToInt32(int)

public static int ToInt32(int value)

Parameters

value int

Returns

int

ToInt32(long)

public static int ToInt32(long value)

Parameters

value long

Returns

int

ToInt32(Complex)

public static int ToInt32(Complex value)

Parameters

value Complex

Returns

int

ToInt32(object)

Converts a boxed value of any NumSharp dtype (or a Python str) to Int32: a number by NumPy's cast rules (the element astype writes), a string by NumPy's text rules (ToInt32(string)), anything else through its IConvertible.

public static int ToInt32(object value)

Parameters

value object

The value; null gives the default.

Returns

int

The converted value.

Exceptions

ValueError

A str that is not a literal of the target's kind.

OverflowError

A str holding an integer outside an integer target.

InvalidCastException

A value that is neither a dtype value, a str nor IConvertible.

ToInt32(object, IFormatProvider)

public static int ToInt32(object value, IFormatProvider provider)

Parameters

value object
provider IFormatProvider

Returns

int

ToInt32(sbyte)

public static int ToInt32(sbyte value)

Parameters

value sbyte

Returns

int

ToInt32(float)

public static int ToInt32(float value)

Parameters

value float

Returns

int

ToInt32(string)

Converts a Python str to int32 as NumPy stores it into a int32 array (a[0] = text): CPython's int() grammar (whitespace, a sign, underscores between digits, non-ASCII decimal digits), culture-invariant.

public static int ToInt32(string value)

Parameters

value string

The text; null gives 0 (C#'s "no value", as Convert gives).

Returns

int

The int32 value.

Exceptions

ValueError

The text is not a literal of the target's kind (CPython's text, quoting the str: invalid literal for int() with base 10: '1.5', could not convert string to float: 'x').

OverflowError

The integer is outside int32 (NumPy's Python integer 300 out of bounds for uint8, or Python int too large to convert to C long).

ToInt32(string, IFormatProvider)

ToInt32(string): NumPy's text has no culture, so provider is ignored (the parameter keeps Convert's signature).

public static int ToInt32(string value, IFormatProvider provider)

Parameters

value string

The text; null gives 0.

provider IFormatProvider

Ignored.

Returns

int

The int32 value.

Exceptions

ValueError

The text is not a literal of the target's kind (CPython's text, quoting the str: invalid literal for int() with base 10: '1.5', could not convert string to float: 'x').

OverflowError

The integer is outside int32 (NumPy's Python integer 300 out of bounds for uint8, or Python int too large to convert to C long).

ToInt32(TimeSpan)

public static int ToInt32(TimeSpan value)

Parameters

value TimeSpan

Returns

int

ToInt32(ushort)

public static int ToInt32(ushort value)

Parameters

value ushort

Returns

int

ToInt32(uint)

public static int ToInt32(uint value)

Parameters

value uint

Returns

int

ToInt32(ulong)

public static int ToInt32(ulong value)

Parameters

value ulong

Returns

int

ToInt32Array(Char8[])

public static int[] ToInt32Array(Char8[] src)

Parameters

src Char8[]

Returns

int[]

ToInt64(Char8)

public static long ToInt64(Char8 value)

Parameters

value Char8

Returns

long

ToInt64(DateTime64)

public static long ToInt64(DateTime64 value)

Parameters

value DateTime64

Returns

long

ToInt64(NDArray)

public static long ToInt64(NDArray nd)

Parameters

nd NDArray

Returns

long

ToInt64(bool)

public static long ToInt64(bool value)

Parameters

value bool

Returns

long

ToInt64(byte)

public static long ToInt64(byte value)

Parameters

value byte

Returns

long

ToInt64(char)

public static long ToInt64(char value)

Parameters

value char

Returns

long

ToInt64(DateTime)

public static long ToInt64(DateTime value)

Parameters

value DateTime

Returns

long

ToInt64(decimal)

public static long ToInt64(decimal value)

Parameters

value decimal

Returns

long

ToInt64(double)

public static long ToInt64(double value)

Parameters

value double

Returns

long

ToInt64(Half)

public static long ToInt64(Half value)

Parameters

value Half

Returns

long

ToInt64(short)

public static long ToInt64(short value)

Parameters

value short

Returns

long

ToInt64(int)

public static long ToInt64(int value)

Parameters

value int

Returns

long

ToInt64(long)

public static long ToInt64(long value)

Parameters

value long

Returns

long

ToInt64(Complex)

public static long ToInt64(Complex value)

Parameters

value Complex

Returns

long

ToInt64(object)

Converts a boxed value of any NumSharp dtype (or a Python str) to Int64: a number by NumPy's cast rules (the element astype writes), a string by NumPy's text rules (ToInt64(string)), anything else through its IConvertible.

public static long ToInt64(object value)

Parameters

value object

The value; null gives the default.

Returns

long

The converted value.

Exceptions

ValueError

A str that is not a literal of the target's kind.

OverflowError

A str holding an integer outside an integer target.

InvalidCastException

A value that is neither a dtype value, a str nor IConvertible.

ToInt64(object, IFormatProvider)

public static long ToInt64(object value, IFormatProvider provider)

Parameters

value object
provider IFormatProvider

Returns

long

ToInt64(sbyte)

public static long ToInt64(sbyte value)

Parameters

value sbyte

Returns

long

ToInt64(float)

public static long ToInt64(float value)

Parameters

value float

Returns

long

ToInt64(string)

Converts a Python str to int64 as NumPy stores it into a int64 array (a[0] = text): CPython's int() grammar (whitespace, a sign, underscores between digits, non-ASCII decimal digits), culture-invariant.

public static long ToInt64(string value)

Parameters

value string

The text; null gives 0 (C#'s "no value", as Convert gives).

Returns

long

The int64 value.

Exceptions

ValueError

The text is not a literal of the target's kind (CPython's text, quoting the str: invalid literal for int() with base 10: '1.5', could not convert string to float: 'x').

OverflowError

The integer is outside int64 (NumPy's Python integer 300 out of bounds for uint8, or Python int too large to convert to C long).

ToInt64(string, IFormatProvider)

ToInt64(string): NumPy's text has no culture, so provider is ignored (the parameter keeps Convert's signature).

public static long ToInt64(string value, IFormatProvider provider)

Parameters

value string

The text; null gives 0.

provider IFormatProvider

Ignored.

Returns

long

The int64 value.

Exceptions

ValueError

The text is not a literal of the target's kind (CPython's text, quoting the str: invalid literal for int() with base 10: '1.5', could not convert string to float: 'x').

OverflowError

The integer is outside int64 (NumPy's Python integer 300 out of bounds for uint8, or Python int too large to convert to C long).

ToInt64(TimeSpan)

public static long ToInt64(TimeSpan value)

Parameters

value TimeSpan

Returns

long

ToInt64(ushort)

public static long ToInt64(ushort value)

Parameters

value ushort

Returns

long

ToInt64(uint)

public static long ToInt64(uint value)

Parameters

value uint

Returns

long

ToInt64(ulong)

public static long ToInt64(ulong value)

Parameters

value ulong

Returns

long

ToObject(Char8, NPTypeCode)

Converts a Char8 to a NumSharp-supported primitive by target type code.

public static object ToObject(Char8 value, NPTypeCode typeCode)

Parameters

value Char8
typeCode NPTypeCode

Returns

object

ToSByte(Char8)

public static sbyte ToSByte(Char8 value)

Parameters

value Char8

Returns

sbyte

ToSByte(DateTime64)

public static sbyte ToSByte(DateTime64 value)

Parameters

value DateTime64

Returns

sbyte

ToSByte(bool)

public static sbyte ToSByte(bool value)

Parameters

value bool

Returns

sbyte

ToSByte(byte)

public static sbyte ToSByte(byte value)

Parameters

value byte

Returns

sbyte

ToSByte(char)

public static sbyte ToSByte(char value)

Parameters

value char

Returns

sbyte

ToSByte(DateTime)

public static sbyte ToSByte(DateTime value)

Parameters

value DateTime

Returns

sbyte

ToSByte(decimal)

public static sbyte ToSByte(decimal value)

Parameters

value decimal

Returns

sbyte

ToSByte(double)

public static sbyte ToSByte(double value)

Parameters

value double

Returns

sbyte

ToSByte(Half)

public static sbyte ToSByte(Half value)

Parameters

value Half

Returns

sbyte

ToSByte(short)

public static sbyte ToSByte(short value)

Parameters

value short

Returns

sbyte

ToSByte(int)

public static sbyte ToSByte(int value)

Parameters

value int

Returns

sbyte

ToSByte(long)

public static sbyte ToSByte(long value)

Parameters

value long

Returns

sbyte

ToSByte(Complex)

public static sbyte ToSByte(Complex value)

Parameters

value Complex

Returns

sbyte

ToSByte(object)

Converts a boxed value of any NumSharp dtype (or a Python str) to SByte: a number by NumPy's cast rules (the element astype writes), a string by NumPy's text rules (ToSByte(string)), anything else through its IConvertible.

public static sbyte ToSByte(object value)

Parameters

value object

The value; null gives the default.

Returns

sbyte

The converted value.

Exceptions

ValueError

A str that is not a literal of the target's kind.

OverflowError

A str holding an integer outside an integer target.

InvalidCastException

A value that is neither a dtype value, a str nor IConvertible.

ToSByte(object, IFormatProvider)

public static sbyte ToSByte(object value, IFormatProvider provider)

Parameters

value object
provider IFormatProvider

Returns

sbyte

ToSByte(sbyte)

public static sbyte ToSByte(sbyte value)

Parameters

value sbyte

Returns

sbyte

ToSByte(float)

public static sbyte ToSByte(float value)

Parameters

value float

Returns

sbyte

ToSByte(string)

Converts a Python str to int8 as NumPy stores it into a int8 array (a[0] = text): CPython's int() grammar (whitespace, a sign, underscores between digits, non-ASCII decimal digits), culture-invariant.

public static sbyte ToSByte(string value)

Parameters

value string

The text; null gives 0 (C#'s "no value", as Convert gives).

Returns

sbyte

The int8 value.

Exceptions

ValueError

The text is not a literal of the target's kind (CPython's text, quoting the str: invalid literal for int() with base 10: '1.5', could not convert string to float: 'x').

OverflowError

The integer is outside int8 (NumPy's Python integer 300 out of bounds for uint8, or Python int too large to convert to C long).

ToSByte(string, IFormatProvider)

ToSByte(string): NumPy's text has no culture, so provider is ignored (the parameter keeps Convert's signature).

public static sbyte ToSByte(string value, IFormatProvider provider)

Parameters

value string

The text; null gives 0.

provider IFormatProvider

Ignored.

Returns

sbyte

The int8 value.

Exceptions

ValueError

The text is not a literal of the target's kind (CPython's text, quoting the str: invalid literal for int() with base 10: '1.5', could not convert string to float: 'x').

OverflowError

The integer is outside int8 (NumPy's Python integer 300 out of bounds for uint8, or Python int too large to convert to C long).

ToSByte(TimeSpan)

public static sbyte ToSByte(TimeSpan value)

Parameters

value TimeSpan

Returns

sbyte

ToSByte(ushort)

public static sbyte ToSByte(ushort value)

Parameters

value ushort

Returns

sbyte

ToSByte(uint)

public static sbyte ToSByte(uint value)

Parameters

value uint

Returns

sbyte

ToSByte(ulong)

public static sbyte ToSByte(ulong value)

Parameters

value ulong

Returns

sbyte

ToSingle(Char8)

public static float ToSingle(Char8 value)

Parameters

value Char8

Returns

float

ToSingle(DateTime64)

public static float ToSingle(DateTime64 value)

Parameters

value DateTime64

Returns

float

ToSingle(NDArray)

public static float ToSingle(NDArray nd)

Parameters

nd NDArray

Returns

float

ToSingle(bool)

public static float ToSingle(bool value)

Parameters

value bool

Returns

float

ToSingle(byte)

public static float ToSingle(byte value)

Parameters

value byte

Returns

float

ToSingle(char)

public static float ToSingle(char value)

Parameters

value char

Returns

float

ToSingle(DateTime)

public static float ToSingle(DateTime value)

Parameters

value DateTime

Returns

float

ToSingle(decimal)

public static float ToSingle(decimal value)

Parameters

value decimal

Returns

float

ToSingle(double)

public static float ToSingle(double value)

Parameters

value double

Returns

float

ToSingle(Half)

float16 → float32, exact, with NumPy's NaN rule (npy_halfbits_to_floatbits): a NaN keeps its sign and payload and a SIGNALLING NaN stays signalling — the BCL cast sets the quiet bit.

public static float ToSingle(Half value)

Parameters

value Half

The value to convert.

Returns

float

The same value as float32 (every float16 is exactly representable).

ToSingle(short)

public static float ToSingle(short value)

Parameters

value short

Returns

float

ToSingle(int)

public static float ToSingle(int value)

Parameters

value int

Returns

float

ToSingle(long)

public static float ToSingle(long value)

Parameters

value long

Returns

float

ToSingle(Complex)

public static float ToSingle(Complex value)

Parameters

value Complex

Returns

float

ToSingle(object)

Converts a boxed value of any NumSharp dtype (or a Python str) to Single: a number by NumPy's cast rules (the element astype writes), a string by NumPy's text rules (ToSingle(string)), anything else through its IConvertible.

public static float ToSingle(object value)

Parameters

value object

The value; null gives the default.

Returns

float

The converted value.

Exceptions

ValueError

A str that is not a literal of the target's kind.

OverflowError

A str holding an integer outside an integer target.

InvalidCastException

A value that is neither a dtype value, a str nor IConvertible.

ToSingle(object, IFormatProvider)

public static float ToSingle(object value, IFormatProvider provider)

Parameters

value object
provider IFormatProvider

Returns

float

ToSingle(sbyte)

public static float ToSingle(sbyte value)

Parameters

value sbyte

Returns

float

ToSingle(float)

public static float ToSingle(float value)

Parameters

value float

Returns

float

ToSingle(string)

Converts a Python str to float32 as NumPy stores it into a float32 array (a[0] = text): CPython's float() grammar (whitespace, underscores between digits, inf / nan in any case), culture-invariant. The parsed float64 is rounded once more into float32, as NumPy's store rounds it.

public static float ToSingle(string value)

Parameters

value string

The text; null gives 0 (C#'s "no value", as Convert gives).

Returns

float

The float32 value.

Exceptions

ValueError

The text is not a literal of the target's kind (CPython's text, quoting the str: invalid literal for int() with base 10: '1.5', could not convert string to float: 'x').

ToSingle(string, IFormatProvider)

ToSingle(string): NumPy's text has no culture, so provider is ignored (the parameter keeps Convert's signature).

public static float ToSingle(string value, IFormatProvider provider)

Parameters

value string

The text; null gives 0.

provider IFormatProvider

Ignored.

Returns

float

The float32 value.

Exceptions

ValueError

The text is not a literal of the target's kind (CPython's text, quoting the str: invalid literal for int() with base 10: '1.5', could not convert string to float: 'x').

ToSingle(TimeSpan)

public static float ToSingle(TimeSpan value)

Parameters

value TimeSpan

Returns

float

ToSingle(ushort)

public static float ToSingle(ushort value)

Parameters

value ushort

Returns

float

ToSingle(uint)

public static float ToSingle(uint value)

Parameters

value uint

Returns

float

ToSingle(ulong)

uint64 → float32, rounded ONCE to nearest-even as NumPy's C cast does — not .NET 8's conversion, which goes through float64 and rounds twice (2⁶⁰ + 2³⁶ + 1 → 0x5D800000 instead of NumPy's 0x5D800001).

public static float ToSingle(ulong value)

Parameters

value ulong

The value to convert.

Returns

float

The float32 nearest value, ties to even.

ToString(Char8)

Returns a 1-character string (Latin-1 decode of the byte).

public static string ToString(Char8 value)

Parameters

value Char8

Returns

string

ToString(DateTime64)

public static string ToString(DateTime64 value)

Parameters

value DateTime64

Returns

string

ToString(DateTime64, IFormatProvider)

public static string ToString(DateTime64 value, IFormatProvider provider)

Parameters

value DateTime64
provider IFormatProvider

Returns

string

ToString(bool)

NumPy's str() of a bool value — the text astype('U') writes for it: True / False. Culture-invariant.

public static string ToString(bool value)

Parameters

value bool

The value.

Returns

string

The text.

ToString(bool, IFormatProvider)

ToString(bool): NumPy's text has no culture, so provider is ignored.

public static string ToString(bool value, IFormatProvider provider)

Parameters

value bool

The value.

provider IFormatProvider

Ignored.

Returns

string

The text.

ToString(byte)

NumPy's str() of a uint8 value — the text astype('U') writes for it: its decimal digits. Culture-invariant.

public static string ToString(byte value)

Parameters

value byte

The value.

Returns

string

The text.

ToString(byte, IFormatProvider)

ToString(byte): NumPy's text has no culture, so provider is ignored.

public static string ToString(byte value, IFormatProvider provider)

Parameters

value byte

The value.

provider IFormatProvider

Ignored.

Returns

string

The text.

ToString(char)

NumPy's str() of a char value — the text astype('U') writes for it: its uint16 number ('a' → "97"): NumSharp's char dtype crosses to text as a uint16, as astype('U') writes it. Culture-invariant.

public static string ToString(char value)

Parameters

value char

The value.

Returns

string

The text.

ToString(char, IFormatProvider)

ToString(char): NumPy's text has no culture, so provider is ignored.

public static string ToString(char value, IFormatProvider provider)

Parameters

value char

The value.

provider IFormatProvider

Ignored.

Returns

string

The text.

ToString(DateTime)

public static string ToString(DateTime value)

Parameters

value DateTime

Returns

string

ToString(DateTime, IFormatProvider)

public static string ToString(DateTime value, IFormatProvider provider)

Parameters

value DateTime
provider IFormatProvider

Returns

string

ToString(decimal)

NumPy's str() of a decimal value — the text astype('U') writes for it: the float64 it converts to (NumSharp's decimal text rule; no NumPy analog). Culture-invariant.

public static string ToString(decimal value)

Parameters

value decimal

The value.

Returns

string

The text.

ToString(decimal, IFormatProvider)

ToString(decimal): NumPy's text has no culture, so provider is ignored.

public static string ToString(decimal value, IFormatProvider provider)

Parameters

value decimal

The value.

provider IFormatProvider

Ignored.

Returns

string

The text.

ToString(double)

NumPy's str() of a float64 value — the text astype('U') writes for it: Python's repr of the float (1.0 → "1.0", 1e20 → "1e+20", NaN → "nan"). Culture-invariant.

public static string ToString(double value)

Parameters

value double

The value.

Returns

string

The text.

ToString(double, IFormatProvider)

ToString(double): NumPy's text has no culture, so provider is ignored.

public static string ToString(double value, IFormatProvider provider)

Parameters

value double

The value.

provider IFormatProvider

Ignored.

Returns

string

The text.

ToString(Half)

NumPy's str() of a float16 value — the text astype('U') writes for it: its shortest round-trip digits as float16 ((Half)0.1 → "0.1", (Half)65504 → "6.55e+04"). Culture-invariant.

public static string ToString(Half value)

Parameters

value Half

The value.

Returns

string

The text.

ToString(Half, IFormatProvider)

ToString(Half): NumPy's text has no culture, so provider is ignored.

public static string ToString(Half value, IFormatProvider provider)

Parameters

value Half

The value.

provider IFormatProvider

Ignored.

Returns

string

The text.

ToString(short)

NumPy's str() of a int16 value — the text astype('U') writes for it: its decimal digits. Culture-invariant.

public static string ToString(short value)

Parameters

value short

The value.

Returns

string

The text.

ToString(short, IFormatProvider)

ToString(short): NumPy's text has no culture, so provider is ignored.

public static string ToString(short value, IFormatProvider provider)

Parameters

value short

The value.

provider IFormatProvider

Ignored.

Returns

string

The text.

ToString(int)

NumPy's str() of a int32 value — the text astype('U') writes for it: its decimal digits. Culture-invariant.

public static string ToString(int value)

Parameters

value int

The value.

Returns

string

The text.

ToString(int, IFormatProvider)

ToString(int): NumPy's text has no culture, so provider is ignored.

public static string ToString(int value, IFormatProvider provider)

Parameters

value int

The value.

provider IFormatProvider

Ignored.

Returns

string

The text.

ToString(long)

NumPy's str() of a int64 value — the text astype('U') writes for it: its decimal digits. Culture-invariant.

public static string ToString(long value)

Parameters

value long

The value.

Returns

string

The text.

ToString(long, IFormatProvider)

ToString(long): NumPy's text has no culture, so provider is ignored.

public static string ToString(long value, IFormatProvider provider)

Parameters

value long

The value.

provider IFormatProvider

Ignored.

Returns

string

The text.

ToString(Complex)

NumPy's str() of a complex128 value — the text astype('U') writes for it: "(1+2j)", a pure imaginary value as "2j", each part written like a float64 ("(nan+infj)"). Culture-invariant.

public static string ToString(Complex value)

Parameters

value Complex

The value.

Returns

string

The text.

ToString(Complex, IFormatProvider)

ToString(Complex): NumPy's text has no culture, so provider is ignored.

public static string ToString(Complex value, IFormatProvider provider)

Parameters

value Complex

The value.

provider IFormatProvider

Ignored.

Returns

string

The text.

ToString(object)

The text of a boxed value (ToString(object, IFormatProvider) with no provider): NumPy's str() for a NumSharp dtype value, the value itself for a string.

public static string ToString(object value)

Parameters

value object

The value; null gives the empty string.

Returns

string

The text.

ToString(object, IFormatProvider)

The text of a boxed value: NumPy's str() for a value of one of NumSharp's dtypes (the text astype('U') writes for it, culture-invariant), the value itself for a string, and .NET's text through provider for anything else (a DateTime, a TimeSpan, another object).

public static string ToString(object value, IFormatProvider provider)

Parameters

value object

The value; null gives the empty string.

provider IFormatProvider

The format provider for a value that is not a NumSharp dtype value; ignored otherwise.

Returns

string

The text.

ToString(sbyte)

NumPy's str() of a int8 value — the text astype('U') writes for it: its decimal digits. Culture-invariant.

public static string ToString(sbyte value)

Parameters

value sbyte

The value.

Returns

string

The text.

ToString(sbyte, IFormatProvider)

ToString(sbyte): NumPy's text has no culture, so provider is ignored.

public static string ToString(sbyte value, IFormatProvider provider)

Parameters

value sbyte

The value.

provider IFormatProvider

Ignored.

Returns

string

The text.

ToString(float)

NumPy's str() of a float32 value — the text astype('U') writes for it: its shortest round-trip digits as float32 (0.1f → "0.1", 1e20f → "1e+20"). Culture-invariant.

public static string ToString(float value)

Parameters

value float

The value.

Returns

string

The text.

ToString(float, IFormatProvider)

ToString(float): NumPy's text has no culture, so provider is ignored.

public static string ToString(float value, IFormatProvider provider)

Parameters

value float

The value.

provider IFormatProvider

Ignored.

Returns

string

The text.

ToString(string)

public static string ToString(string value)

Parameters

value string

Returns

string

ToString(string, IFormatProvider)

public static string ToString(string value, IFormatProvider provider)

Parameters

value string
provider IFormatProvider

Returns

string

ToString(ushort)

NumPy's str() of a uint16 value — the text astype('U') writes for it: its decimal digits. Culture-invariant.

public static string ToString(ushort value)

Parameters

value ushort

The value.

Returns

string

The text.

ToString(ushort, IFormatProvider)

ToString(ushort): NumPy's text has no culture, so provider is ignored.

public static string ToString(ushort value, IFormatProvider provider)

Parameters

value ushort

The value.

provider IFormatProvider

Ignored.

Returns

string

The text.

ToString(uint)

NumPy's str() of a uint32 value — the text astype('U') writes for it: its decimal digits. Culture-invariant.

public static string ToString(uint value)

Parameters

value uint

The value.

Returns

string

The text.

ToString(uint, IFormatProvider)

ToString(uint): NumPy's text has no culture, so provider is ignored.

public static string ToString(uint value, IFormatProvider provider)

Parameters

value uint

The value.

provider IFormatProvider

Ignored.

Returns

string

The text.

ToString(ulong)

NumPy's str() of a uint64 value — the text astype('U') writes for it: its decimal digits. Culture-invariant.

public static string ToString(ulong value)

Parameters

value ulong

The value.

Returns

string

The text.

ToString(ulong, IFormatProvider)

ToString(ulong): NumPy's text has no culture, so provider is ignored.

public static string ToString(ulong value, IFormatProvider provider)

Parameters

value ulong

The value.

provider IFormatProvider

Ignored.

Returns

string

The text.

ToTimeSpan(DateTime64)

public static TimeSpan ToTimeSpan(DateTime64 value)

Parameters

value DateTime64

Returns

TimeSpan

ToTimeSpan(bool)

public static TimeSpan ToTimeSpan(bool value)

Parameters

value bool

Returns

TimeSpan

ToTimeSpan(byte)

public static TimeSpan ToTimeSpan(byte value)

Parameters

value byte

Returns

TimeSpan

ToTimeSpan(char)

public static TimeSpan ToTimeSpan(char value)

Parameters

value char

Returns

TimeSpan

ToTimeSpan(DateTime)

public static TimeSpan ToTimeSpan(DateTime value)

Parameters

value DateTime

Returns

TimeSpan

ToTimeSpan(decimal)

public static TimeSpan ToTimeSpan(decimal value)

Parameters

value decimal

Returns

TimeSpan

ToTimeSpan(double)

public static TimeSpan ToTimeSpan(double value)

Parameters

value double

Returns

TimeSpan

ToTimeSpan(Half)

public static TimeSpan ToTimeSpan(Half value)

Parameters

value Half

Returns

TimeSpan

ToTimeSpan(short)

public static TimeSpan ToTimeSpan(short value)

Parameters

value short

Returns

TimeSpan

ToTimeSpan(int)

public static TimeSpan ToTimeSpan(int value)

Parameters

value int

Returns

TimeSpan

ToTimeSpan(long)

public static TimeSpan ToTimeSpan(long value)

Parameters

value long

Returns

TimeSpan

ToTimeSpan(Complex)

public static TimeSpan ToTimeSpan(Complex value)

Parameters

value Complex

Returns

TimeSpan

ToTimeSpan(object)

public static TimeSpan ToTimeSpan(object value)

Parameters

value object

Returns

TimeSpan

ToTimeSpan(sbyte)

public static TimeSpan ToTimeSpan(sbyte value)

Parameters

value sbyte

Returns

TimeSpan

ToTimeSpan(float)

public static TimeSpan ToTimeSpan(float value)

Parameters

value float

Returns

TimeSpan

ToTimeSpan(string)

public static TimeSpan ToTimeSpan(string value)

Parameters

value string

Returns

TimeSpan

ToTimeSpan(string, IFormatProvider)

public static TimeSpan ToTimeSpan(string value, IFormatProvider provider)

Parameters

value string
provider IFormatProvider

Returns

TimeSpan

ToTimeSpan(TimeSpan)

public static TimeSpan ToTimeSpan(TimeSpan value)

Parameters

value TimeSpan

Returns

TimeSpan

ToTimeSpan(ushort)

public static TimeSpan ToTimeSpan(ushort value)

Parameters

value ushort

Returns

TimeSpan

ToTimeSpan(uint)

public static TimeSpan ToTimeSpan(uint value)

Parameters

value uint

Returns

TimeSpan

ToTimeSpan(ulong)

public static TimeSpan ToTimeSpan(ulong value)

Parameters

value ulong

Returns

TimeSpan

ToUInt16(Char8)

public static ushort ToUInt16(Char8 value)

Parameters

value Char8

Returns

ushort

ToUInt16(DateTime64)

public static ushort ToUInt16(DateTime64 value)

Parameters

value DateTime64

Returns

ushort

ToUInt16(NDArray)

public static ushort ToUInt16(NDArray nd)

Parameters

nd NDArray

Returns

ushort

ToUInt16(bool)

public static ushort ToUInt16(bool value)

Parameters

value bool

Returns

ushort

ToUInt16(byte)

public static ushort ToUInt16(byte value)

Parameters

value byte

Returns

ushort

ToUInt16(char)

public static ushort ToUInt16(char value)

Parameters

value char

Returns

ushort

ToUInt16(DateTime)

public static ushort ToUInt16(DateTime value)

Parameters

value DateTime

Returns

ushort

ToUInt16(decimal)

public static ushort ToUInt16(decimal value)

Parameters

value decimal

Returns

ushort

ToUInt16(double)

public static ushort ToUInt16(double value)

Parameters

value double

Returns

ushort

ToUInt16(Half)

public static ushort ToUInt16(Half value)

Parameters

value Half

Returns

ushort

ToUInt16(short)

public static ushort ToUInt16(short value)

Parameters

value short

Returns

ushort

ToUInt16(int)

public static ushort ToUInt16(int value)

Parameters

value int

Returns

ushort

ToUInt16(long)

public static ushort ToUInt16(long value)

Parameters

value long

Returns

ushort

ToUInt16(Complex)

public static ushort ToUInt16(Complex value)

Parameters

value Complex

Returns

ushort

ToUInt16(object)

Converts a boxed value of any NumSharp dtype (or a Python str) to UInt16: a number by NumPy's cast rules (the element astype writes), a string by NumPy's text rules (ToUInt16(string)), anything else through its IConvertible.

public static ushort ToUInt16(object value)

Parameters

value object

The value; null gives the default.

Returns

ushort

The converted value.

Exceptions

ValueError

A str that is not a literal of the target's kind.

OverflowError

A str holding an integer outside an integer target.

InvalidCastException

A value that is neither a dtype value, a str nor IConvertible.

ToUInt16(object, IFormatProvider)

public static ushort ToUInt16(object value, IFormatProvider provider)

Parameters

value object
provider IFormatProvider

Returns

ushort

ToUInt16(sbyte)

public static ushort ToUInt16(sbyte value)

Parameters

value sbyte

Returns

ushort

ToUInt16(float)

public static ushort ToUInt16(float value)

Parameters

value float

Returns

ushort

ToUInt16(string)

Converts a Python str to uint16 as NumPy stores it into a uint16 array (a[0] = text): CPython's int() grammar (whitespace, a sign, underscores between digits, non-ASCII decimal digits), culture-invariant.

public static ushort ToUInt16(string value)

Parameters

value string

The text; null gives 0 (C#'s "no value", as Convert gives).

Returns

ushort

The uint16 value.

Exceptions

ValueError

The text is not a literal of the target's kind (CPython's text, quoting the str: invalid literal for int() with base 10: '1.5', could not convert string to float: 'x').

OverflowError

The integer is outside uint16 (NumPy's Python integer 300 out of bounds for uint8, or Python int too large to convert to C long).

ToUInt16(string, IFormatProvider)

ToUInt16(string): NumPy's text has no culture, so provider is ignored (the parameter keeps Convert's signature).

public static ushort ToUInt16(string value, IFormatProvider provider)

Parameters

value string

The text; null gives 0.

provider IFormatProvider

Ignored.

Returns

ushort

The uint16 value.

Exceptions

ValueError

The text is not a literal of the target's kind (CPython's text, quoting the str: invalid literal for int() with base 10: '1.5', could not convert string to float: 'x').

OverflowError

The integer is outside uint16 (NumPy's Python integer 300 out of bounds for uint8, or Python int too large to convert to C long).

ToUInt16(TimeSpan)

public static ushort ToUInt16(TimeSpan value)

Parameters

value TimeSpan

Returns

ushort

ToUInt16(ushort)

public static ushort ToUInt16(ushort value)

Parameters

value ushort

Returns

ushort

ToUInt16(uint)

public static ushort ToUInt16(uint value)

Parameters

value uint

Returns

ushort

ToUInt16(ulong)

public static ushort ToUInt16(ulong value)

Parameters

value ulong

Returns

ushort

ToUInt32(Char8)

public static uint ToUInt32(Char8 value)

Parameters

value Char8

Returns

uint

ToUInt32(DateTime64)

public static uint ToUInt32(DateTime64 value)

Parameters

value DateTime64

Returns

uint

ToUInt32(NDArray)

public static uint ToUInt32(NDArray nd)

Parameters

nd NDArray

Returns

uint

ToUInt32(bool)

public static uint ToUInt32(bool value)

Parameters

value bool

Returns

uint

ToUInt32(byte)

public static uint ToUInt32(byte value)

Parameters

value byte

Returns

uint

ToUInt32(char)

public static uint ToUInt32(char value)

Parameters

value char

Returns

uint

ToUInt32(DateTime)

public static uint ToUInt32(DateTime value)

Parameters

value DateTime

Returns

uint

ToUInt32(decimal)

public static uint ToUInt32(decimal value)

Parameters

value decimal

Returns

uint

ToUInt32(double)

public static uint ToUInt32(double value)

Parameters

value double

Returns

uint

ToUInt32(Half)

public static uint ToUInt32(Half value)

Parameters

value Half

Returns

uint

ToUInt32(short)

public static uint ToUInt32(short value)

Parameters

value short

Returns

uint

ToUInt32(int)

public static uint ToUInt32(int value)

Parameters

value int

Returns

uint

ToUInt32(long)

public static uint ToUInt32(long value)

Parameters

value long

Returns

uint

ToUInt32(Complex)

public static uint ToUInt32(Complex value)

Parameters

value Complex

Returns

uint

ToUInt32(object)

Converts a boxed value of any NumSharp dtype (or a Python str) to UInt32: a number by NumPy's cast rules (the element astype writes), a string by NumPy's text rules (ToUInt32(string)), anything else through its IConvertible.

public static uint ToUInt32(object value)

Parameters

value object

The value; null gives the default.

Returns

uint

The converted value.

Exceptions

ValueError

A str that is not a literal of the target's kind.

OverflowError

A str holding an integer outside an integer target.

InvalidCastException

A value that is neither a dtype value, a str nor IConvertible.

ToUInt32(object, IFormatProvider)

public static uint ToUInt32(object value, IFormatProvider provider)

Parameters

value object
provider IFormatProvider

Returns

uint

ToUInt32(sbyte)

public static uint ToUInt32(sbyte value)

Parameters

value sbyte

Returns

uint

ToUInt32(float)

public static uint ToUInt32(float value)

Parameters

value float

Returns

uint

ToUInt32(string)

Converts a Python str to uint32 as NumPy stores it into a uint32 array (a[0] = text): CPython's int() grammar (whitespace, a sign, underscores between digits, non-ASCII decimal digits), culture-invariant.

public static uint ToUInt32(string value)

Parameters

value string

The text; null gives 0 (C#'s "no value", as Convert gives).

Returns

uint

The uint32 value.

Exceptions

ValueError

The text is not a literal of the target's kind (CPython's text, quoting the str: invalid literal for int() with base 10: '1.5', could not convert string to float: 'x').

OverflowError

The integer is outside uint32 (NumPy's Python integer 300 out of bounds for uint8, or Python int too large to convert to C long).

ToUInt32(string, IFormatProvider)

ToUInt32(string): NumPy's text has no culture, so provider is ignored (the parameter keeps Convert's signature).

public static uint ToUInt32(string value, IFormatProvider provider)

Parameters

value string

The text; null gives 0.

provider IFormatProvider

Ignored.

Returns

uint

The uint32 value.

Exceptions

ValueError

The text is not a literal of the target's kind (CPython's text, quoting the str: invalid literal for int() with base 10: '1.5', could not convert string to float: 'x').

OverflowError

The integer is outside uint32 (NumPy's Python integer 300 out of bounds for uint8, or Python int too large to convert to C long).

ToUInt32(TimeSpan)

public static uint ToUInt32(TimeSpan value)

Parameters

value TimeSpan

Returns

uint

ToUInt32(ushort)

public static uint ToUInt32(ushort value)

Parameters

value ushort

Returns

uint

ToUInt32(uint)

public static uint ToUInt32(uint value)

Parameters

value uint

Returns

uint

ToUInt32(ulong)

public static uint ToUInt32(ulong value)

Parameters

value ulong

Returns

uint

ToUInt64(Char8)

public static ulong ToUInt64(Char8 value)

Parameters

value Char8

Returns

ulong

ToUInt64(DateTime64)

public static ulong ToUInt64(DateTime64 value)

Parameters

value DateTime64

Returns

ulong

ToUInt64(NDArray)

public static ulong ToUInt64(NDArray nd)

Parameters

nd NDArray

Returns

ulong

ToUInt64(bool)

public static ulong ToUInt64(bool value)

Parameters

value bool

Returns

ulong

ToUInt64(byte)

public static ulong ToUInt64(byte value)

Parameters

value byte

Returns

ulong

ToUInt64(char)

public static ulong ToUInt64(char value)

Parameters

value char

Returns

ulong

ToUInt64(DateTime)

public static ulong ToUInt64(DateTime value)

Parameters

value DateTime

Returns

ulong

ToUInt64(decimal)

public static ulong ToUInt64(decimal value)

Parameters

value decimal

Returns

ulong

ToUInt64(double)

public static ulong ToUInt64(double value)

Parameters

value double

Returns

ulong

ToUInt64(Half)

public static ulong ToUInt64(Half value)

Parameters

value Half

Returns

ulong

ToUInt64(short)

public static ulong ToUInt64(short value)

Parameters

value short

Returns

ulong

ToUInt64(int)

public static ulong ToUInt64(int value)

Parameters

value int

Returns

ulong

ToUInt64(long)

public static ulong ToUInt64(long value)

Parameters

value long

Returns

ulong

ToUInt64(Complex)

public static ulong ToUInt64(Complex value)

Parameters

value Complex

Returns

ulong

ToUInt64(object)

Converts a boxed value of any NumSharp dtype (or a Python str) to UInt64: a number by NumPy's cast rules (the element astype writes), a string by NumPy's text rules (ToUInt64(string)), anything else through its IConvertible.

public static ulong ToUInt64(object value)

Parameters

value object

The value; null gives the default.

Returns

ulong

The converted value.

Exceptions

ValueError

A str that is not a literal of the target's kind.

OverflowError

A str holding an integer outside an integer target.

InvalidCastException

A value that is neither a dtype value, a str nor IConvertible.

ToUInt64(object, IFormatProvider)

public static ulong ToUInt64(object value, IFormatProvider provider)

Parameters

value object
provider IFormatProvider

Returns

ulong

ToUInt64(sbyte)

public static ulong ToUInt64(sbyte value)

Parameters

value sbyte

Returns

ulong

ToUInt64(float)

public static ulong ToUInt64(float value)

Parameters

value float

Returns

ulong

ToUInt64(string)

Converts a Python str to uint64 as NumPy stores it into a uint64 array (a[0] = text): CPython's int() grammar (whitespace, a sign, underscores between digits, non-ASCII decimal digits), culture-invariant.

public static ulong ToUInt64(string value)

Parameters

value string

The text; null gives 0 (C#'s "no value", as Convert gives).

Returns

ulong

The uint64 value.

Exceptions

ValueError

The text is not a literal of the target's kind (CPython's text, quoting the str: invalid literal for int() with base 10: '1.5', could not convert string to float: 'x').

OverflowError

The integer is outside uint64 (NumPy's Python integer 300 out of bounds for uint8, or Python int too large to convert to C long).

ToUInt64(string, IFormatProvider)

ToUInt64(string): NumPy's text has no culture, so provider is ignored (the parameter keeps Convert's signature).

public static ulong ToUInt64(string value, IFormatProvider provider)

Parameters

value string

The text; null gives 0.

provider IFormatProvider

Ignored.

Returns

ulong

The uint64 value.

Exceptions

ValueError

The text is not a literal of the target's kind (CPython's text, quoting the str: invalid literal for int() with base 10: '1.5', could not convert string to float: 'x').

OverflowError

The integer is outside uint64 (NumPy's Python integer 300 out of bounds for uint8, or Python int too large to convert to C long).

ToUInt64(TimeSpan)

public static ulong ToUInt64(TimeSpan value)

Parameters

value TimeSpan

Returns

ulong

ToUInt64(ushort)

public static ulong ToUInt64(ushort value)

Parameters

value ushort

Returns

ulong

ToUInt64(uint)

public static ulong ToUInt64(uint value)

Parameters

value uint

Returns

ulong

ToUInt64(ulong)

public static ulong ToUInt64(ulong value)

Parameters

value ulong

Returns

ulong