add associated constructor to `Dimension` trait
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 35/100
- Issue-Typ
- Feature
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Ruhig
- Tech-Stack
- rust
- Bereich
- backend-api-design
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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>;
}
- Vorherrschende Sprache
- Rust
- Sterne
- 4.3k
- Forks
- 391
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus rust-ndarray/ndarray
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
rust-ndarray/ndarray#1612 · 1 Kommentar ·
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
rust-ndarray/ndarray#1617 · 1 Kommentar ·
-
Stack overflow in `triu` Offenbug good first issue
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 68/100
rust-ndarray/ndarray#1615 · 1 Kommentar ·
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
rust-ndarray/ndarray#1610 ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 72/100
rust-ndarray/ndarray#1609 ·
Alle Issues in rust-ndarray/ndarray
Ähnliche Issues
-
risk:low runtime status:in-progress type:test
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 92/100
zeroclaw-labs/zeroclaw#11023 ·
-
good first issue refactor
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
kwakseongjae/auto-hwp#319 ·
-
area:cli bug filter-quality good first issue priority:medium
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 72/100
bevyengine/bevy#25861 ·