DynArray

Enum DynArray 

Source
pub enum DynArray {
    F32(Array<f32>),
    F64(Array<f64>),
    I32(Array<i32>),
    I8(Array<i8>),
    U8(Array<u8>),
    Bool(Array<bool>),
}
Expand description

Array con tipo borrado (type-erased) que puede contener cualquier dtype

Similar a como NumPy maneja arrays internamente: el dtype se conoce en runtime.

§Ejemplo

let a = DynArray::F32(Array::new(vec![2], vec![1.0, 2.0]));
let b = DynArray::I32(Array::new(vec![2], vec![3, 4]));
 
// Operaciones devuelven DynArray con tipo promovido
let result = ops::add_dyn(&a, &b)?; // -> DynArray::F32
 
// Pattern matching para extraer el tipo concreto
match result {
    DynArray::F32(arr) => println!("f32: {:?}", arr.data),
    DynArray::I32(arr) => println!("i32: {:?}", arr.data),
    _ => {}
}

Variants§

§

F32(Array<f32>)

§

F64(Array<f64>)

§

I32(Array<i32>)

§

I8(Array<i8>)

§

U8(Array<u8>)

§

Bool(Array<bool>)

Implementations§

Source§

impl DynArray

Source

pub fn dtype(&self) -> DType

Obtener el DType de este array

Source

pub fn shape(&self) -> &[usize]

Obtener el shape de este array

Source

pub fn len(&self) -> usize

Número de elementos

Source

pub fn is_empty(&self) -> bool

Si el array está vacío

Source

pub fn to_f32(&self) -> Array<f32>

Convertir a Array (con conversión si es necesario)

Source

pub fn map_data<F, R>(&self, f: F) -> Result<R>
where F: FnOnce(&dyn Any) -> Result<R>,

Aplicar una función a los datos internos

Source

pub fn into_typed<T: DTypeValue>(self) -> Result<Array<T>>

Extract the inner Array with zero-copy if types match, or cast if they don’t.

§Automatic Casting

If the internal dtype differs from T, this function will automatically cast/convert the data to T. This enables “automatic narrowing” (F64 -> F32) or normal promotion casting.

Source

pub fn from_generic<T: DTypeValue>(arr: Array<T>) -> Self

Envolver un Array genérico en DynArray basándose en su dtype

Esto usa unsafe para transmute, pero es seguro porque verificamos el dtype

Trait Implementations§

Source§

impl Clone for DynArray

Source§

fn clone(&self) -> DynArray

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for DynArray

Source§

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

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

impl From<Array<bool>> for DynArray

Source§

fn from(arr: Array<bool>) -> Self

Converts to this type from the input type.
Source§

impl From<Array<f64>> for DynArray

Source§

fn from(arr: Array<f64>) -> Self

Converts to this type from the input type.
Source§

impl From<Array<i32>> for DynArray

Source§

fn from(arr: Array<i32>) -> Self

Converts to this type from the input type.
Source§

impl From<Array<i8>> for DynArray

Source§

fn from(arr: Array<i8>) -> Self

Converts to this type from the input type.
Source§

impl From<Array<u8>> for DynArray

Source§

fn from(arr: Array<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<Array> for DynArray

Source§

fn from(arr: Array<f32>) -> Self

Converts to this type from the input type.
Source§

impl TryFrom<DynArray> for Array<f32>

Source§

type Error = Error

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

fn try_from(dyn_arr: DynArray) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<DynArray> for Array<bool>

Source§

type Error = Error

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

fn try_from(dyn_arr: DynArray) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<DynArray> for Array<f64>

Source§

type Error = Error

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

fn try_from(dyn_arr: DynArray) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<DynArray> for Array<i32>

Source§

type Error = Error

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

fn try_from(dyn_arr: DynArray) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<DynArray> for Array<i8>

Source§

type Error = Error

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

fn try_from(dyn_arr: DynArray) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<DynArray> for Array<u8>

Source§

type Error = Error

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

fn try_from(dyn_arr: DynArray) -> Result<Self>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

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

§

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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
§

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,