oarust 0.9.0

GPU-first semantic computing engine written in Rust
// @generated by tool/gen/fn/generate.py; DO NOT EDIT.
// schemas=matrix_elemwise.json,matrix_blas.json,matrix_reduce.json,matrix_rng.json,matrix_index.json,matrix_view.json schema_version=1 generator_version=64
// schema_sha256=c242fe54ba3c1a01f423c995c847a717188eb5c66addecfa27eb0870eb928c0d
use crate::matrix::{MoeExpertPlan, TopKResult};
use crate::{Matrix, Result};

impl Matrix {
	/// Add two matrices elementwise using multidirectional broadcasting.
	///
	/// Delegates to [`crate::matrix::add`].
	pub fn add(&self, right: &Matrix) -> Result<Self> {
		crate::matrix::add(self, right)
	}

	/// Subtract two FP32 matrices elementwise using multidirectional broadcasting.
	///
	/// Delegates to [`crate::matrix::sub`].
	pub fn sub(&self, right: &Matrix) -> Result<Self> {
		crate::matrix::sub(self, right)
	}

	/// Multiply two FP32 matrices elementwise.
	///
	/// Delegates to [`crate::matrix::mul`].
	pub fn mul(&self, right: &Matrix) -> Result<Self> {
		crate::matrix::mul(self, right)
	}

	/// Divide two FP32 matrices elementwise using multidirectional broadcasting.
	///
	/// Delegates to [`crate::matrix::div`].
	pub fn div(&self, right: &Matrix) -> Result<Self> {
		crate::matrix::div(self, right)
	}

	/// Multiply every FP32 matrix element by a scalar.
	///
	/// Delegates to [`crate::matrix::scale`].
	pub fn scale(&self, scalar: f32) -> Result<Self> {
		crate::matrix::scale(self, scalar)
	}

	/// Negate every FP32 matrix element.
	///
	/// Delegates to [`crate::matrix::neg`].
	pub fn neg(&self) -> Result<Self> {
		crate::matrix::neg(self)
	}

	/// Take the absolute value of every FP32 matrix element.
	///
	/// Delegates to [`crate::matrix::abs`].
	pub fn abs(&self) -> Result<Self> {
		crate::matrix::abs(self)
	}

	/// Take the natural logarithm of every FP32 matrix element.
	///
	/// Delegates to [`crate::matrix::log`].
	pub fn log(&self) -> Result<Self> {
		crate::matrix::log(self)
	}

	/// Take the square root of every FP32 matrix element.
	///
	/// Delegates to [`crate::matrix::sqrt`].
	pub fn sqrt(&self) -> Result<Self> {
		crate::matrix::sqrt(self)
	}

	/// Raise every FP32 matrix element to a scalar exponent.
	///
	/// Delegates to [`crate::matrix::pow`].
	pub fn pow(&self, exponent: f32) -> Result<Self> {
		crate::matrix::pow(self, exponent)
	}

	/// Add a scalar to every FP32 matrix element.
	///
	/// Delegates to [`crate::matrix::add_scalar`].
	pub fn add_scalar(&self, scalar: f32) -> Result<Self> {
		crate::matrix::add_scalar(self, scalar)
	}

	/// Subtract a scalar from every FP32 matrix element.
	///
	/// Delegates to [`crate::matrix::sub_scalar`].
	pub fn sub_scalar(&self, scalar: f32) -> Result<Self> {
		crate::matrix::sub_scalar(self, scalar)
	}

	/// Divide every FP32 matrix element by a scalar.
	///
	/// Delegates to [`crate::matrix::div_scalar`].
	pub fn div_scalar(&self, scalar: f32) -> Result<Self> {
		crate::matrix::div_scalar(self, scalar)
	}

	/// Take the exponential of every FP32 matrix element.
	///
	/// Delegates to [`crate::matrix::exp`].
	pub fn exp(&self) -> Result<Self> {
		crate::matrix::exp(self)
	}

	/// Take the sine of every FP32 matrix element.
	///
	/// Delegates to [`crate::matrix::sin`].
	pub fn sin(&self) -> Result<Self> {
		crate::matrix::sin(self)
	}

