BroadcastOps

Trait BroadcastOps 

Source
pub trait BroadcastOps<A: Clone + Copy + 'static + Send + Sync> {
    // Required method
    fn broadcast_op<F>(
        &self,
        other: &Self,
        f: F,
    ) -> CoreResult<MemoryMappedArray<A>>
       where F: Fn(A, A) -> A + Send + Sync;
}
Expand description

Trait for broadcasting operations between memory-mapped arrays of different shapes.

This trait provides methods for performing broadcasting operations between memory-mapped arrays without unnecessary memory allocations or copies.

Required Methods§

Source

fn broadcast_op<F>( &self, other: &Self, f: F, ) -> CoreResult<MemoryMappedArray<A>>
where F: Fn(A, A) -> A + Send + Sync,

Broadcasts an operation between two arrays of compatible shapes.

Follows the NumPy broadcasting rules:

  1. If arrays don’t have the same rank, prepend shape with 1s
  2. Two dimensions are compatible if:
    • They are equal, or
    • One of them is 1
§Arguments
  • other - Another memory-mapped array with a compatible shape
  • f - A function that takes two elements (one from each array) and returns a new element
§Returns

A new memory-mapped array containing the result of the broadcasted operation

§Example
// Broadcast and multiply
let result = mmap1.broadcast_op(&mmap2, |a, b| a * b);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<A: Clone + Copy + 'static + Send + Sync + Zero> BroadcastOps<A> for MemoryMappedArray<A>