Skip to content

Getter for dim in Shape #820

Closed
Closed
@RolfStierle

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

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