pub fn erased_broadcast_mul_into_uninit(
dtype: KernelDType,
dest: &mut ErasedRawStridedUninitMut<'_>,
lhs: &ErasedRawStridedPtr<'_>,
lhs_axes: &[usize],
rhs: &ErasedRawStridedPtr<'_>,
rhs_axes: &[usize],
exec: Exec<'_>,
) -> Result<()>Expand description
Broadcast two same-dtype operands onto the destination axes and multiply them into uninitialized storage.
lhs_axes[k] names the destination axis that lhs axis k maps to; each
mapped extent must equal the destination extent or be one, and unmapped
destination axes broadcast. Supported dtypes are f32, f64, c32,
c64, and the signed integers, whose products wrap on overflow.
§Examples
use core::mem::MaybeUninit;
use strided_kernel::{
erased_broadcast_mul_into_uninit, ErasedRawStridedPtr, ErasedRawStridedRef,
ErasedRawStridedUninitMut, Exec, KernelDType,
};
// Outer product: out[i, j] = a[i] * b[j], column-major 2 x 3 output.
let a = [1.0_f64, 2.0];
let b = [10.0_f64, 20.0, 30.0];
let a = ErasedRawStridedRef::from_slice(&a, &[2], &[1], 0).unwrap();
let b = ErasedRawStridedRef::from_slice(&b, &[3], &[1], 0).unwrap();
let mut out = [MaybeUninit::<f64>::uninit(); 6];
let mut dest =
ErasedRawStridedUninitMut::from_uninit_slice(&mut out, &[2, 3], &[1, 2], 0).unwrap();
erased_broadcast_mul_into_uninit(
KernelDType::F64,
&mut dest,
&ErasedRawStridedPtr::from_ref(&a),
&[0],
&ErasedRawStridedPtr::from_ref(&b),
&[1],
Exec::serial(),
)
.unwrap();
// SAFETY: a successful call initializes every reachable element.
let out = unsafe { out.map(|value| value.assume_init()) };
assert_eq!(out, [10.0, 20.0, 20.0, 40.0, 30.0, 60.0]);§Errors
Returns StridedError::DTypeMismatch when dest, lhs, or rhs does
not carry dtype, StridedError::OverlappingInputOutput when either
input allocation overlaps the destination,
StridedError::InvalidBoolByte when an input holds a bool byte other
than 0 or 1, StridedError::RankMismatch when lhs_axes or rhs_axes
is not one axis per input dim, StridedError::InvalidAxis for a mapped
axis that is out of range or named twice,
StridedError::ShapeMismatch when a mapped input extent is neither the
destination extent nor one,
StridedError::NonInjectiveOutputLayout when the destination layout
cannot be proven to place logical elements on distinct offsets, and
StridedError::UnsupportedDType for bool. Validation completes before
any write.