Skip to main content

DType

Enum DType 

Source
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§

§

Boolean

§

Integer(Width)

§

Float(FloatWidth)

§

Complex(ComplexWidth)

§

Character

Implementations§

Source§

impl DType

Source

pub fn is_integral(self) -> bool

Whether items of this dtype are whole numbers: Booleans and integers.

Source

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.

Source

pub fn is_real(self) -> bool

Whether items of this dtype are real numbers: Booleans, integers and floats.

Source

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.

Source

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.

Source

pub fn named(name: &str) -> Option<DType>

The dtype that DType::name calls name, or None for any other name.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn real(self) -> DType

The real dtype of a complex dtype’s parts. Other dtypes are their own.

Source

pub fn complex(self) -> DType

The complex dtype that numbers of this dtype take: complex64 for f16, f32 and complex64, and complex128 for everything else.

Source§

impl DType

Source

pub const ALL: [DType; 11]

Every dtype, in the order that numbers widen, with characters last.

Source

pub const fn index(self) -> usize

This dtype’s position in DType::ALL.

Source§

impl DType

Source

pub fn bytes(self) -> usize

The bytes that one item of this dtype takes.

Trait Implementations§

Source§

impl Clone for DType

Source§

fn clone(&self) -> DType

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for DType

Source§

impl Debug for DType

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Eq for DType

Source§

impl Hash for DType

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for DType

Source§

fn eq(&self, other: &DType) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.