pub enum DType {
Show 14 variants
Bool,
Int8,
Int16,
Int32,
Int64,
Uint8,
Uint16,
Uint32,
Uint64,
Fp16,
Fp32,
Fp64,
Bf16,
Others,
}Expand description
Enumeration of all supported data types for tensor elements.
This enum represents the various numeric types that can be stored in tensors, including integers, floating-point numbers, and boolean values. Each variant corresponds to a specific Rust primitive type or half-precision type.
§Examples
use slsl::DType;
let dtype = DType::Fp32;
assert_eq!(dtype.size_in_bytes(), 4);
assert!(dtype.is_float());
let int_dtype = DType::Int32;
assert_eq!(int_dtype.size_in_bytes(), 4);
assert!(!int_dtype.is_float());Variants§
Bool
Boolean type (bool)
Int8
8-bit signed integer (i8)
Int16
16-bit signed integer (i16)
Int32
32-bit signed integer (i32)
Int64
64-bit signed integer (i64)
Uint8
8-bit unsigned integer (u8)
Uint16
16-bit unsigned integer (u16)
Uint32
32-bit unsigned integer (u32)
Uint64
64-bit unsigned integer (u64)
Fp16
16-bit floating-point number (half-precision)
Fp32
32-bit floating-point number (single-precision)
Fp64
64-bit floating-point number (double-precision)
Bf16
16-bit brain floating-point number
Others
Placeholder variant - should not be used in practice, use _
Implementations§
Source§impl DType
impl DType
Sourcepub fn size_in_bytes(self) -> usize
pub fn size_in_bytes(self) -> usize
Returns the size in bytes of this data type.
This method returns the memory footprint of a single element of this data type, which is useful for memory allocation and layout calculations.
§Returns
The size in bytes as a usize.
§Panics
Panics if called on DType::Others, as this is a placeholder
variant and does not correspond to a concrete type.
§Examples
use slsl::DType;
assert_eq!(DType::Bool.size_in_bytes(), 1);
assert_eq!(DType::Int32.size_in_bytes(), 4);
assert_eq!(DType::Fp64.size_in_bytes(), 8);
assert_eq!(DType::Fp16.size_in_bytes(), 2);Sourcepub fn is_float(self) -> bool
pub fn is_float(self) -> bool
Checks if this data type represents a floating-point number.
Returns true for all floating-point variants (including half-precision
and brain floating-point types), and false for integer and boolean types.
§Returns
true if the data type is floating-point, false otherwise.
§Examples
use slsl::DType;
// Floating-point types
assert!(DType::Fp16.is_float());
assert!(DType::Fp32.is_float());
assert!(DType::Fp64.is_float());
assert!(DType::Bf16.is_float());
// Non-floating-point types
assert!(!DType::Int32.is_float());
assert!(!DType::Bool.is_float());
assert!(!DType::Uint8.is_float());Sourcepub fn is_integer(self) -> bool
pub fn is_integer(self) -> bool
Checks if this data type represents an integer number.
Returns true for all signed and unsigned integer variants,
and false for floating-point and boolean types.
§Returns
true if the data type is an integer, false otherwise.
§Examples
use slsl::DType;
// Integer types
assert!(DType::Int8.is_integer());
assert!(DType::Int32.is_integer());
assert!(DType::Uint16.is_integer());
assert!(DType::Uint64.is_integer());
// Non-integer types
assert!(!DType::Fp32.is_integer());
assert!(!DType::Bool.is_integer());Sourcepub fn is_signed_integer(self) -> bool
pub fn is_signed_integer(self) -> bool
Checks if this data type represents a signed integer.
Returns true only for signed integer variants.
§Returns
true if the data type is a signed integer, false otherwise.
§Examples
use slsl::DType;
// Signed integer types
assert!(DType::Int8.is_signed_integer());
assert!(DType::Int32.is_signed_integer());
assert!(DType::Int64.is_signed_integer());
// Non-signed integer types
assert!(!DType::Uint32.is_signed_integer());
assert!(!DType::Fp32.is_signed_integer());
assert!(!DType::Bool.is_signed_integer());Sourcepub fn is_unsigned_integer(self) -> bool
pub fn is_unsigned_integer(self) -> bool
Checks if this data type represents an unsigned integer.
Returns true only for unsigned integer variants.
§Returns
true if the data type is an unsigned integer, false otherwise.
§Examples
use slsl::DType;
// Unsigned integer types
assert!(DType::Uint8.is_unsigned_integer());
assert!(DType::Uint32.is_unsigned_integer());
assert!(DType::Uint64.is_unsigned_integer());
// Non-unsigned integer types
assert!(!DType::Int32.is_unsigned_integer());
assert!(!DType::Fp32.is_unsigned_integer());
assert!(!DType::Bool.is_unsigned_integer());Trait Implementations§
Source§impl Ord for DType
impl Ord for DType
Source§impl PartialOrd for DType
impl PartialOrd for DType
impl Copy for DType
impl Eq for DType
impl StructuralPartialEq for DType
Auto Trait Implementations§
impl Freeze for DType
impl RefUnwindSafe for DType
impl Send for DType
impl Sync for DType
impl Unpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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