add associated constructor to `Dimension` trait
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Tranquilo
- Stack tecnológico
- rust
- Área
- backend-api-design
Línea de trabajo
Start by reading the Dimension trait and the interp_array method in ndarray-interp, focusing on how the output dimension is constructed for static dimensions and IxDyn. Define and validate an associated constructor or conversion from a slice that preserves dynamic dimensionality, rejects incompatible static dimensions, and remains suitable for custom Dimension implementations.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
I am working on the ndarray-interp crate, which is generic over the number of dimensions. This causes difficulties when the I need to construct a Dimension that is bigger than 6 (IxDyn).
Specifically the method interp_array needs to generically construct its return array of Dimension <Dq as DimAdd<D::Smaller>>::Output where Dq: Dimension + DimAdd<D::Smaller>.
This works fine for static dimensions as I can use the Default trait to create the correct Dimension. But when <Dq as DimAdd<D::Smaller>>::Output happens to be IxDyn this does not work because the information about the number of dimensions is lost.
This is my current, very ugly solution:
let shape = match <Dq as DimAdd<D::Smaller>>::Output::NDIM {
Some(_) => {
let mut dim = <Dq as DimAdd<D::Smaller>>::Output::default();
dim.as_array_view_mut()
.into_iter()
// ... set the correct axis lenghts
;
dim
}
None => {
let lenghts: Vec<usize> = ; // ... collect the correct axis lenghts
let dyn_dim = IxDyn(&lenghts);
(&dyn_dim as &dyn Any)
.downcast_ref::<<Dq as DimAdd<D::Smaller>>::Output>()
.unwrap_or_else(|| unimplemented!())
.clone()
}
};
This requires ndarray to guarantee that Dimension::NDIM is only ever None when the underlying type is IxDyn. If there is ever a impl Dimension for NewType this code will probably brake.
I might have missed something, but there does not seem to be a good solution for this problem currently.
I suggest extending the Dimenion trait, possibly by requiring Dimension: TryFrom<&[Ix]> or adding a associated constructor:
trait Dimension {
/// try to create a new Dimension from the provided slice
/// fails when `Self::NDIM.is_some_and(|ndim| ndim != ix.len())`
fn try_new(ix: &[Ix]) -> Option<Self>;
}
- Lenguaje dominante
- Rust
- Estrellas
- 4.3k
- Forks
- 391
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de rust-ndarray/ndarray
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
rust-ndarray/ndarray#1612 · 1 comentario ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
rust-ndarray/ndarray#1617 · 1 comentario ·
-
Stack overflow in `triu` Abiertobug good first issue
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
rust-ndarray/ndarray#1615 · 1 comentario ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
rust-ndarray/ndarray#1610 ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 72/100
rust-ndarray/ndarray#1609 ·
Todos los issues de rust-ndarray/ndarray
Issues similares
-
risk:low runtime status:in-progress type:test
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
zeroclaw-labs/zeroclaw#11023 ·
-
good first issue refactor
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
EricSpencer00/Resilient#4835 · 1 comentario ·
-
agent:ready documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
cesarferreira/stax#890 ·
-
bug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100