Skip to content

Accept owned arrays in concatenate and stack #1591

@watsaig

Description

@watsaig

It would be convenient to be able to call concatenate or stack with a slice of owned arrays or array views, rather than just views currently.

So for concatenate, this:

let arrays = vec![a, b, c]; // more realistically, this would be returned by a function
let arrays = arrays.iter().map(|a| a.view()).collect::<Vec<_>>();
let res = ndarray::concatenate(Axis(2), &arrays);

would become:

let arrays = vec![a, b, c];
let res = ndarray::concatenate(Axis(2), &arrays);

This could be done by changing the signature of concatenate to the following, which would allow either views or owned arrays:

-pub fn concatenate<A, D>(axis: Axis, arrays: &[ArrayView<A, D>]) -> Result<Array<A, D>, ShapeError>
+pub fn concatenate<S, D, A>(axis: Axis, arrays: &[ArrayBase<S, D, A>]) -> Result<Array<A, D>, ShapeError>
 where
+    S: Data<Elem = A>,
     A: Clone,
     D: RemoveAxis,
 {

This is technically a breaking API change though, at least in the niche case of passing an empty slice as a parameter (which causes a type inference error). Before I open an unsolicited PR, would there be interest in this change?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions