Direct access to Shape
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
Direzione di ricerca
Start by reading ArrayBase::dim, raw_dim, as_slice, and as_slice_memory_order, then trace the Shape and ShapeBuilder APIs referenced in the issue. Done means callers can directly obtain an array's Shape and determine row-major, column-major, or non-contiguous layout without relying on the workaround shown.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
I have this code, which takes a matrix and tries to create a matrix with similar specifications, i.e. a matrix with the same Shape. Unfortunately, this turns out to be more complicated then I hoped, because I don't have an easy way to check the memory layout of my matrix.
The reasons are:
- I don't have direct access to
Shape, but only toDim::Pattern(viaArrayBase::dim) orDim(viaArrayBase::raw_dim). If I could get theShapefrom an array, I could pass it to the various methods that accept aT: ShapeBuilder. - There is no way to check if a matrix is in column major or row major form. Similarly, there is no way to check if a
Shapeis for column or row major form.
The only workaround that I see and am using, is to call as_slice and as_slice_memory_order on my array. If the first call returns an Option, I know I am in row major form. If it returns None but as_slice_memory_order returns an Option, I know I am in column major form. Both of these methods of course depend on the current specific implementation in ndarray.
It would be nice to have a more direct check for the memory layout. This is important when writing methods that call blas or lapack functions.
See the code below for reference.
fn from_matrix<S>(a: &ArrayBase<S, Ix2>) -> Result<Self>
where S: Data<Elem = f64>
{
use cblas::Layout::*;
let dim = a.dim();
let shape = match utils::get_layout(a) {
Some(ColumnMajor) => dim.f(),
Some(RowMajor) => dim.into_shape(),
None => Err(Error::NonContiguous)?,
};
Self::from_shape(shape)
}
fn from_shape<T>(shape: T) -> Result<Self>
where T: ShapeBuilder<Dim = Ix2>,
{
// Unfortunately we cannot check the shape itself to see if it's
// in ColumnMajor or RowMajor layout. So we need to first construct
// an array and then check that.
let shape = shape.into_shape();
let q = Array2::zeros(shape);
let memory_layout = match get_layout(&q) {
Some(layout) => layout,
None => Err(Error::NonContiguous)?,
};
let r = q.clone();
Ok(ClassicalGramSchmidt {
q,
r,
memory_layout,
})
}
fn get_layout<S, T, D>(a: &ArrayBase<S, D>) -> Option<cblas::Layout>
where S: Data<Elem=T>,
D: Dimension
{
if let Some(_) = a.as_slice() {
Some(cblas::Layout::RowMajor)
} else if let Some(_) = a.as_slice_memory_order() {
Some(cblas::Layout::ColumnMajor)
} else {
None
}
}
- Lingua principale
- Rust
- Stelle
- 4.3k
- Fork
- 391
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di rust-ndarray/ndarray
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
rust-ndarray/ndarray#1612 · 1 commento ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
rust-ndarray/ndarray#1617 · 1 commento ·
-
Stack overflow in `triu` Apertabug good first issue
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
rust-ndarray/ndarray#1615 · 1 commento ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
rust-ndarray/ndarray#1610 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
rust-ndarray/ndarray#1609 ·
Tutte le issue di rust-ndarray/ndarray
Issue simili
-
risk:low runtime status:in-progress type:test
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
zeroclaw-labs/zeroclaw#11023 ·
-
good first issue refactor
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
EricSpencer00/Resilient#4835 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
bisq-network/bisq-musig#204 ·
-
agent:ready documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
cesarferreira/stax#890 ·