Skip to main content

TensorOps

Trait TensorOps 

Source
pub trait TensorOps: TensorBase {
Show 18 methods // Required methods fn add(&self, other: &Self) -> Self; fn sub(&self, other: &Self) -> Self; fn mul(&self, other: &Self) -> Self; fn div(&self, other: &Self) -> Self; fn matmul(&self, other: &Self) -> Self; fn transpose(&self, axes: Option<&[usize]>) -> Self; fn sum(&self, axes: Option<&[usize]>) -> Self; fn mean(&self, axes: Option<&[usize]>) -> Self; fn mul_scalar(&self, scalar: f64) -> Self; fn add_scalar(&self, scalar: f64) -> Self; fn map<F>(&self, f: F) -> Self where F: Fn(f64) -> f64 + Send + Sync; fn reshape(&self, new_shape: &[usize]) -> Self; fn slice(&self, axes: &[usize], ranges: &[Range<usize>]) -> Self; fn concat(&self, other: &Self, axis: usize) -> Self; fn max(&self) -> f64; fn min(&self) -> f64; fn norm(&self) -> f64; fn normalize(&self) -> Self;
}
Expand description

Tensor 操作 trait:定义数学运算

提供加法、乘法、矩阵乘法、转置等操作

Required Methods§

Source

fn add(&self, other: &Self) -> Self

张量加法

Source

fn sub(&self, other: &Self) -> Self

张量减法

Source

fn mul(&self, other: &Self) -> Self

逐元素乘法(Hadamard 积)

Source

fn div(&self, other: &Self) -> Self

逐元素除法

Source

fn matmul(&self, other: &Self) -> Self

矩阵乘法(仅适用于 2D 张量)

Source

fn transpose(&self, axes: Option<&[usize]>) -> Self

转置(交换维度)

Source

fn sum(&self, axes: Option<&[usize]>) -> Self

沿指定轴求和

Source

fn mean(&self, axes: Option<&[usize]>) -> Self

沿指定轴求均值

Source

fn mul_scalar(&self, scalar: f64) -> Self

逐元素乘以标量

Source

fn add_scalar(&self, scalar: f64) -> Self

逐元素加上标量

Source

fn map<F>(&self, f: F) -> Self
where F: Fn(f64) -> f64 + Send + Sync,

逐元素应用函数

Source

fn reshape(&self, new_shape: &[usize]) -> Self

重塑张量形状

Source

fn slice(&self, axes: &[usize], ranges: &[Range<usize>]) -> Self

切片操作

Source

fn concat(&self, other: &Self, axis: usize) -> Self

拼接两个张量

Source

fn max(&self) -> f64

获取最大值

Source

fn min(&self) -> f64

获取最小值

Source

fn norm(&self) -> f64

获取 L2 范数

Source

fn normalize(&self) -> Self

归一化到单位范数

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 TensorOps for DenseTensor

Available on crate feature tensor only.