You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been reviewing #606 and to better understand how the code works I was trying to rewrite it (it usually helps me).
The skeleton of what I was trying to do looks like this:
fn format_array<A,S,D,F>(view:&ArrayBase<S,D>,f:&mut fmt::Formatter,mutformat:F,limit:Ix) -> fmt::ResultwhereF:FnMut(&A,&mut fmt::Formatter) -> fmt::Result,D:Dimension,S:Data<Elem=A>,{match view.shape(){[] => format(view.iter().next().unwrap(), f)?,[_] => format_1d_array(&view, f, format, limit)?,
shape => {let first_axis_length = shape[0];let indexes_to_be_printed:Vec<Option<usize>> = [...]write!(f,"[")?;for index in indexes_to_be_printed {match index {Some(i) => format_array(&view.index_axis(Axis(0), i), f, format, limit
)?,None => {writeln!(f,"...,")?
}}}write!(f,"]")?;}}Ok(())}
If I try to compile it, I obviously get this error:
error[E0277]: the trait bound `D: dimension::remove_axis::RemoveAxis` is not satisfied
--> src/arrayformat.rs:111:31
|
111 | &view.index_axis(Axis(0), i), f, format, limit
| ^^^^^^^^^^ the trait `dimension::remove_axis::RemoveAxis` is not implemented for `D`
|
= help: consider adding a `where D: dimension::remove_axis::RemoveAxis` bound
At this point I'd have liked to work with a dynamical dimension: get a "dynamically dimensioned" view of my ArrayBase reference and take the risk of a panic when using index_array (if I try to pass invalid parameters).
Is this even possible?
Looking at the signature of into_dyn, it seems I need to consume the array in the conversion, which is something I can't do.
Is there an alternative I can use that could work with this function skeleton?
The text was updated successfully, but these errors were encountered:
Yes, I think .view().into_dyn() is the best way right now. We could add a .dyn_view() method or something to make sure the shape/strides don't get copied twice (assuming the compiler doesn't optimize out the extra copy anyway), but unless it's called in a long, tight loop, the cost of an extra copy should be negligible anyway.
I have been reviewing #606 and to better understand how the code works I was trying to rewrite it (it usually helps me).
The skeleton of what I was trying to do looks like this:
If I try to compile it, I obviously get this error:
At this point I'd have liked to work with a dynamical dimension: get a "dynamically dimensioned" view of my
ArrayBase
reference and take the risk of a panic when usingindex_array
(if I try to pass invalid parameters).Is this even possible?
Looking at the signature of
into_dyn
, it seems I need to consume the array in the conversion, which is something I can't do.Is there an alternative I can use that could work with this function skeleton?
The text was updated successfully, but these errors were encountered: