#mathematics #science #integration

cuba

A Rust wrapper for the C Cuba integration library

19 releases

Uses old Rust 2015

0.2.4 Dec 5, 2020
0.2.3 Sep 8, 2020
0.2.2 Mar 30, 2020
0.1.14 Mar 26, 2020
0.1.3 Oct 30, 2018

#63 in Math

Download history 5/week @ 2021-02-27 4/week @ 2021-03-06 52/week @ 2021-03-20 40/week @ 2021-03-27 19/week @ 2021-04-03 41/week @ 2021-04-10 26/week @ 2021-04-17 1/week @ 2021-05-01 20/week @ 2021-05-15 2/week @ 2021-05-22 19/week @ 2021-06-05

88 downloads per month

MIT license

370KB
708 lines

Rust Cuba interface

This library provides safe access to the Cuba integration library (version 4.2.1).

Example

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);
}

Dependencies