pub enum DType {
Boolean,
Integer(Width),
Float(FloatWidth),
Complex(ComplexWidth),
Character,
}Expand description
The element type of a compact buffer. Numbers widen from Boolean through the integer widths to the float widths to the complex widths.
Variants§
Implementations§
Source§impl DType
impl DType
Sourcepub fn is_integral(self) -> bool
pub fn is_integral(self) -> bool
Whether items of this dtype are whole numbers: Booleans and integers.
Sourcepub fn mathish(self) -> bool
pub fn mathish(self) -> bool
Whether Mathish forms (tolerant::MathishFloorDivide and the rest) apply to a call that computes at this dtype: 64-bit floats and complex numbers with 64-bit parts.
Sourcepub fn is_real(self) -> bool
pub fn is_real(self) -> bool
Whether items of this dtype are real numbers: Booleans, integers and floats.
Sourcepub fn kind(self) -> u8
pub fn kind(self) -> u8
This dtype’s kind, in the order that NEP 50 promotes kinds: 0 for Booleans, 1 for integers, 2 for floats, 3 for complex numbers and 4 for characters, which don’t mix with numbers.
Sourcepub fn name(self) -> &'static str
pub fn name(self) -> &'static str
The dtype’s name, as NumPy names its dtypes: "bool", "uint8", "int16", "int32", "int64", "float16", "float32", "float64", "complex64" and "complex128". NumPy has no dtype for characters, which are "character". Rustymath’s Python API and BPL’s •storage both use these names.
Sourcepub fn named(name: &str) -> Option<DType>
pub fn named(name: &str) -> Option<DType>
The dtype that DType::name calls name, or None for any other name.
Sourcepub fn widens_to(self, to: DType) -> bool
pub fn widens_to(self, to: DType) -> bool
Whether this dtype widens to to: whether DType::common promotes this dtype and to to to. An integer widens to every float and complex dtype.
Sourcepub fn inexact(self, limit: FloatWidth) -> Option<(DType, DType)>
pub fn inexact(self, limit: FloatWidth) -> Option<(DType, DType)>
The dtypes that a function of floats or complex numbers computes in and gives, for arguments of this dtype. A Boolean or an integer takes the float that Width::float gives under limit, but at least f32, which computes faster than f16. Under NumPy’s limit, f64, that’s f32 for Booleans, u8 and i16, and f64 for i32 and i64. f16 computes in f32, and its results round back. Other floats and complex numbers stay as they are. None for characters.
Sourcepub fn numpy_float(self) -> FloatWidth
pub fn numpy_float(self) -> FloatWidth
The float width that a Boolean or integer computes in under rustymath’s own policy, NumPy’s: the float that DType::inexact gives it under f64. f64 for any other dtype.
Sourcepub fn computes_in(
self,
int: Width,
float: FloatWidth,
has: impl Fn(DType) -> bool,
) -> Option<DType>
pub fn computes_in( self, int: Width, float: FloatWidth, has: impl Fn(DType) -> bool, ) -> Option<DType>
The dtype that an argument of this dtype computes in, for a function with a kernel at each dtype where has holds. That’s this dtype where it has a kernel. Otherwise it’s the first with a kernel of these: for a Boolean or an integer, integers of int or of this dtype’s width, whichever is wider, then floats of float; for a float or a complex number, the dtype that DType::inexact gives it; then each wider float, and each complex dtype whose parts are at least as wide; and last, for a float, integers of int, which compute it as the whole number it holds (operation::whole_numbers). int and float are the caller’s policy for exact numbers. NumPy’s is i64 and the float that inexact gives under f64. None where no dtype on the way has a kernel.
Sourcepub fn common(self, other: DType) -> Option<DType>
pub fn common(self, other: DType) -> Option<DType>
The dtype that arguments of this dtype and other promote to: the higher kind, wide enough for both. A Boolean takes the other dtype. An integer beside a float or complex dtype takes that dtype, as in JAX, where NumPy widens the float to hold every integer exactly. A float beside a complex dtype takes parts at least as wide. None for characters beside numbers.
Sourcepub fn common_weak(self, weak: DType) -> Option<DType>
pub fn common_weak(self, weak: DType) -> Option<DType>
The dtype that NEP 50 promotes an array of this dtype and a weak value of dtype weak to. A weak value is a Python scalar, which has no dtype of its own. BPL’s weak numbers follow the same rule. The caller gives the weak value’s dtype at the default width of its kind. Where its kind is no higher, the array’s dtype wins. A weak complex value beside floats takes their width. Otherwise the weak dtype wins. None for characters beside numbers.
Trait Implementations§
impl Copy for DType
impl Eq for DType
impl StructuralPartialEq for DType
Auto Trait Implementations§
impl Forget for DType
impl Freeze for DType
impl RefUnwindSafe for DType
impl Send for DType
impl Sync for DType
impl Unpin for DType
impl UnsafeUnpin for DType
impl UnwindSafe for DType
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more