intel_mkl_sys/
lib.rs

1//! Rust binding to Intel-MKL including
2//!
3//! - [Vector Mathematical Functions (mkl_vml.h)](https://software.intel.com/en-us/onemkl-developer-reference-c-vector-mathematical-functions)
4//! - [Statistical Functions (mkl_vsl.h)](https://software.intel.com/en-us/onemkl-developer-reference-c-statistical-functions)
5//!
6//! Other parts of Intel-MKL is served via
7//!
8//! - [blas-sys](https://crates.io/crates/blas-sys)
9//! - [lapack-sys](https://crates.io/crates/lapack-sys)
10//! - [lapacke-sys](https://crates.io/crates/lapacke-sys)
11//! - [fftw-sys](https://crates.io/crates/fftw-sys)
12//!
13#![allow(
14    improper_ctypes,
15    non_upper_case_globals,
16    non_camel_case_types,
17    non_snake_case
18)]
19
20extern crate intel_mkl_src;
21
22include!("mkl.rs");
23
24// Test linking
25#[cfg(test)]
26mod tests {
27    use super::*;
28    use approx::ulps_eq;
29    use rand::distributions::{Distribution, Uniform};
30    use std::ffi::c_void;
31
32    fn gen_rand_array(n: usize) -> Vec<f64> {
33        let mut rng = rand::thread_rng();
34        let between = Uniform::from(0.0..2.0 * std::f64::consts::PI);
35        let mut buf = vec![0.0; n];
36        for val in buf.iter_mut() {
37            *val = between.sample(&mut rng);
38        }
39        buf
40    }
41
42    #[test]
43    fn cos() {
44        let n = 1024;
45        let a = gen_rand_array(n);
46        let mut b = vec![0.0_f64; n];
47        unsafe {
48            vdCos(n as i32, a.as_ptr(), b.as_mut_ptr());
49        }
50        for i in 0..n {
51            assert!(ulps_eq!(
52                b[i],
53                a[i].cos(),
54                max_ulps = 4,
55                epsilon = std::f64::EPSILON
56            ));
57        }
58    }
59
60    #[test]
61    fn new_stream() {
62        let mut stream: *mut c_void = std::ptr::null_mut();
63        unsafe {
64            vslNewStream(
65                &mut stream as *mut *mut c_void,
66                VSL_BRNG_MT19937 as i32,
67                777,
68            );
69        }
70    }
71}