Skip to main content
Bumped by Community user
added 298 characters in body
Source Link
Makogan
  • 379
  • 1
  • 9
fn faer_arpack_symmetric_f64<F>(
    mut transform: F,
    dimension: usize,
    eigenvalue_kind: &str,
    number_of_eigenvalues: usize,
    number_of_basis_vectors: usize,
    maxiter: usize,
    vectors: bool,
) -> (Col<f64>, Mat<f64>)
where
    F: FnMut(ColRef<f64>) -> Col<f64>,
{
    let mut ido = 0;
    let mut residual: Col<f64> = Col::zeros(dimension);
    let mut eigenvectors = Mat::<f64>::zeros(dimension, number_of_basis_vectors);
    let mut iparam = [0; 11];
    iparam[0] = 1;
    iparam[2] = maxiter as i32;
    iparam[6] = 1;
    let mut ipntr = [0; 14];
    let mut workd = Col::zeros(3 * dimension);
    let lworkl = 3 * number_of_basis_vectors.pow(2) + 6 * number_of_basis_vectors;
    let mut workl = Col::<f64>::zeros(lworkl);
    let mut info = 0;

        loop
    {
        unsafe {
            dsaupd_c(
                &mut ido,
                "I".as_ptr() as *const i8,
                dimension as i32,
                eigenvalue_kind.as_ptr() as *const i8,
                number_of_eigenvalues as i32,
                f64::EPSILON,
                residual.as_ptr_mut() as *mut f64,
                number_of_basis_vectors as i32,
            eigenvectors    arnoldi_vectors.as_ptr_mut() as *mut f64,
                dimension as i32,
                iparam.as_mut_ptr(), // no idea what this does
                ipntr.as_mut_ptr(),  // no idea what this does
                workd.as_ptr_mut() as *mut f64,
                workl.as_ptr_mut() as *mut f64,
                lworkl as i32,
                &mut info,
            );

            match info
            {
                0 | 1 | 2 =>
                {
                    println!("a {}", ido);
                }
                -1 => errorpanic!("N must be positive."),
                -2 => errorpanic!("NEV must be positive."),
                -3 => errorpanic!("NCV-NEV >= 2 and less than or equal to N."),
                -4 => errorpanic!("Maximum iterations must be greater than 0."),
                -5 => errorpanic!("Maximum iterations must be greater than 0."),
                i => errorpanic!(""dsaupd_c returned error code {}", i),
            }

            if (ido == -1) || (ido == 1)
            {
                let res = transform(workd.subrows(ipntr[0] as usize - 1, dimension));
                workd
                    .subrows_mut(ipntr[1] as usize - 1, dimension)
                    .copy_from(&res);
                break;
            }
        }
    }

    let select = vec![false as i32; number_of_basis_vectors];
    let mut d: Col<f64> = Col::zeros(number_of_eigenvalues + 1);
    let mut z: Mat<f64> = Mat::zeros(dimension, number_of_basis_vectors);
    unsafe {
        dseupd_c(
            vectors as i32,
            "A".as_ptr() as *const i8,
            select.as_ptr(),
            d.as_ptr_mut() as *mut f64,
            z.as_ptr_mut() as *mut f64,
            dimension as i32,
            0.0 as f64,
            "I".as_ptr() as *const i8,
            dimension as i32,
            "LR".as_ptr() as *const i8,
            number_of_eigenvalues as i32,
            f64::EPSILON,
            residual.as_ptr_mut() as *mut f64,
            number_of_basis_vectors as i32,
            eigenvectors.as_ptr_mut() as *mut f64,
            dimension as i32,
            iparam.as_mut_ptr(),
            ipntr.as_mut_ptr(),
            workd.as_ptr_mut() as *mut f64,
            workl.as_ptr_mut() as *mut f64,
            lworkl as i32,
            &mut info,
        );
    }

    (d.subrows(0, number_of_eigenvalues).to_owned(), z)
}
fn faer_arpack_symmetric_f64<F>(
    mut transform: F,
    dimension: usize,
    eigenvalue_kind: &str,
    number_of_eigenvalues: usize,
    number_of_basis_vectors: usize,
    maxiter: usize,
    vectors: bool,
) -> (Col<f64>, Mat<f64>)
where
    F: FnMut(ColRef<f64>) -> Col<f64>,
{
    let mut ido = 0;
    let mut residual: Col<f64> = Col::zeros(dimension);
    let mut eigenvectors = Mat::<f64>::zeros(dimension, number_of_basis_vectors);
    let mut iparam = [0; 11];
    iparam[0] = 1;
    iparam[2] = maxiter as i32;
    iparam[6] = 1;
    let mut ipntr = [0; 14];
    let mut workd = Col::zeros(3 * dimension);
    let lworkl = 3 * number_of_basis_vectors.pow(2) + 6 * number_of_basis_vectors;
    let mut workl = Col::<f64>::zeros(lworkl);
    let mut info = 0;

    unsafe {
        dsaupd_c(
            &mut ido,
            "I".as_ptr() as *const i8,
            dimension as i32,
            eigenvalue_kind.as_ptr() as *const i8,
            number_of_eigenvalues as i32,
            f64::EPSILON,
            residual.as_ptr_mut() as *mut f64,
            number_of_basis_vectors as i32,
            eigenvectors.as_ptr_mut() as *mut f64,
            dimension as i32,
            iparam.as_mut_ptr(), // no idea what this does
            ipntr.as_mut_ptr(),  // no idea what this does
            workd.as_ptr_mut() as *mut f64,
            workl.as_ptr_mut() as *mut f64,
            lworkl as i32,
            &mut info,
        );

        match info
        {
            0 | 1 | 2 =>
            {}
            -1 => error!("N must be positive."),
            -2 => error!("NEV must be positive."),
            -3 => error!("NCV-NEV >= 2 and less than or equal to N."),
            -4 => error!("Maximum iterations must be greater than 0."),
            -5 => error!("Maximum iterations must be greater than 0."),
            i => error!("{}", i),
        }

        if (ido == -1) || (ido == 1)
        {
            let res = transform(workd.subrows(ipntr[0] as usize - 1, dimension));
            workd
                .subrows_mut(ipntr[1] as usize - 1, dimension)
                .copy_from(&res);
        }
    }

    let select = vec![false as i32; number_of_basis_vectors];
    let mut d: Col<f64> = Col::zeros(number_of_eigenvalues + 1);
    let mut z: Mat<f64> = Mat::zeros(dimension, number_of_basis_vectors);
    unsafe {
        dseupd_c(
            vectors as i32,
            "A".as_ptr() as *const i8,
            select.as_ptr(),
            d.as_ptr_mut() as *mut f64,
            z.as_ptr_mut() as *mut f64,
            dimension as i32,
            0.0 as f64,
            "I".as_ptr() as *const i8,
            dimension as i32,
            "LR".as_ptr() as *const i8,
            number_of_eigenvalues as i32,
            f64::EPSILON,
            residual.as_ptr_mut() as *mut f64,
            number_of_basis_vectors as i32,
            eigenvectors.as_ptr_mut() as *mut f64,
            dimension as i32,
            iparam.as_mut_ptr(),
            ipntr.as_mut_ptr(),
            workd.as_ptr_mut() as *mut f64,
            workl.as_ptr_mut() as *mut f64,
            lworkl as i32,
            &mut info,
        );
    }

    (d.subrows(0, number_of_eigenvalues).to_owned(), z)
}
fn faer_arpack_symmetric_f64<F>(
    mut transform: F,
    dimension: usize,
    eigenvalue_kind: &str,
    number_of_eigenvalues: usize,
    number_of_basis_vectors: usize,
    maxiter: usize,
    vectors: bool,
) -> (Col<f64>, Mat<f64>)
where
    F: FnMut(ColRef<f64>) -> Col<f64>,
{
    let mut ido = 0;
    let mut residual: Col<f64> = Col::zeros(dimension);
    let mut eigenvectors = Mat::<f64>::zeros(dimension, number_of_basis_vectors);
    let mut iparam = [0; 11];
    iparam[0] = 1;
    iparam[2] = maxiter as i32;
    iparam[6] = 1;
    let mut ipntr = [0; 14];
    let mut workd = Col::zeros(3 * dimension);
    let lworkl = 3 * number_of_basis_vectors.pow(2) + 6 * number_of_basis_vectors;
    let mut workl = Col::<f64>::zeros(lworkl);
    let mut info = 0;

        loop
    {
        unsafe {
            dsaupd_c(
                &mut ido,
                "I".as_ptr() as *const i8,
                dimension as i32,
                eigenvalue_kind.as_ptr() as *const i8,
                number_of_eigenvalues as i32,
                f64::EPSILON,
                residual.as_ptr_mut() as *mut f64,
                number_of_basis_vectors as i32,
                arnoldi_vectors.as_ptr_mut() as *mut f64,
                dimension as i32,
                iparam.as_mut_ptr(), // no idea what this does
                ipntr.as_mut_ptr(),  // no idea what this does
                workd.as_ptr_mut() as *mut f64,
                workl.as_ptr_mut() as *mut f64,
                lworkl as i32,
                &mut info,
            );

            match info
            {
                0 | 1 | 2 =>
                {
                    println!("a {}", ido);
                }
                -1 => panic!("N must be positive."),
                -2 => panic!("NEV must be positive."),
                -3 => panic!("NCV-NEV >= 2 and less than or equal to N."),
                -4 => panic!("Maximum iterations must be greater than 0."),
                -5 => panic!("Maximum iterations must be greater than 0."),
                i => panic!("dsaupd_c returned error code {}", i),
            }

            if (ido == -1) || (ido == 1)
            {
                let res = transform(workd.subrows(ipntr[0] as usize - 1, dimension));
                workd
                    .subrows_mut(ipntr[1] as usize - 1, dimension)
                    .copy_from(&res);
                break;
            }
        }
    }

    let select = vec![false as i32; number_of_basis_vectors];
    let mut d: Col<f64> = Col::zeros(number_of_eigenvalues + 1);
    let mut z: Mat<f64> = Mat::zeros(dimension, number_of_basis_vectors);
    unsafe {
        dseupd_c(
            vectors as i32,
            "A".as_ptr() as *const i8,
            select.as_ptr(),
            d.as_ptr_mut() as *mut f64,
            z.as_ptr_mut() as *mut f64,
            dimension as i32,
            0.0 as f64,
            "I".as_ptr() as *const i8,
            dimension as i32,
            "LR".as_ptr() as *const i8,
            number_of_eigenvalues as i32,
            f64::EPSILON,
            residual.as_ptr_mut() as *mut f64,
            number_of_basis_vectors as i32,
            eigenvectors.as_ptr_mut() as *mut f64,
            dimension as i32,
            iparam.as_mut_ptr(),
            ipntr.as_mut_ptr(),
            workd.as_ptr_mut() as *mut f64,
            workl.as_ptr_mut() as *mut f64,
            lworkl as i32,
            &mut info,
        );
    }

    (d.subrows(0, number_of_eigenvalues).to_owned(), z)
}
minor fixes
Source Link
Federico Poloni
  • 12.6k
  • 1
  • 34
  • 62

How to properly use ARAPCK'sARPACK's dsaupd and dseupd?

In rustRust, I am trying to solve an eigendecomposition problem through ARPACK. I made the following subroutine for this purpose:

How to properly use ARAPCK's dsaupd and dseupd?

In rust, I am trying to solve an eigendecomposition problem through ARPACK. I made the following subroutine for this purpose:

How to properly use ARPACK's dsaupd and dseupd?

In Rust, I am trying to solve an eigendecomposition problem through ARPACK. I made the following subroutine for this purpose:

added 2 characters in body
Source Link
Makogan
  • 379
  • 1
  • 9

I suspect I am probably making a mistake in the ways I am copying the dat aordata or passing the pointers, but I am not sure where.

I suspect I am probably making a mistake in the ways I am copying the dat aor passing the pointers, but I am not sure where.

I suspect I am probably making a mistake in the ways I am copying the data or passing the pointers, but I am not sure where.

Source Link
Makogan
  • 379
  • 1
  • 9
Loading