	/// Take the cosine of every FP32 matrix element.
	///
	/// Delegates to [`crate::matrix::cos`].
	pub fn cos(&self) -> Result<Self> {
		crate::matrix::cos(self)
	}

	/// Take the reciprocal of every FP32 matrix element.
	///
	/// Delegates to [`crate::matrix::reciprocal`].
	pub fn reciprocal(&self) -> Result<Self> {
		crate::matrix::reciprocal(self)
	}

	/// Cap every FP32 matrix element at an upper bound.
	///
	/// Delegates to [`crate::matrix::clamp_max`].
	pub fn clamp_max(&self, maximum: f32) -> Result<Self> {
		crate::matrix::clamp_max(self, maximum)
	}

	/// Raise every FP32 matrix element to a lower bound.
	///
	/// Delegates to [`crate::matrix::clamp_min`].
	pub fn clamp_min(&self, minimum: f32) -> Result<Self> {
		crate::matrix::clamp_min(self, minimum)
	}

	/// Deep-copy a dense matrix into independent device storage.
	///
	/// Delegates to [`crate::matrix::copy`].
	pub fn copy(&self) -> Result<Self> {
		crate::matrix::copy(self)
	}

	/// Multiply A by the transpose of B using the OA weight-layout convention.
	///
	/// Delegates to [`crate::matrix::mat_mul_nt`].
	pub fn mat_mul_nt(&self, right: &Matrix) -> Result<Self> {
		crate::matrix::mat_mul_nt(self, right)
	}

	/// Delegates to [`crate::matrix::softmax`].
	pub fn softmax(&self, dim: i32) -> Result<Self> {
		crate::matrix::softmax(self, dim)
	}

	/// Delegates to [`crate::matrix::log_softmax`].
	pub fn log_softmax(&self, dim: i32) -> Result<Self> {
		crate::matrix::log_softmax(self, dim)
	}

	/// Delegates to [`crate::matrix::sum`].
	pub fn sum(&self, dim: i32) -> Result<Self> {
		crate::matrix::sum(self, dim)
	}

	/// Delegates to [`crate::matrix::categorical_accuracy_count`].
	pub fn categorical_accuracy_count(&self, labels: &Matrix) -> Result<Self> {
		crate::matrix::categorical_accuracy_count(self, labels)
	}

	/// Delegates to [`crate::matrix::masked_categorical_accuracy_count`].
	pub fn masked_categorical_accuracy_count(&self, labels: &Matrix, mask: &Matrix) -> Result<Self> {
		crate::matrix::masked_categorical_accuracy_count(self, labels, mask)
	}

	/// Delegates to [`crate::matrix::philox_uniform`].
	pub fn philox_uniform(&self, low: f32, high: f32, seed: u64) -> Result<Self> {
		crate::matrix::philox_uniform(self, low, high, seed)
	}

	/// Delegates to [`crate::matrix::philox_normal`].
	pub fn philox_normal(&self, mean: f32, stddev: f32, seed: u64) -> Result<Self> {
		crate::matrix::philox_normal(self, mean, stddev, seed)
	}

	/// Delegates to [`crate::matrix::dropout`].
	pub fn dropout(&self, probability: f32, seed: u64) -> Result<Self> {
		crate::matrix::dropout(self, probability, seed)
	}

	/// Delegates to [`crate::matrix::sample_logits`].
	pub fn sample_logits(&self, temperature: f32, top_k: i32, top_p: f32, seed: u64) -> Result<Self> {
		crate::matrix::sample_logits(self, temperature, top_k, top_p, seed)
	}

	/// Delegates to [`crate::matrix::top_k`].
	pub fn top_k(&self, k: i32, dim: i32) -> Result<TopKResult> {
		crate::matrix::top_k(self, k, dim)
	}

	/// Delegates to [`crate::matrix::top_k_mask`].
	pub fn top_k_mask(&self, num_experts: usize) -> Result<Self> {
		crate::matrix::top_k_mask(self, num_experts)
	}

