File: construct.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 (41 lines) | stat: -rw-r--r-- 898 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
33
34
35
36
37
38
39
40
41
#![feature(test)]
#![allow(
    clippy::many_single_char_names, clippy::deref_addrof, clippy::unreadable_literal, clippy::many_single_char_names
)]
extern crate test;
use test::Bencher;

use ndarray::prelude::*;

#[bench]
fn default_f64(bench: &mut Bencher)
{
    bench.iter(|| Array::<f64, _>::default((128, 128)))
}

#[bench]
fn zeros_f64(bench: &mut Bencher)
{
    bench.iter(|| Array::<f64, _>::zeros((128, 128)))
}

#[cfg(feature = "std")]
#[bench]
fn map_regular(bench: &mut test::Bencher)
{
    let a = Array::linspace(0., 127., 128)
        .into_shape_with_order((8, 16))
        .unwrap();
    bench.iter(|| a.map(|&x| 2. * x));
}

#[cfg(feature = "std")]
#[bench]
fn map_stride(bench: &mut test::Bencher)
{
    let a = Array::linspace(0., 127., 256)
        .into_shape_with_order((8, 32))
        .unwrap();
    let av = a.slice(s![.., ..;2]);
    bench.iter(|| av.map(|&x| 2. * x));
}