add getter for dim in shape
minor fix
changed method name
@@ -21,7 +21,6 @@ impl<D> Shape<D> {
}
}
-
/// An array shape of n dimensions in c-order, f-order or custom strides.
#[derive(Copy, Clone, Debug)]
pub struct StrideShape<D> {
@@ -29,6 +28,20 @@ pub struct StrideShape<D> {
pub(crate) strides: Strides<D>,
}
+impl<D> StrideShape<D>
+where
+ D: Dimension,
+{
+ /// Return a reference to the dimension
+ pub fn raw_dim(&self) -> &D {
+ &self.dim
+ }
+ /// Return the size of the shape in number of elements
+ pub fn size(&self) -> usize {
+ self.dim.size()
+ }
+}
+
/// Stride description
#[derive(Copy, Clone, Debug)]
pub(crate) enum Strides<D> {
@@ -37,21 +50,26 @@ pub(crate) enum Strides<D> {
/// Column-major ("F"-order)
F,
/// Custom strides
- Custom(D)
+ Custom(D),
}
impl<D> Strides<D> {
/// Return strides for `dim` (computed from dimension if c/f, else return the custom stride)
pub(crate) fn strides_for_dim(self, dim: &D) -> D
- where D: Dimension
+ where
+ D: Dimension,
{
match self {
Strides::C => dim.default_strides(),
Strides::F => dim.fortran_strides(),
Strides::Custom(c) => {
- debug_assert_eq!(c.ndim(), dim.ndim(),
+ debug_assert_eq!(
+ c.ndim(),
+ dim.ndim(),
"Custom strides given with {} dimensions, expected {}",
- c.ndim(), dim.ndim());
+ c.ndim(),
+ dim.ndim()
+ );
c
}
}
@@ -94,11 +112,7 @@ where
{
fn from(value: T) -> Self {
let shape = value.into_shape();
- let st = if shape.is_c() {
- Strides::C
- } else {
- Strides::F
- };
+ let st = if shape.is_c() { Strides::C } else { Strides::F };
StrideShape {
strides: st,
dim: shape.dim,
@@ -161,8 +175,10 @@ impl<D> Shape<D>
where
D: Dimension,
{
- // Return a reference to the dimension
- //pub fn dimension(&self) -> &D { &self.dim }
+ /// Return a reference to the dimension
+ pub fn raw_dim(&self) -> &D {
+ &self.dim
+ }
/// Return the size of the shape in number of elements
pub fn size(&self) -> usize {
self.dim.size()
