Feature Request: Unpacking Array<[A; N], D> into Array<A, D::Larger>
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Facilidade para iniciantes
- 35/100
Direção de pesquisa
Start by reviewing the Array, Dimension, mapv, raw_dim, strides, and from_shape_vec APIs shown in the proposal, along with existing dimension-changing operations. Determine how the requested unpacking should fit the ndarray API, including the offset and layout cases raised by the example. Done means the proposed Array<[A; N], D> transformation is integrated with documented behavior and coverage for its supported cases.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
In certain scenarios, it is convenient to create a new dimension by unpacking arrays. For example:
let angles = array![0.1, 0.2, 0.3];
let vectors = angles.mapv(|a| [a.cos(), a.sin()]);
// Here, `vectors` is of type `Array1<[f64; 2]>`, but an `Array2<f64>` is preferred.
To address this, I have written an extension trait:
pub trait ArrayUnpackExt<A, D, const N: usize>
where
D: Dimension,
{
fn unpack(self) -> Array<A, D::Larger>;
}
impl<A, D, const N: usize> ArrayUnpackExt<A, D, N> for Array<[A; N], D>
where
D: Dimension,
{
fn unpack(self) -> Array<A, D::Larger> {
assert!(mem::size_of::<[A; N]>() == mem::size_of::<A>() * N);
let ndim = self.ndim();
let mut sh = self.raw_dim().insert_axis(Axis(ndim));
sh[ndim] = N;
let mut st = D::zeros(ndim);
self.strides().iter().enumerate().for_each(|(i, &v)| {
st[i] = (v * (N as isize)) as usize;
});
let st = st.insert_axis(Axis(ndim));
let (vec, off) = self.into_raw_vec_and_offset();
match off {
Some(0) => {
let vec = {
let mut vec = mem::ManuallyDrop::new(vec);
let ptr = vec.as_mut_ptr() as *mut A;
let len = vec.len() * N;
let cap = vec.capacity() * N;
unsafe { Vec::from_raw_parts(ptr, len, cap) }
};
unsafe { Array::from_shape_vec_unchecked(sh.strides(st), vec) }
}
_ => unreachable!(), // Unable to handle non-zero offsets even with unsafe code
}
}
}
I believe this functionality would be a valuable addition to the ndarray crate, allowing users to easily transform arrays into higher dimensions when needed. I hope you consider embedding this feature into the library.
Thank you for your attention and consideration.
- Linguagem predominante
- Rust
- Estrelas
- 4.3k
- Forks
- 391
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Preparar o ambiente
Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.
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
-
.is_all_nan() returns true for an all-finite arrayTalvez já em andamento @youdie006 assumiu há 51 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
rust-ndarray/ndarray#1612 · 1 comentário · 1 reação ·
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 48/100
rust-ndarray/ndarray#1617 · 1 comentário ·
-
Stack overflow in `triu`Talvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. 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 ·
-
Empty Array lead to "The strides must not allow any element to be referenced by two different indices"Talvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 72/100
rust-ndarray/ndarray#1609 ·
Todas as issues de rust-ndarray/ndarray
Issues semelhantes
-
security-scan
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 85/100
Mantenedores costumam responder em até 1 dia
-
content good first issue
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
StudentSuite/awesome-skills-plugins-for-students#293 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 72/100
gfx-rs/wgpu-native#636 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 1 dia
-
maintainer-needed p2 remote triaged
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
Mantenedores costumam responder em até 1 dia