Skip to main content

DType

Enum DType 

Source
pub enum DType {
    Scalar(ScalarDType),
    Vector {
        scalar: ScalarDType,
        count: usize,
    },
    Ptr {
        base: Box<DType>,
        addrspace: AddrSpace,
        size: Option<usize>,
        vcount: usize,
    },
    Image {
        kind: ImageKind,
        shape: Vec<usize>,
    },
}
Expand description

Data type including scalars, vectors, pointers, and images.

Variants§

§

Scalar(ScalarDType)

Scalar type (single value).

§

Vector

Vector type (SIMD).

Fields

§count: usize
§

Ptr

Pointer type. vcount is the vector count of the pointer itself (1 = scalar pointer, >1 = vector of pointers). This matches Tinygrad’s PtrDType.v field.

Fields

§base: Box<DType>
§addrspace: AddrSpace
§vcount: usize
§

Image

Image type (for texture operations).

Fields

§shape: Vec<usize>

Implementations§

Source§

impl DType

Source

pub fn can_safe_cast(from: Self, to: Self) -> bool

Check if casting from from to to is safe (preserves value).

Source

pub fn least_upper_dtype(dtypes: &[Self]) -> Option<Self>

Find the least upper bound type for a set of dtypes.

Returns the smallest type that all input types can be safely cast to.

Type promotion rules:

  • Scalar + Scalar → promoted Scalar
  • Ptr<T> + Ptr<T>Ptr<T> (same Ptr types)
  • Ptr<T> + Scalar(T)Scalar(T) (Ptr will be auto-loaded in codegen)
  • Ptr<T> + Scalar(U) → promoted Scalar (if T and U are compatible)
Source§

impl DType

Source

pub fn vec(&self, count: usize) -> Self

Create a vector type from this dtype.

Source

pub fn ptr(self, size: Option<usize>, addrspace: AddrSpace) -> Self

Create a pointer type from this dtype.

Source

pub fn scalar(&self) -> Option<ScalarDType>

Source

pub fn is_vector(&self) -> bool

Check if this is a vector type.

Source

pub fn is_image(&self) -> bool

Check if this is an image (texture) type.

Source

pub fn base(&self) -> ScalarDType

Get the base scalar type (works for both scalars and vectors).

Source

pub fn scalar_dtype(&self) -> DType

Get scalar DType (works on both Scalar and Vector).

Unlike base() which returns ScalarDType, this returns DType. This enables chaining with .vec().

§Examples
use svod_dtype::DType;

let vec_dtype = DType::Float32.vec(4);
assert_eq!(vec_dtype.scalar_dtype(), DType::Float32);

// Enable chaining: dtype.scalar_dtype().vec(new_count)
let new_vec = vec_dtype.scalar_dtype().vec(8);
assert_eq!(new_vec, DType::Float32.vec(8));
Source

pub fn with_base(&self, new_base: ScalarDType) -> Self

Create a new dtype with a different base scalar type, preserving vector count.

Useful for type conversions like bool→uint8 where the structure is preserved.

Source

pub fn with_ptr_base(&self, new_base: DType) -> Option<Self>

For Ptr types: replace the base dtype while preserving addrspace, size, and vcount. Returns None if not a Ptr.

Source

pub fn count(&self) -> usize

Get the vector count (1 for scalars).

Source

pub fn vcount(&self) -> usize

Get effective vectorization count (for pointers to vectors).

Source

pub fn bytes(&self) -> usize

Source

pub fn is_bool(&self) -> bool

Source

pub fn is_signed(&self) -> bool

Source

pub fn is_unsigned(&self) -> bool

Source

pub fn is_int(&self) -> bool

Source

pub fn is_float(&self) -> bool

Source

pub fn is_fp8(&self) -> bool

Source

pub fn min_value(&self) -> f64

Source

pub fn max_value(&self) -> f64

Source

pub fn c_style(&self) -> String

Source§

impl DType

Source

pub const fn bool_() -> Self

Source

pub const fn int8() -> Self

Source

pub const fn int16() -> Self

Source

pub const fn int32() -> Self

Source

pub const fn int64() -> Self

Source

pub const fn uint8() -> Self

Source

pub const fn uint16() -> Self

Source

pub const fn uint32() -> Self

Source

pub const fn uint64() -> Self

Source

pub const fn float16() -> Self

Source

pub const fn bfloat16() -> Self

Source

pub const fn float32() -> Self

Source

pub const fn float64() -> Self

Source

pub const fn void_() -> Self

Source

pub const fn index() -> Self

Source§

impl DType

Source

pub const Bool: Self

Source

pub const Int8: Self

Source

pub const Int16: Self

Source

pub const Int32: Self

Source

pub const Int64: Self

Source

pub const UInt8: Self

Source

pub const UInt16: Self

Source

pub const UInt32: Self

Source

pub const UInt64: Self

Source

pub const FP8E4M3: Self

Source

pub const FP8E5M2: Self

Source

pub const Float16: Self

Source

pub const BFloat16: Self

Source

pub const Float32: Self

Source

pub const Float64: Self

Source

pub const Void: Self

Source

pub const Index: Self

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 Debug for DType

Source§

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

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

impl<'de> Deserialize<'de> for DType

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<ScalarDType> for DType

Source§

fn from(scalar: ScalarDType) -> Self

Converts to this type from the input type.
Source§

impl Hash for DType

Source§

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

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for DType

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for DType

Source§

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 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<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<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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,