Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Quantics Function

When working with algorithms that expect a function of quantics indices, you can wrap a coordinate-space function with quantics_function.

use quanticsgrids::{DiscretizedGrid, quantics_function};

fn main() -> quanticsgrids::Result<()> {
    let grid = DiscretizedGrid::builder(&[4, 4]).build()?;

    let f = |coords: &[f64]| coords[0].sin() + coords[1];
    let fq = quantics_function(&grid, f);

    let quantics = grid.origcoord_to_quantics(&[0.0, 0.5])?;
    let coords = grid.quantics_to_origcoord(&quantics)?;
    let value = fq(&quantics)?;

    assert!((value - (coords[0].sin() + coords[1])).abs() < 1e-12);

    Ok(())
}

This is the Rust equivalent of first defining a function in the original coordinate space and then obtaining a quantics-index wrapper around it.