add associated constructor to `Dimension` trait
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Facilidade para iniciantes
- 35/100
- Tipo de issue
- Funcionalidade
- Clareza
- Razoavelmente clara
- Status de atividade
- Pouca atividade
- Stack de tecnologia
- rust
- Domínio
- backend-api-design
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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>;
}
- Linguagem predominante
- Rust
- Estrelas
- 4.3k
- Forks
- 391
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Guia de contribuição
Nenhum guia de contribuição indexado para este repositório
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de rust-ndarray/ndarray
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
rust-ndarray/ndarray#1612 · 1 comentário ·
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 48/100
rust-ndarray/ndarray#1617 · 1 comentário ·
-
Stack overflow in `triu` Abertabug good first issue
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 68/100
rust-ndarray/ndarray#1615 · 1 comentário ·
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 48/100
rust-ndarray/ndarray#1610 ·
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 72/100
rust-ndarray/ndarray#1609 ·
Todas as issues de rust-ndarray/ndarray
Issues semelhantes
-
risk:low runtime status:in-progress type:test
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 92/100
zeroclaw-labs/zeroclaw#11023 ·
-
good first issue refactor
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 86/100
kwakseongjae/auto-hwp#319 ·
-
area:cli bug filter-quality good first issue priority:medium
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 72/100
bevyengine/bevy#25861 ·