diff --git a/src/core/arith.rs b/src/core/arith.rs index 86a4681c..3c978eef 100644 --- a/src/core/arith.rs +++ b/src/core/arith.rs @@ -383,7 +383,7 @@ where type OutType = T; fn convert(&self) -> Array { - constant(self.clone(), Dim4::new(&[1, 1, 1, 1])) + constant(*self, Dim4::new(&[1, 1, 1, 1])) } } diff --git a/src/core/array.rs b/src/core/array.rs index 9d426756..6e22a10f 100644 --- a/src/core/array.rs +++ b/src/core/array.rs @@ -5,6 +5,7 @@ use super::util::{af_array, dim_t, void_ptr, HasAfEnum}; use libc::{c_char, c_int, c_longlong, c_uint, c_void}; use std::ffi::CString; +use std::fmt; use std::marker::PhantomData; // Some unused functions from array.h in C-API of ArrayFire @@ -853,6 +854,24 @@ pub fn is_eval_manual() -> bool { } } +/// Prints data type, shape and data of a given Array in programming friendly context +/// +/// Used via println macro or formatter +impl fmt::Debug for Array +where + T: HasAfEnum, +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let mut vec = vec![T::default(); self.elements()]; + self.host(&mut vec); + f.debug_struct("Array") + .field("dtype", &self.get_type()) + .field("shape", &self.dims()) + .field("data", &vec) + .finish() + } +} + #[cfg(feature = "afserde")] mod afserde { // Reimport required from super scope @@ -872,7 +891,7 @@ mod afserde { /// Serialize Implementation of Array impl Serialize for Array where - T: std::default::Default + std::clone::Clone + Serialize + HasAfEnum + std::fmt::Debug, + T: Serialize + HasAfEnum, { fn serialize(&self, serializer: S) -> Result where @@ -892,7 +911,7 @@ mod afserde { /// Deserialize Implementation of Array impl<'de, T> Deserialize<'de> for Array where - T: Deserialize<'de> + HasAfEnum + std::fmt::Debug, + T: Deserialize<'de> + HasAfEnum, { fn deserialize(deserializer: D) -> Result where diff --git a/src/core/util.rs b/src/core/util.rs index 253695f3..b4363582 100644 --- a/src/core/util.rs +++ b/src/core/util.rs @@ -120,7 +120,7 @@ impl From for ColorMap { } mod private { - pub trait Sealed {} + pub trait Sealed: std::fmt::Debug + std::marker::Copy + std::default::Default {} impl Sealed for num::complex::Complex {} impl Sealed for num::complex::Complex {}