Skip to content
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

Getter for dim in Shape #820

Open
RolfStierle opened this issue May 21, 2020 · 2 comments
Open

Getter for dim in Shape #820

RolfStierle opened this issue May 21, 2020 · 2 comments

Comments

@RolfStierle
Copy link

@RolfStierle RolfStierle commented May 21, 2020

For Shape, there is not getter for the dimension stored inside the structure. There was one, but now it is solely a comment (see below):

impl<D> Shape<D>
where
    D: Dimension,
{
    // Return a reference to the dimension
    //pub fn dimension(&self) -> &D { &self.dim }
    /// Return the size of the shape in number of elements
    pub fn size(&self) -> usize {
        self.dim.size()
    }
}

Is there a possibility to extract the exact dimension stored inside Shape to use it to modify the dimensions of struct definitions (minimal example below) outside of the crate?

struct Tester<D: Dimension> {
    weight: Array<f64, D::Larger>,
}

impl Tester<Ix1> {
    fn new<Sh>(shape: Sh, first_dim: usize) -> Self
    where
        Sh: ShapeBuilder<Dim = Ix1>,
    {
        let dim_in = shape.into_shape().dim;  // This is not possible because the field `dim` is private. How can one obtain the dimension?
        let shape_new = Shape::from(Ix2(first_dim, dim[0]));
        let weight = Array::<f64, Ix2>::zeros(new);
        // ... modify `weight` ...
        Self { weight }
    }
}
@bluss
Copy link
Member

@bluss bluss commented May 21, 2020

Makes sense. Some redesign is needed. Right now, these are only designed for argument conversion for the constructors, and are not intended to be modified like this.

@RolfStierle
Copy link
Author

@RolfStierle RolfStierle commented May 30, 2020

Thank you for you reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.