mirror of
https://github.com/huggingface/candle.git
synced 2025-06-16 10:38:54 +00:00
Add i64-abs. (#1216)
This commit is contained in:
@ -536,7 +536,6 @@ unary_op!(Log, "log", v, v.ln(), vs_ln, vd_ln);
|
|||||||
unary_op!(Sin, "sin", v, v.sin(), vs_sin, vd_sin);
|
unary_op!(Sin, "sin", v, v.sin(), vs_sin, vd_sin);
|
||||||
unary_op!(Cos, "cos", v, v.cos(), vs_cos, vd_cos);
|
unary_op!(Cos, "cos", v, v.cos(), vs_cos, vd_cos);
|
||||||
unary_op!(Tanh, "tanh", v, v.tanh(), vs_tanh, vd_tanh);
|
unary_op!(Tanh, "tanh", v, v.tanh(), vs_tanh, vd_tanh);
|
||||||
unary_op!(Abs, "abs", v, v.abs());
|
|
||||||
unary_op!(Neg, "neg", v, -v);
|
unary_op!(Neg, "neg", v, -v);
|
||||||
unary_op!(Recip, "recip", v, v.recip());
|
unary_op!(Recip, "recip", v, v.recip());
|
||||||
unary_op!(Sqr, "sqr", v, v * v, vs_sqr, vd_sqr);
|
unary_op!(Sqr, "sqr", v, v * v, vs_sqr, vd_sqr);
|
||||||
@ -666,6 +665,40 @@ impl UnaryOpT for Erf {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl UnaryOpT for Abs {
|
||||||
|
const NAME: &'static str = "abs";
|
||||||
|
const KERNEL: &'static str = "uabs";
|
||||||
|
const V: Self = Abs;
|
||||||
|
#[inline(always)]
|
||||||
|
fn bf16(v: bf16) -> bf16 {
|
||||||
|
v.abs()
|
||||||
|
}
|
||||||
|
#[inline(always)]
|
||||||
|
fn f16(v: f16) -> f16 {
|
||||||
|
v.abs()
|
||||||
|
}
|
||||||
|
#[inline(always)]
|
||||||
|
fn f32(v: f32) -> f32 {
|
||||||
|
v.abs()
|
||||||
|
}
|
||||||
|
#[inline(always)]
|
||||||
|
fn f64(v: f64) -> f64 {
|
||||||
|
v.abs()
|
||||||
|
}
|
||||||
|
#[inline(always)]
|
||||||
|
fn u8(v: u8) -> u8 {
|
||||||
|
v
|
||||||
|
}
|
||||||
|
#[inline(always)]
|
||||||
|
fn u32(v: u32) -> u32 {
|
||||||
|
v
|
||||||
|
}
|
||||||
|
#[inline(always)]
|
||||||
|
fn i64(v: i64) -> i64 {
|
||||||
|
v.abs()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl UnaryOpT for Ceil {
|
impl UnaryOpT for Ceil {
|
||||||
const NAME: &'static str = "ceil";
|
const NAME: &'static str = "ceil";
|
||||||
const KERNEL: &'static str = "uceil";
|
const KERNEL: &'static str = "uceil";
|
||||||
|
@ -1089,3 +1089,11 @@ fn pad_with_same() -> Result<()> {
|
|||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn i64_abs() -> Result<()> {
|
||||||
|
let t = Tensor::new(&[-42i64, 1337], &Device::Cpu)?;
|
||||||
|
let t = t.abs()?;
|
||||||
|
assert_eq!(t.to_vec1::<i64>()?, [42, 1337]);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user