diff --git a/src/base/matrix.rs b/src/base/matrix.rs index 887ed047..1d69d6e4 100644 --- a/src/base/matrix.rs +++ b/src/base/matrix.rs @@ -7,6 +7,7 @@ use approx::{AbsDiffEq, RelativeEq, UlpsEq}; use std::any::TypeId; use std::cmp::Ordering; use std::fmt; +use std::hash::{Hash, Hasher}; use std::marker::PhantomData; use std::mem; @@ -72,7 +73,7 @@ pub type MatrixCross = /// dynamically-sized column vector should be represented as a `Matrix` (given /// some concrete types for `N` and a compatible data storage type `S`). #[repr(C)] -#[derive(Hash, Clone, Copy)] +#[derive(Clone, Copy)] pub struct Matrix { /// The data storage that contains all the matrix components and informations about its number /// of rows and column (if needed). @@ -1482,3 +1483,24 @@ where self.as_ref().ulps_eq(other.as_ref(), epsilon, max_ulps) } } + +impl Hash for Matrix +where + N: Scalar + Hash, + R: Dim, + C: Dim, + S: Storage, +{ + fn hash(&self, state: &mut H) { + let (nrows, ncols) = self.shape(); + (nrows, ncols).hash(state); + + for j in 0..ncols { + for i in 0..nrows { + unsafe { + self.get_unchecked(i, j).hash(state); + } + } + } + } +}