Add docs on how to write a function for both owned arrays and views

Open
#1,212 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
35/100
Issue type
Documentation
Clarity
Mostly clear
Activity status
Stale
Tech stack
rust
Domain
documentation

Research direction

Review the existing ndarray documentation and the linked Stack Overflow example first. Determine the recommended way to write a function accepting both owned arrays and views, then document that pattern with a comparable example and make the guidance clear for both cases.

Written by the indexing model from the issue text.

Description

docs

I'm currently trying to write a function that can take either an owned array or a view. I'm currently relying on this stackoverflow post to do something like:

use ndarray::{ArrayBase, RawData, s, array, Ix1};

fn do_something_with_array<S>(a: &ArrayBase<S, Ix1>) where S: RawData{

}

fn main () {
    let a = array![1, 2, 3];
    do_something_with_array(&a);

    let slc = a.slice(s![1..3]);
    do_something_with_array(&slc);
}

I'm not sure if this is the best way though (certainly having to include a type parameter in the function definition seems clunky), so it would be good to get clarification and add a section to the docs explaining how to write these functions.

Dominant language
Rust
Stars
4.3k
Forks
391
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rust-ndarray/ndarray

All issues in rust-ndarray/ndarray

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.