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 摘要。