Skip to content

Getter for dim in Shape #820

Closed
Closed

Description

@RolfStierle

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 }
    }
}

Activity

  1. bluss commented on May 21, 2020

    @bluss
    Member

    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.

  2. RolfStierle commented on May 30, 2020

    @RolfStierle
    Author

    Thank you for you reply.

  3. stokhos commented on Apr 8, 2021

    @stokhos
    Contributor

    Is anyone working on this. If not I'd like to work on this issue. @bluss @jturner314

  4. bluss commented on Apr 8, 2021

    @bluss
    Member

    Feel free to add this accessor in a simple way. Shape/StrideShape needs redesign but I'd like to give input on that another time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions