File: numeric.rs

package info (click to toggle)
rust-ndarray 0.16.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,028 kB
  • sloc: sh: 30; makefile: 2
file content (32 lines) | stat: -rw-r--r-- 575 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#![feature(test)]

extern crate test;
use test::Bencher;

use ndarray::prelude::*;

const N: usize = 1024;
const X: usize = 64;
const Y: usize = 16;

#[cfg(feature = "std")]
#[bench]
fn clip(bench: &mut Bencher)
{
    let mut a = Array::linspace(0., 127., N * 2)
        .into_shape_with_order([X, Y * 2])
        .unwrap();
    let min = 2.;
    let max = 5.;
    bench.iter(|| {
        a.mapv_inplace(|mut x| {
            if x < min {
                x = min
            }
            if x > max {
                x = max
            }
            x
        })
    });
}