#mathematics #science #integration

cuba

A Rust wrapper for the C Cuba integration library

14 releases

0.1.13 May 26, 2019
0.1.12 May 17, 2019
0.1.11 Mar 27, 2019
0.1.9 Nov 28, 2018
0.1.3 Oct 30, 2018

#66 in Math

Download history 3/week @ 2019-04-24 1/week @ 2019-05-01 12/week @ 2019-05-08 56/week @ 2019-05-15 60/week @ 2019-05-22 42/week @ 2019-05-29 16/week @ 2019-06-05 57/week @ 2019-06-12 44/week @ 2019-06-19 70/week @ 2019-06-26 50/week @ 2019-07-03 56/week @ 2019-07-10 28/week @ 2019-07-17 12/week @ 2019-07-31

102 downloads per month

MIT license

365KB
546 lines

Rust Cuba interface

This library provides safe access to the Cuba integration library.

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 TestUserData {
    f1: f64,
    f2: f64,
}

#[inline(always)]
fn test_integrand(x: &[f64], f: &mut [f64], user_data: &mut TestUserData) -> i32 {
    f[0] = (x[0] * x[1]).sin() * user_data.f1;
    f[1] = (x[1] * x[1]).cos() * user_data.f2;
    0
}

fn main() {
    let mut ci = CubaIntegrator::new(test_integrand);
    ci.set_mineval(10).set_maxeval(10000);

    let r = ci.vegas(
        2,
        2,
        CubaVerbosity::Progress,
        TestUserData { f1: 5., f2: 7. },
    );
    println!("{:#?}", r);
}

lib.rs:

Rust binding for the Cuba integrator.

Cuba (http://www.feynarts.de/cuba/) is written by Thomas Hahn.

Usage

Create a CubaIntegrator and supply it with a function of the form

fn test_integrand(x: &[f64], f: &mut [f64], user_data: &mut T) -> i32 {
}

where T can be any type. If you don't want to provide user data, simply make T a usize and provide any number.

Example

extern crate cuba;
use cuba::{CubaIntegrator, CubaVerbosity};

#[derive(Debug)]
struct TestUserData {
    f1: f64,
    f2: f64,
}

#[inline(always)]
fn test_integrand(x: &[f64], f: &mut [f64], user_data: &mut TestUserData) -> i32 {
    f[0] = (x[0] * x[1]).sin() * user_data.f1;
    f[1] = (x[1] * x[1]).cos() * user_data.f2;
    0
}

fn main() {
    let mut ci = CubaIntegrator::new(test_integrand);
    ci.set_mineval(10).set_maxeval(10000);

    let r = ci.vegas(
        2,
        2,
        CubaVerbosity::Progress,
        TestUserData { f1: 5., f2: 7. },
    );
    println!("{:#?}", r);
}

Dependencies