From 6d57396a422285139109f6484ff43a0aa8cdd86e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Tue, 3 Aug 2021 17:53:48 +0200 Subject: [PATCH] Remove the Scalar::is method, which is unsound. --- src/base/blas_uninit.rs | 5 +++-- src/base/scalar.rs | 11 +---------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/base/blas_uninit.rs b/src/base/blas_uninit.rs index 04812d7e..a50ec97d 100644 --- a/src/base/blas_uninit.rs +++ b/src/base/blas_uninit.rs @@ -22,6 +22,7 @@ use crate::base::dimension::{Dim, Dynamic, U1}; use crate::base::storage::{RawStorage, RawStorageMut}; use crate::base::uninit::{InitStatus, Initialized}; use crate::base::{Matrix, Scalar, Vector}; +use std::any::TypeId; // # Safety // The content of `y` must only contain values for which @@ -265,7 +266,7 @@ pub unsafe fn gemm_uninit< return; } - if T::is::() { + if TypeId::of::() == TypeId::of::() { let (rsa, csa) = a.strides(); let (rsb, csb) = b.strides(); let (rsc, csc) = y.strides(); @@ -287,7 +288,7 @@ pub unsafe fn gemm_uninit< csc as isize, ); return; - } else if T::is::() { + } else if TypeId::of::() == TypeId::of::() { let (rsa, csa) = a.strides(); let (rsb, csb) = b.strides(); let (rsc, csc) = y.strides(); diff --git a/src/base/scalar.rs b/src/base/scalar.rs index db9e458d..baee6e4f 100644 --- a/src/base/scalar.rs +++ b/src/base/scalar.rs @@ -1,19 +1,10 @@ use std::any::Any; -use std::any::TypeId; use std::fmt::Debug; /// The basic scalar type for all structures of `nalgebra`. /// /// This does not make any assumption on the algebraic properties of `Self`. -pub trait Scalar: Clone + PartialEq + Debug + Any { - #[inline] - /// Tests if `Self` the same as the type `T` - /// - /// Typically used to test of `Self` is a f32 or a f64 with `T::is::()`. - fn is() -> bool { - TypeId::of::() == TypeId::of::() - } - +pub trait Scalar: 'static + Clone + PartialEq + Debug { #[inline(always)] /// Performance hack: Clone doesn't get inlined for Copy types in debug mode, so make it inline anyway. fn inlined_clone(&self) -> Self {