Trait ArrayProtocol

Source
pub trait ArrayProtocol:
    Any
    + Send
    + Sync {
    // Required methods
    fn array_function(
        &self,
        func: &ArrayFunction,
        _types: &[TypeId],
        _args: &[Box<dyn Any>],
        _kwargs: &HashMap<String, Box<dyn Any>>,
    ) -> Result<Box<dyn Any>, NotImplemented>;
    fn as_any(&self) -> &dyn Any;
    fn box_clone(&self) -> Box<dyn ArrayProtocol>;

    // Provided methods
    fn shape(&self) -> &[usize] { ... }
    fn dtype(&self) -> TypeId { ... }
}
Expand description

Trait for objects that can handle the array protocol.

This is similar to NumPy’s __array_function__ protocol.

Required Methods§

Source

fn array_function( &self, func: &ArrayFunction, _types: &[TypeId], _args: &[Box<dyn Any>], _kwargs: &HashMap<String, Box<dyn Any>>, ) -> Result<Box<dyn Any>, NotImplemented>

Implementation of the array protocol.

  • func - The function being called
  • types - The types of all arguments that implement ArrayProtocol
  • args - The arguments to the function
  • kwargs - Named arguments to the function

Returns Ok(result) if the operation is successful, or Err(NotImplemented) if the operation is not implemented for this type.

§Errors

Returns Err(NotImplemented) if the operation is not supported by this array type.

Source

fn as_any(&self) -> &dyn Any

Get the array as Any for downcasting

Source

fn box_clone(&self) -> Box<dyn ArrayProtocol>

Clone this array protocol object.

Provided Methods§

Source

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

Get the shape of the array (default implementation returns empty slice)

Source

fn dtype(&self) -> TypeId

Get the data type of the array (default implementation returns f64)

Trait Implementations§

Source§

impl Clone for Box<dyn ArrayProtocol>

Make Box<dyn ArrayProtocol> cloneable via box_clone

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more

Implementors§

Source§

impl<T, A> ArrayProtocol for JITEnabledArray<T, A>
where T: Send + Sync + 'static, A: ArrayProtocol + Clone + Send + Sync + 'static,

Source§

impl<T, D> ArrayProtocol for AutoDevice<T, D>
where T: Clone + Send + Sync + 'static + Zero + Div<f64, Output = T> + Default + Mul<Output = T> + Add<Output = T>, D: Dimension + RemoveAxis + 'static, SliceInfo<[SliceInfoElem; 1], Dim<[usize; 1]>, Dim<[usize; 1]>>: SliceArg<D>, SliceInfo<[SliceInfoElem; 2], Dim<[usize; 2]>, Dim<[usize; 2]>>: SliceArg<D>,

Source§

impl<T, D> ArrayProtocol for MixedPrecisionArray<T, D>
where T: Clone + Float + Send + Sync + 'static, D: Dimension + Send + Sync + 'static,

Implement ArrayProtocol for MixedPrecisionArray.

Source§

impl<T, D> ArrayProtocol for DistributedNdarray<T, D>
where T: Clone + Send + Sync + 'static + Zero + Div<f64, Output = T> + Default + Add<Output = T> + Mul<Output = T>, D: Dimension + Clone + Send + Sync + 'static + RemoveAxis,

Source§

impl<T, D> ArrayProtocol for GPUNdarray<T, D>
where T: Clone + Send + Sync + 'static + Zero + Div<f64, Output = T> + Mul<Output = T> + Add<Output = T>, D: Dimension + Clone + Send + Sync + 'static + RemoveAxis,

Source§

impl<T, D> ArrayProtocol for NdarrayWrapper<T, D>
where T: Clone + Send + Sync + 'static, D: Dimension + Send + Sync + 'static,

Source§

impl<T: Clone + Send + Sync + 'static> ArrayProtocol for MockDistributedArray<T>

Source§

impl<T: Clone + Send + Sync + 'static> ArrayProtocol for MockGPUArray<T>