-
Notifications
You must be signed in to change notification settings - Fork 329
Default
trait for ArrayBase
?
#204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Default seems useless since it doesn't tell us what size the array should be. One could make the choice to make it a 0-element array or a 1-element array, but since arrays are not growable it doesn't seem useful at all. |
The reason is quality-of-life. Take the following example: fn default_1d<T>() -> Array<T,Ix>
where T: Default
{
Array::default(0)
}
fn default_2d<T>() -> Array<T,(Ix,Ix)>
where T: Default
{
Array::default((0,0))
}
#[derive(Clone,Debug,Deserialize,Serialize)]
pub struct MyStruct {
alpha: Array<f64, Ix>,
#[serde(skip_deserializing,skip_serializing,default="default_1d")]
inverse_alpha: Array<f64, Ix>,
#[serde(skip_deserializing,skip_serializing,default="default_2d")]
temp_quantities: Array<f64, (Ix, Ix)>,
} I am skipping serialization and deserialization of some quantities. After deserialization, Since I can't leave these fields empty, I need to fill something in, which I can accomplish through the |
It makes sense. Not fill, but replace the array. You'd need separate default implementations depending on the storage type (type parameter S), maybe we could implement an zero-dimensional default for all of Array, RcArray, ArrayView, ArrayViewMut |
Not sure I understand. A zero-dimensional default would not work in the case above, since I don't generalize over |
Ah I mean zero-size. |
Uh oh!
There was an error while loading. Please reload this page.
What is the opinion on implementing
std::default::Default
forArrayBase
? When skipping deserialization of a field withserde
, it wants to insert theDefault::default()
value in there, so this would be one case where this would be very useful.We already have a default function for
ArrayBase
, which however expects some kind of shape/dimension:A default in the spirit of
std::default::Default
would look like:And
Default
impls for the various dimension-like types would be akin to:Is this desirable?
EDIT: I just realize that this might not be as straightforward as I thought, since e.g.
Ix
acts as just a type alias, preventing an easy implementation ofDefault
for it. :-/The text was updated successfully, but these errors were encountered: