From 05aebdb28917a10ca1aec1490c459f778998da91 Mon Sep 17 00:00:00 2001 From: Jorge Perez Burgos Date: Fri, 3 Jan 2025 18:28:56 +0100 Subject: [PATCH] Add Neg trait to Float trait. --- crates/cubecl-core/src/frontend/element/float.rs | 1 + .../src/frontend/element/float/tensor_float.rs | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/cubecl-core/src/frontend/element/float.rs b/crates/cubecl-core/src/frontend/element/float.rs index 2f302fef8..d1370b0b4 100644 --- a/crates/cubecl-core/src/frontend/element/float.rs +++ b/crates/cubecl-core/src/frontend/element/float.rs @@ -33,6 +33,7 @@ pub trait Float: + Normalize + Dot + Into + + core::ops::Neg + core::ops::Add + core::ops::Sub + core::ops::Mul diff --git a/crates/cubecl-core/src/frontend/element/float/tensor_float.rs b/crates/cubecl-core/src/frontend/element/float/tensor_float.rs index cdc0cd14c..97c2ee1d5 100644 --- a/crates/cubecl-core/src/frontend/element/float/tensor_float.rs +++ b/crates/cubecl-core/src/frontend/element/float/tensor_float.rs @@ -2,7 +2,7 @@ #![allow(clippy::transmute_float_to_int)] // prev=1.83. use bytemuck::{Pod, Zeroable}; -use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; +use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign}; use half::f16; use num_traits::{NumCast, ToPrimitive}; use serde::Serialize; @@ -88,6 +88,14 @@ impl tf32 { } } +impl Neg for tf32 { + type Output = Self; + + fn neg(self) -> Self::Output { + Self::from_f32(self.to_f32().neg()) + } +} + impl Mul for tf32 { type Output = Self;