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

Đang mở
#325 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
rust
Lĩnh vực
data

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Rust
Star
4.3k
Fork
391
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của rust-ndarray/ndarray

Tất cả issue của rust-ndarray/ndarray

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.