Skip to content

Improve bounds check elision in indexing #349

Open
@bluss

Description

@bluss

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
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions