Improve bounds check elision in indexing

Open
#349 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
rust
Domain
performance

Research direction

Begin with the unchecked test1d case and compare it with the completed test1d_single and test2d cases referenced in #350. Examine the generated code for the indexing loops; done means test1d compiles without extra bounds checks, as required by the example.

Written by the indexing model from the issue text.

Description

enhancement performance

Note: We encourage higher level functionality including map, Zip, azip!() and so on before resorting indexing.

Still, it is a good benchmark to consider bounds check elision in the most trivial cases — assuming it will improve it in some less trivial cases too.

Set the goal that the following examples compile without extra bounds checks, because their loop counters are already in bounds.

pub fn test1d(a: &Array1<f64>) -> f64 {
    let mut sum = 0.;
    for i in 0..a.len() {
        sum += a[i];
    }
    sum
}

pub fn test2d(a: &Array2<f64>) -> f64 {
    let mut sum = 0.;
    for i in 0..a.rows() {
        for j in 0..a.cols() {
            sum += a[[i, j]];
        }
    }
    sum
}
  • test1d_single #350
  • test1d
  • test2d #350
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.