	/// Delegates to [`crate::matrix::moe_expert_plan`].
	pub fn moe_expert_plan(&self, num_experts: usize) -> Result<MoeExpertPlan> {
		crate::matrix::moe_expert_plan(self, num_experts)
	}

	/// Delegates to [`crate::matrix::moe_routing_bias_update`].
	pub fn moe_routing_bias_update(
		&self,
		bias: &Matrix,
		experts_per_token: usize,
		gamma: f32,
	) -> Result<()> {
		crate::matrix::moe_routing_bias_update(self, bias, experts_per_token, gamma)
	}

	/// Delegates to [`crate::matrix::slice`].
	pub fn slice(&self, dim: i32, start: i64, end: i64) -> Result<Self> {
		crate::matrix::slice(self, dim, start, end)
	}

	/// Delegates to [`crate::matrix::repeat_interleave`].
	pub fn repeat_interleave(&self, repeats: usize, dim: i32) -> Result<Self> {
		crate::matrix::repeat_interleave(self, repeats, dim)
	}

	/// Delegates to [`crate::matrix::gather`].
	pub fn gather(&self, indices: &Matrix) -> Result<Self> {
		crate::matrix::gather(self, indices)
	}

	/// Delegates to [`crate::matrix::gather_last_dim`].
	pub fn gather_last_dim(&self, indices: &Matrix) -> Result<Self> {
		crate::matrix::gather_last_dim(self, indices)
	}

	/// Delegates to [`crate::matrix::transpose`].
	pub fn transpose(&self, dim0: i32, dim1: i32) -> Result<Self> {
		crate::matrix::transpose(self, dim0, dim1)
	}

	/// Delegates to [`crate::matrix::equal`].
	pub fn equal(&self, value: f32) -> Result<Self> {
		crate::matrix::equal(self, value)
	}

	/// Delegates to [`crate::matrix::reshape`].
	pub fn reshape(&self, shape: impl Into<Vec<usize>>) -> Result<Self> {
		crate::matrix::reshape(self, shape)
	}
}

const _: fn(&Matrix, &Matrix) -> Result<Matrix> = crate::matrix::add;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = Matrix::add;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = crate::matrix::sub;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = Matrix::sub;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = crate::matrix::mul;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = Matrix::mul;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = crate::matrix::div;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = Matrix::div;
const _: fn(&Matrix, f32) -> Result<Matrix> = crate::matrix::scale;
const _: fn(&Matrix, f32) -> Result<Matrix> = Matrix::scale;
const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::neg;
const _: fn(&Matrix) -> Result<Matrix> = Matrix::neg;
const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::abs;
const _: fn(&Matrix) -> Result<Matrix> = Matrix::abs;
const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::log;
const _: fn(&Matrix) -> Result<Matrix> = Matrix::log;
const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::sqrt;
const _: fn(&Matrix) -> Result<Matrix> = Matrix::sqrt;
const _: fn(&Matrix, f32) -> Result<Matrix> = crate::matrix::pow;
const _: fn(&Matrix, f32) -> Result<Matrix> = Matrix::pow;
const _: fn(&Matrix, f32) -> Result<Matrix> = crate::matrix::add_scalar;
const _: fn(&Matrix, f32) -> Result<Matrix> = Matrix::add_scalar;
const _: fn(&Matrix, f32) -> Result<Matrix> = crate::matrix::sub_scalar;
const _: fn(&Matrix, f32) -> Result<Matrix> = Matrix::sub_scalar;
const _: fn(&Matrix, f32) -> Result<Matrix> = crate::matrix::div_scalar;
const _: fn(&Matrix, f32) -> Result<Matrix> = Matrix::div_scalar;
const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::exp;
const _: fn(&Matrix) -> Result<Matrix> = Matrix::exp;
const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::sin;
const _: fn(&Matrix) -> Result<Matrix> = Matrix::sin;
const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::cos;
const _: fn(&Matrix) -> Result<Matrix> = Matrix::cos;
const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::reciprocal;
const _: fn(&Matrix) -> Result<Matrix> = Matrix::reciprocal;
const _: fn(&Matrix, f32) -> Result<Matrix> = crate::matrix::clamp_max;
const _: fn(&Matrix, f32) -> Result<Matrix> = Matrix::clamp_max;
const _: fn(&Matrix, f32) -> Result<Matrix> = crate::matrix::clamp_min;
const _: fn(&Matrix, f32) -> Result<Matrix> = Matrix::clamp_min;
const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::copy;
const _: fn(&Matrix) -> Result<Matrix> = Matrix::copy;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = crate::matrix::mat_mul_nt;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = Matrix::mat_mul_nt;
const _: fn(&Matrix, i32) -> Result<Matrix> = crate::matrix::softmax;
const _: fn(&Matrix, i32) -> Result<Matrix> = Matrix::softmax;
const _: fn(&Matrix, i32) -> Result<Matrix> = crate::matrix::log_softmax;
const _: fn(&Matrix, i32) -> Result<Matrix> = Matrix::log_softmax;
const _: fn(&Matrix, i32) -> Result<Matrix> = crate::matrix::sum;
const _: fn(&Matrix, i32) -> Result<Matrix> = Matrix::sum;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = crate::matrix::categorical_accuracy_count;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = Matrix::categorical_accuracy_count;
const _: fn(&Matrix, &Matrix, &Matrix) -> Result<Matrix> =
	crate::matrix::masked_categorical_accuracy_count;
