Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Add .into_view/_mut() methods to Windows, ExactChunks, and ExactChunksMut

未关闭
#920 2 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
停滞
技术栈
rust
领域
data

调研方向

Locate Windows, ExactChunks, ExactChunksMut, and the DimAdd trait from issue #570. Compare the proposed Windows::into_view implementation with the corresponding types, then add the requested immutable and mutable view methods; done means all three types support the requested conversions while preserving outer and window axes.

由索引模型根据 Issue 内容生成。

描述

enhancement help wanted

This can be convenient for some use cases, such as copying windows (especially with a non-unit step between windows) into a new owned array for modification.

This would rely on the DimAdd trait from #570. For example, the implementation for Windows could be the following:

impl<'a, A, D: Dimension> Windows<'a, A, D> {
    /// Returns a view such that the outer axes are the iteration axes and the
    /// inner axes are the axes of the windows.
    ///
    /// # Example
    ///
    /// ```
    /// use ndarray::{array, aview2, s};
    ///
    /// let arr = array![
    ///     [0, 1, 2, 3],
    ///     [4, 5, 6, 7],
    ///     [8, 9, 10, 11],
    /// ];
    /// let windows = arr.windows([2, 3]).into_view();
    /// assert_eq!(windows.shape(), &[2, 2, 2, 3]);
    /// assert_eq!(
    ///     windows.slice(s![0, 0, .., ..]),
    ///     aview2(&[[0, 1, 2], [4, 5, 6]]),
    /// );
    /// assert_eq!(
    ///     windows.slice(s![0, 1, .., ..]),
    ///     aview2(&[[1, 2, 3], [5, 6, 7]]),
    /// );
    /// assert_eq!(
    ///     windows.slice(s![1, 0, .., ..]),
    ///     aview2(&[[4, 5, 6], [8, 9, 10]]),
    /// );
    /// assert_eq!(
    ///     windows.slice(s![1, 1, .., ..]),
    ///     aview2(&[[5, 6, 7], [9, 10, 11]]),
    /// );
    /// ```
    pub fn into_view(self) -> ArrayView<'a, A, <D as DimAdd<D>>::Output> {
        let base_ndim = self.base.ndim();
        let out_ndim = 2 * base_ndim; // check for overflow?
        let mut out_dim = <D as DimAdd<D>>::Output::zeros(out_ndim);
        out_dim.slice_mut()[..base_ndim].copy_from_slice(&self.base.dim.slice());
        out_dim.slice_mut()[base_ndim..].copy_from_slice(&self.window.slice());
        let mut out_strides = <D as DimAdd<D>>::Output::zeros(out_ndim);
        out_strides.slice_mut()[..base_ndim].copy_from_slice(&self.base.strides.slice());
        out_strides.slice_mut()[base_ndim..].copy_from_slice(&self.strides.slice());
        unsafe { self.base.with_strides_dim(out_strides, out_dim) }
    }
}
主要语言
Rust
星标
4.3k
派生
391
PR 合并指标
30 天内没有已合并 PR

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

rust-ndarray/ndarray 的其他 Issue

查看 rust-ndarray/ndarray 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。