Convert Array<A, D> into ArrayBase<S, D>

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

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
rust
领域
data

调研方向

Start by reading Array, ArrayBase, into_owned, and into_shared, then review the strongly typed strides discussion in issue #283. Determine whether an owned array can be generalized to ArrayBase without copying while preserving its strides, with results usable as both Array and RcArray.

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

描述

enhancement

I would like to switch array type to implement a general library

pub fn algorithm<A, Si, So, D>(a: ArrayBase<Si, D>) -> ArrayBase<So, D>
where Si: Data<Elem = A>, So: DataOwned<Elem =A>, D: Dimension
{ ... }

Users of this library can get the result using both Array and RcArray:

let result1: Array2<f64> = algorithm(a);
let result2: RcArray2<f64> = algorithm(a);

However, some algorithm in this crate (e.g. ndarray::linalg::Dot::dot) returns Array,
and thus I try to write a function that convert Array<D> into ArrayBase<S: DataOwned, D> without data copy:

fn generalize<A, S, D>(a: Array<A, D>) -> ArrayBase<S, D>
where
  S: DataOwned<Elem =A>,
  D: Dimension,
{
  ArrayBase::from_shape_vec(a.dim(), a.into_raw_vec())
}

This is an generalization of into_owned and into_shared. This generalize can be compiled, but does not keep its stride.

let a: Array3<f64> = Array::zeros((3, 2, 4).f()); // f-order
let ans = a.clone();
let a: Array3<f64> = generalize(a); // c-order
assert_eq!(a, ans); /// panic!

I cannot find a way to keep strides :< I suspect that I need the strongly typed strides #283
Is it possible to implement it correctly out of this crate? If impossible, please add such function.

主要语言
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 摘要。