Crates.io | cuba |
lib.rs | cuba |
version | 0.2.4 |
source | src |
created_at | 2018-10-17 11:11:12.034748 |
updated_at | 2020-12-05 18:00:46.10872 |
description | A Rust wrapper for the C Cuba integration library |
homepage | |
repository | https://github.com/benruijl/cuba |
max_upload_size | |
id | 91137 |
size | 404,780 |
This library provides safe access to the Cuba integration library (version 4.2.1).
Below we show an example of an integration of a test function with user data (this can be of any type):
extern crate cuba;
use cuba::{CubaIntegrator, CubaVerbosity};
#[derive(Debug)]
struct UserData {
f1: f64,
f2: f64,
}
#[inline(always)]
fn integrand(
x: &[f64],
f: &mut [f64],
user_data: &mut UserData,
nvec: usize,
_core: i32,
_weight: &[f64],
_iter: usize,
) -> Result<(), &'static str> {
for i in 0..nvec {
f[i * 2] = (x[i * 2] * x[i * 2]).sin() * user_data.f1;
f[i * 2 + 1] = (x[i * 2 + 1] * x[i * 2 + 1]).cos() * user_data.f2;
}
Ok(())
}
fn main() {
let mut ci = CubaIntegrator::new();
ci.set_mineval(10)
.set_maxeval(10000000)
.set_epsrel(0.0001)
.set_seed(0) // use quasi-random numbers
.set_cores(2, 1000);
let data = UserData { f1: 5., f2: 7. };
let r = ci.vegas(2, 2, 4, CubaVerbosity::Progress, 0, integrand, data);
println!("{:#?}", r);
}