-
I know arrayfire-rust has some useful macro for stdout (e.g., af_print!). But I want to create some struct which has the member of arrayfire: pub struct SomeStruct {
pub data: af::Array<f32>,
}
impl std::fmt::Display for SumStruct {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let message = "???????" // <- I want to know how to prepare the message
write!(f, "{}", message)
}
} Is there any good way? |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments
-
@nocotan I am not sure I understand the question completely. Are you requesting some sort of |
Beta Was this translation helpful? Give feedback.
-
@9prady9 Thanks for the reply. |
Beta Was this translation helpful? Give feedback.
-
Since Array is just wrapper for handle, there isn't much useful to print from it(has the internal handle). fmt::write for Array could print the entire array to it, is that what you are looking for ? This may be useful for smaller arrays, but not for larger arrays. I guess the question is how much or what info of Array should be printed when passed onto |
Beta Was this translation helpful? Give feedback.
-
To clarify better, what I meant was Array implementing I think you should print the info relevant to your code from Array doing something like the below
Please note that I didn't compile the above code, so kindly check for the right method name. Hope that helps. |
Beta Was this translation helpful? Give feedback.
-
@9prady9 Thank you for your kind reply! In fact, I was wondering how to write the entire arrayfire elements. pub struct SomeStruct {
pub data: af::Array<f32>,
}
impl std::fmt::Display for SomeStruct {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "entire array {}", self.data)
}
} However, I get the following error: |
25 | write!(f, "entire array {}", self.data)
| `arrayfire::array::Array<f32>` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `arrayfire::array::Array<f32>` I'm sure it's due to my lack of Rust skills... |
Beta Was this translation helpful? Give feedback.
-
Array doesn't have pub struct SomeStruct {
pub data: arrayfire::Array<f32>,
pub handle: i32,
}
impl std::fmt::Display for SomeStruct {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
af_print!("entire array:", self.data);
write!(f, "Handle value: {}", self.handle)
}
}
fn main() {
let s = SomeStruct{handle: 0, data: arrayfire::constant(0f32, Dim4::new(&[5, 5, 1, 1]))};
println!("{}", s);
} The associated output looks like below
If you don't want to use |
Beta Was this translation helpful? Give feedback.
-
@9prady9 I see. Thank you so much! |
Beta Was this translation helpful? Give feedback.
Array doesn't have
fmt
implemented in the library code. Hence, I was suggesting you could do it or you can just using existing methods to print the relevant info.The associated output looks like below