use crate::into_scalar::Cast;
use crate::into_vec::IntoVec;
#[cfg(any(
all(not(target_feature = "avx2"), target_feature = "sse"),
target_arch = "arm",
target_arch = "aarch64",
target_feature = "neon"
))]
use crate::simd::_128bit::common::*;
#[cfg(target_feature = "avx2")]
use crate::simd::_256bit::common::*;
use crate::traits::SimdMath;
use crate::vectors::traits::SimdCompare;
use crate::vectors::traits::VecTrait;
use half::bf16;
use half::f16;
use hpt_macros::{
float_out_binary, float_out_binary_simd_with_lhs_scalar, float_out_binary_simd_with_rhs_scalar,
float_out_unary, impl_bitwise_out, impl_cmp, impl_eval, impl_normal_out_binary,
impl_normal_out_simd, impl_normal_out_simd_with_lhs_scalar,
impl_normal_out_simd_with_rhs_scalar, impl_normal_out_unary, impl_normal_out_unary_simd,
simd_cmp, simd_eval, simd_float_out_unary,
};
use num_complex::{Complex32, Complex64};
use num_traits::float::Float;
#[cfg(feature = "cuda")]
mod cuda_imports {
use super::*;
use crate::cuda_types::scalar::Scalar;
use hpt_macros::{
float_out_binary_cuda, float_out_unary_cuda, impl_cmp_cuda, impl_cuda_bitwise_out,
impl_cuda_normal_out_binary, impl_normal_out_unary_cuda,
};
float_out_binary_cuda!();
impl_cuda_normal_out_binary!();
impl_normal_out_unary_cuda!();
impl_cuda_bitwise_out!();
impl_cmp_cuda!();
float_out_unary_cuda!();
}
use hpt_macros::{float_out_binary_simd, simd_bitwise};
pub trait FloatOutBinary<RHS = Self> {
type Output;
fn _div(self, rhs: RHS) -> Self::Output;
fn _log(self, base: RHS) -> Self::Output;
fn _hypot(self, rhs: RHS) -> Self::Output;
fn _pow(self, rhs: RHS) -> Self::Output;
}
pub trait FloatOutBinaryPromote<RHS = Self> {
type Output;
type Intermediate;
}
pub trait FloatOutBinary2 {
fn __div(self, rhs: Self) -> Self;
fn __log(self, base: Self) -> Self;
fn __hypot(self, rhs: Self) -> Self;
fn __pow(self, rhs: Self) -> Self;
}
float_out_binary!();
float_out_binary_simd!();
float_out_binary_simd_with_rhs_scalar!();
float_out_binary_simd_with_lhs_scalar!();
pub trait NormalOut<RHS = Self> {
type Output;
fn _add(self, rhs: RHS) -> Self::Output;
fn _sub(self, rhs: RHS) -> Self::Output;
fn _mul_add(self, a: RHS, b: RHS) -> Self::Output;
fn _mul(self, rhs: RHS) -> Self::Output;
fn _rem(self, rhs: RHS) -> Self::Output;
fn _max(self, rhs: RHS) -> Self::Output;
fn _min(self, rhs: RHS) -> Self::Output;
fn _clamp(self, min: RHS, max: RHS) -> Self::Output;
}
pub trait NormalOut2 {
fn __add(self, rhs: Self) -> Self;
fn __sub(self, rhs: Self) -> Self;
fn __mul_add(self, a: Self, b: Self) -> Self;
fn __mul(self, rhs: Self) -> Self;
fn __rem(self, rhs: Self) -> Self;
fn __max(self, rhs: Self) -> Self;
fn __min(self, rhs: Self) -> Self;
fn __clamp(self, min: Self, max: Self) -> Self;
}
pub trait NormalOutPromote<RHS = Self> {
type Output;
type Intermediate;
}
impl_normal_out_binary!();
impl_normal_out_simd!();
impl_normal_out_simd_with_rhs_scalar!();
impl_normal_out_simd_with_lhs_scalar!();
pub trait NormalOutUnary {
fn _square(self) -> Self;
fn _abs(self) -> Self;
fn _ceil(self) -> Self;
fn _floor(self) -> Self;
fn _neg(self) -> Self;
fn _round(self) -> Self;
fn _signum(self) -> Self;
fn _trunc(self) -> Self;
fn _leaky_relu(self, alpha: Self) -> Self;
fn _relu(self) -> Self;
fn _relu6(self) -> Self;
fn _copysign(self, rhs: Self) -> Self;
}
pub trait NormalOutUnary2 {
fn __square(self) -> Self;
fn __abs(self) -> Self;
fn __ceil(self) -> Self;
fn __floor(self) -> Self;
fn __neg(self) -> Self;
fn __round(self) -> Self;
fn __signum(self) -> Self;
fn __trunc(self) -> Self;
fn __leaky_relu(self, alpha: Self) -> Self;
fn __relu(self) -> Self;
fn __relu6(self) -> Self;
fn __copysign(self, rhs: Self) -> Self;
}
impl_normal_out_unary!();
impl_normal_out_unary_simd!();
pub trait BitWiseOut<RHS = Self> {
type Output;
fn _bitand(self, rhs: RHS) -> Self::Output;
fn _bitor(self, rhs: RHS) -> Self::Output;
fn _bitxor(self, rhs: RHS) -> Self::Output;
fn _not(self) -> Self::Output;
fn _shl(self, rhs: RHS) -> Self::Output;
fn _shr(self, rhs: RHS) -> Self::Output;
}
pub trait BitWiseOut2 {
fn __bitand(self, rhs: Self) -> Self;
fn __bitor(self, rhs: Self) -> Self;
fn __bitxor(self, rhs: Self) -> Self;
fn __not(self) -> Self;
fn __shl(self, rhs: Self) -> Self;
fn __shr(self, rhs: Self) -> Self;
}
impl_bitwise_out!();
simd_bitwise!();
pub trait Cmp<RHS = Self> {
type Output;
fn _eq(self, rhs: RHS) -> Self::Output;
fn _ne(self, rhs: RHS) -> Self::Output;
fn _lt(self, rhs: RHS) -> Self::Output;
fn _le(self, rhs: RHS) -> Self::Output;
fn _gt(self, rhs: RHS) -> Self::Output;
fn _ge(self, rhs: RHS) -> Self::Output;
}
impl_cmp!();
pub trait SimdCmp<RHS = Self> {
type Output;
fn _eq(self, rhs: RHS) -> Self::Output;
fn _ne(self, rhs: RHS) -> Self::Output;
fn _lt(self, rhs: RHS) -> Self::Output;
fn _le(self, rhs: RHS) -> Self::Output;
fn _gt(self, rhs: RHS) -> Self::Output;
fn _ge(self, rhs: RHS) -> Self::Output;
}
pub trait SimdCmpPromote<RHS = Self> {
type Output;
}
simd_cmp!();
pub trait Eval {
type Output;
fn _is_nan(&self) -> Self::Output;
fn _is_true(&self) -> Self::Output;
fn _is_inf(&self) -> Self::Output;
}
pub trait Eval2 {
type Output;
fn __is_nan(&self) -> Self::Output;
fn __is_true(&self) -> Self::Output;
fn __is_inf(&self) -> Self::Output;
}
impl_eval!();
simd_eval!();
pub trait FloatOutUnary {
type Output;
fn _exp(self) -> Self::Output;
fn _expm1(self) -> Self::Output;
fn _exp2(self) -> Self::Output;
fn _exp10(self) -> Self::Output;
fn _ln(self) -> Self::Output;
fn _log1p(self) -> Self::Output;
fn _celu(self, alpha: Self::Output) -> Self::Output;
fn _log2(self) -> Self::Output;
fn _log10(self) -> Self::Output;
fn _sqrt(self) -> Self::Output;
fn _sin(self) -> Self::Output;
fn _cos(self) -> Self::Output;
fn _sincos(self) -> (Self::Output, Self::Output);
fn _tan(self) -> Self::Output;
fn _asin(self) -> Self::Output;
fn _acos(self) -> Self::Output;
fn _atan(self) -> Self::Output;
fn _atan2(self, rhs: Self::Output) -> Self::Output;
fn _sinh(self) -> Self::Output;
fn _cosh(self) -> Self::Output;
fn _tanh(self) -> Self::Output;
fn _asinh(self) -> Self::Output;
fn _acosh(self) -> Self::Output;
fn _atanh(self) -> Self::Output;
fn _recip(self) -> Self::Output;
fn _erf(self) -> Self::Output;
fn _sigmoid(self) -> Self::Output;
fn _elu(self, alpha: Self::Output) -> Self::Output;
fn _gelu(self) -> Self::Output;
fn _selu(self, alpha: Self::Output, scale: Self::Output) -> Self::Output;
fn _hard_sigmoid(self) -> Self::Output;
fn _hard_swish(self) -> Self::Output;
fn _softplus(self) -> Self::Output;
fn _softsign(self) -> Self::Output;
fn _mish(self) -> Self::Output;
fn _cbrt(self) -> Self::Output;
}
pub trait FloatOutUnary2 {
fn __exp(self) -> Self;
fn __expm1(self) -> Self;
fn __exp2(self) -> Self;
fn __exp10(self) -> Self;
fn __ln(self) -> Self;
fn __log1p(self) -> Self;
fn __celu(self, alpha: Self) -> Self;
fn __log2(self) -> Self;
fn __log10(self) -> Self;
fn __sqrt(self) -> Self;
fn __sin(self) -> Self;
fn __cos(self) -> Self;
fn __sincos(self) -> (Self, Self)
where
Self: Sized;
fn __tan(self) -> Self;
fn __asin(self) -> Self;
fn __acos(self) -> Self;
fn __atan(self) -> Self;
fn __atan2(self, rhs: Self) -> Self;
fn __sinh(self) -> Self;
fn __cosh(self) -> Self;
fn __tanh(self) -> Self;
fn __asinh(self) -> Self;
fn __acosh(self) -> Self;
fn __atanh(self) -> Self;
fn __recip(self) -> Self;
fn __erf(self) -> Self;
fn __sigmoid(self) -> Self;
fn __elu(self, alpha: Self) -> Self;
fn __gelu(self) -> Self;
fn __selu(self, alpha: Self, scale: Self) -> Self;
fn __hard_sigmoid(self) -> Self;
fn __hard_swish(self) -> Self;
fn __softplus(self) -> Self;
fn __softsign(self) -> Self;
fn __mish(self) -> Self;
fn __cbrt(self) -> Self;
}
pub trait FloatOutUnaryPromote {
type Output;
type Intermediate;
}
float_out_unary!();
simd_float_out_unary!();