const _: fn(&Matrix, &Matrix, &Matrix) -> Result<Matrix> =
	Matrix::masked_categorical_accuracy_count;
const _: fn(&Matrix, f32, f32, u64) -> Result<Matrix> = crate::matrix::philox_uniform;
const _: fn(&Matrix, f32, f32, u64) -> Result<Matrix> = Matrix::philox_uniform;
const _: fn(&Matrix, f32, f32, u64) -> Result<Matrix> = crate::matrix::philox_normal;
const _: fn(&Matrix, f32, f32, u64) -> Result<Matrix> = Matrix::philox_normal;
const _: fn(&Matrix, f32, u64) -> Result<Matrix> = crate::matrix::dropout;
const _: fn(&Matrix, f32, u64) -> Result<Matrix> = Matrix::dropout;
const _: fn(&Matrix, f32, i32, f32, u64) -> Result<Matrix> = crate::matrix::sample_logits;
const _: fn(&Matrix, f32, i32, f32, u64) -> Result<Matrix> = Matrix::sample_logits;
const _: fn(&Matrix, i32, i32) -> Result<TopKResult> = crate::matrix::top_k;
const _: fn(&Matrix, i32, i32) -> Result<TopKResult> = Matrix::top_k;
const _: fn(&Matrix, usize) -> Result<Matrix> = crate::matrix::top_k_mask;
const _: fn(&Matrix, usize) -> Result<Matrix> = Matrix::top_k_mask;
const _: fn(&Matrix, usize) -> Result<MoeExpertPlan> = crate::matrix::moe_expert_plan;
const _: fn(&Matrix, usize) -> Result<MoeExpertPlan> = Matrix::moe_expert_plan;
const _: fn(&Matrix, &Matrix, usize, f32) -> Result<()> = crate::matrix::moe_routing_bias_update;
const _: fn(&Matrix, &Matrix, usize, f32) -> Result<()> = Matrix::moe_routing_bias_update;
const _: fn(&Matrix, i32, i64, i64) -> Result<Matrix> = crate::matrix::slice;
const _: fn(&Matrix, i32, i64, i64) -> Result<Matrix> = Matrix::slice;
const _: fn(&Matrix, usize, i32) -> Result<Matrix> = crate::matrix::repeat_interleave;
const _: fn(&Matrix, usize, i32) -> Result<Matrix> = Matrix::repeat_interleave;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = crate::matrix::gather;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = Matrix::gather;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = crate::matrix::gather_last_dim;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = Matrix::gather_last_dim;
const _: fn(&Matrix, i32, i32) -> Result<Matrix> = crate::matrix::transpose;
const _: fn(&Matrix, i32, i32) -> Result<Matrix> = Matrix::transpose;
const _: fn(&Matrix, f32) -> Result<Matrix> = crate::matrix::equal;
const _: fn(&Matrix, f32) -> Result<Matrix> = Matrix::equal;