#[doc(inline)]
pub use g_core::{
arange_f32, eye, from_slice_f32, from_slice_f64, from_slice_i64, full_f32, linspace_f32, ones,
randn_f32, zeros, Device, Dtype, Error, ErrorKind, Result, Tensor,
};
#[doc(inline)]
pub use g_ad::{
backward, detach, embedding_fused, fused_block, gated_scan, grad, masked_ce, rms_norm,
slice_tracked, stop_gradient, zero_grad,
};
#[doc(inline)]
pub use g_nn::{
categorical_entropy, categorical_log_prob, cross_entropy, embedding, layer_norm, linear,
log_softmax, mse_loss, nll_loss, one_hot, softmax, whiten, AdamW, Reduce, Sgd,
};
pub fn add(a: &Tensor, b: &Tensor) -> Result<Tensor> {
g_ad::add(a, b)
}
pub fn sub(a: &Tensor, b: &Tensor) -> Result<Tensor> {
g_ad::sub(a, b)
}
pub fn mul(a: &Tensor, b: &Tensor) -> Result<Tensor> {
g_ad::mul(a, b)
}
pub fn div(a: &Tensor, b: &Tensor) -> Result<Tensor> {
g_ad::div(a, b)
}
pub fn mul_scalar(a: &Tensor, s: f64) -> Result<Tensor> {
g_ad::mul_scalar(a, s)
}
pub fn neg(a: &Tensor) -> Result<Tensor> {
g_ad::neg(a)
}
pub fn matmul(a: &Tensor, b: &Tensor) -> Result<Tensor> {
g_ad::matmul(a, b)
}
pub fn relu(a: &Tensor) -> Result<Tensor> {
g_ad::relu(a)
}
pub fn tanh(a: &Tensor) -> Result<Tensor> {
g_ad::tanh(a)
}
pub fn exp(a: &Tensor) -> Result<Tensor> {
g_ad::exp(a)
}
pub fn log(a: &Tensor) -> Result<Tensor> {
g_ad::log(a)
}
pub fn sqrt(a: &Tensor) -> Result<Tensor> {
g_ad::sqrt(a)
}
pub fn abs(a: &Tensor) -> Result<Tensor> {
g_ad::abs(a)
}
pub fn sigmoid(a: &Tensor) -> Result<Tensor> {
g_ad::sigmoid(a)
}
pub fn silu(a: &Tensor) -> Result<Tensor> {
g_ad::silu(a)
}
pub fn gelu(a: &Tensor) -> Result<Tensor> {
g_ad::gelu(a)
}
pub fn softplus(a: &Tensor) -> Result<Tensor> {
g_ad::softplus(a)
}
pub fn leaky_relu(a: &Tensor, slope: f64) -> Result<Tensor> {
g_ad::leaky_relu(a, slope)
}
pub fn clamp(a: &Tensor, min: f64, max: f64) -> Result<Tensor> {
g_ad::clamp(a, min, max)
}
pub fn sum(x: &Tensor, axes: Option<&[isize]>, keepdims: bool) -> Result<Tensor> {
g_ad::sum(x, axes, keepdims)
}
pub fn mean(x: &Tensor, axes: Option<&[isize]>, keepdims: bool) -> Result<Tensor> {
g_ad::mean(x, axes, keepdims)
}
pub fn cat(tensors: &[&Tensor], axis: isize) -> Result<Tensor> {
g_ad::cat(tensors, axis)
}
pub fn stack(tensors: &[&Tensor], axis: isize) -> Result<Tensor> {
g_ad::stack(tensors, axis)
}
pub fn amax(x: &Tensor, axis: isize, keepdims: bool) -> Result<Tensor> {
g_ad::amax(x, axis, keepdims)
}
pub fn gather(x: &Tensor, axis: isize, index: &Tensor) -> Result<Tensor> {
g_ad::gather(x, axis, index)
}
pub fn unsqueeze(x: &Tensor, axis: isize) -> Result<Tensor> {
g_ad::unsqueeze(x, axis)
}
pub fn scatter_add(dst: &Tensor, axis: isize, index: &Tensor, src: &Tensor) -> Result<Tensor> {
g_cpu::scatter_add(dst, axis, index, src)
}
pub fn variance(x: &Tensor, axes: Option<&[isize]>, keepdims: bool) -> Result<Tensor> {
g_ad::variance(x, axes, keepdims)
}
pub fn stddev(x: &Tensor, axes: Option<&[isize]>, keepdims: bool) -> Result<Tensor> {
g_ad::stddev(x, axes, keepdims)
}
pub fn logsumexp(x: &Tensor, axis: isize, keepdims: bool) -> Result<Tensor> {
g_ad::logsumexp(x, axis, keepdims)
}
pub fn maximum(a: &Tensor, b: &Tensor) -> Result<Tensor> {
g_ad::maximum(a, b)
}
pub fn minimum(a: &Tensor, b: &Tensor) -> Result<Tensor> {
g_ad::minimum(a, b)
}
pub fn take(x: &Tensor, axis: isize, index: &Tensor) -> Result<Tensor> {
g_ad::take(x, axis, index)
}
pub fn transpose(x: &Tensor) -> Result<Tensor> {
g_ad::transpose(x)
}
pub fn reshape(x: &Tensor, shape: &[isize]) -> Result<Tensor> {
g_ad::reshape(x, shape)
}
pub trait TensorExt {
fn add(&self, other: &Tensor) -> Result<Tensor>;
fn sub(&self, other: &Tensor) -> Result<Tensor>;
fn mul(&self, other: &Tensor) -> Result<Tensor>;
fn div(&self, other: &Tensor) -> Result<Tensor>;
fn matmul(&self, other: &Tensor) -> Result<Tensor>;
fn relu(&self) -> Result<Tensor>;
fn tanh(&self) -> Result<Tensor>;
fn gelu(&self) -> Result<Tensor>;
fn sigmoid(&self) -> Result<Tensor>;
fn exp(&self) -> Result<Tensor>;
fn log(&self) -> Result<Tensor>;
fn sum(&self, axes: Option<&[isize]>, keepdims: bool) -> Result<Tensor>;
fn mean(&self, axes: Option<&[isize]>, keepdims: bool) -> Result<Tensor>;
fn linear(&self, w: &Tensor, b: Option<&Tensor>) -> Result<Tensor>;
fn softmax(&self, axis: isize) -> Result<Tensor>;
fn log_softmax(&self, axis: isize) -> Result<Tensor>;
fn mse_loss(&self, target: &Tensor, reduction: Reduce) -> Result<Tensor>;
fn backward(&self) -> Result<Vec<(Tensor, Tensor)>>;
fn stop_gradient(&self) -> Result<Tensor>;
fn t(&self) -> Result<Tensor>;
}
impl TensorExt for Tensor {
fn add(&self, other: &Tensor) -> Result<Tensor> {
add(self, other)
}
fn sub(&self, other: &Tensor) -> Result<Tensor> {
sub(self, other)
}
fn mul(&self, other: &Tensor) -> Result<Tensor> {
mul(self, other)
}
fn div(&self, other: &Tensor) -> Result<Tensor> {
div(self, other)
}
fn matmul(&self, other: &Tensor) -> Result<Tensor> {
matmul(self, other)
}
fn relu(&self) -> Result<Tensor> {
relu(self)
}
fn tanh(&self) -> Result<Tensor> {
tanh(self)
}
fn gelu(&self) -> Result<Tensor> {
gelu(self)
}
fn sigmoid(&self) -> Result<Tensor> {
sigmoid(self)
}
fn exp(&self) -> Result<Tensor> {
exp(self)
}
fn log(&self) -> Result<Tensor> {
log(self)
}
fn sum(&self, axes: Option<&[isize]>, keepdims: bool) -> Result<Tensor> {
sum(self, axes, keepdims)
}
fn mean(&self, axes: Option<&[isize]>, keepdims: bool) -> Result<Tensor> {
mean(self, axes, keepdims)
}
fn linear(&self, w: &Tensor, b: Option<&Tensor>) -> Result<Tensor> {
linear(self, w, b)
}
fn softmax(&self, axis: isize) -> Result<Tensor> {
softmax(self, axis)
}
fn log_softmax(&self, axis: isize) -> Result<Tensor> {
log_softmax(self, axis)
}
fn mse_loss(&self, target: &Tensor, reduction: Reduce) -> Result<Tensor> {
mse_loss(self, target, reduction)
}
fn backward(&self) -> Result<Vec<(Tensor, Tensor)>> {
backward(self)
}
fn stop_gradient(&self) -> Result<Tensor> {
stop_gradient(self)
}
fn t(&self) -> Result<Tensor> {
transpose(self)
}
}
#[cfg(feature = "gpu")]
pub use g_apple;
#[cfg(feature = "gpu")]
pub fn gpu_available() -> bool {
g_apple::gpu_available()
}
#[cfg(feature = "gpu")]
pub fn gpu_device_count() -> usize {
g_apple::gpu_device_count()
}
#[cfg(feature = "gpu")]
pub fn gpu_device_name() -> Option<String> {
g_apple::gpu_device_name()
}
#[cfg(feature = "gpu")]
pub fn gpu_device_names() -> Vec<String> {
g_apple::gpu_device_names()
}
#[cfg(feature = "gpu")]
pub fn gpu_all_device_names() -> Vec<String> {
g_apple::gpu_all_device_names()
}
#[cfg(feature = "gpu")]
pub fn set_include_integrated(include: bool) {
g_apple::set_include_integrated(include);
}
pub mod prelude {
pub use crate::TensorExt;
pub use crate::{
add, arange_f32, backward, cat, cross_entropy, detach, from_slice_f32, gated_scan, gelu,
grad, linear, matmul, mse_loss, randn_f32, relu, rms_norm, sigmoid, softmax, stop_gradient,
sum, tanh, zeros, Device, Dtype, Reduce, Result, Tensor,
};
}