is_broadcast_compatible

Function is_broadcast_compatible 

Source
pub fn is_broadcast_compatible(shape1: &[usize], shape2: &[usize]) -> bool
Expand description

Check if two shapes are broadcast compatible

§Arguments

  • shape1 - First shape as a slice
  • shape2 - Second shape as a slice

§Returns

true if the shapes are broadcast compatible, false otherwise

§Examples

use scirs2_core::ndarray_ext::is_broadcast_compatible;

assert!(is_broadcast_compatible(&[2, 3], &[3]));
// This example has dimensions that don't match (5 vs 3 in dimension 0)
// and aren't broadcasting compatible (neither is 1)
assert!(!is_broadcast_compatible(&[5, 1, 4], &[3, 1, 1]));
assert!(!is_broadcast_compatible(&[2, 3], &[4]));