Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stack! macro cannot deal with matrix size in some situation #1490

Open
kazuki0824 opened this issue Feb 17, 2025 · 0 comments
Open

stack! macro cannot deal with matrix size in some situation #1490

kazuki0824 opened this issue Feb 17, 2025 · 0 comments

Comments

@kazuki0824
Copy link

kazuki0824 commented Feb 17, 2025

stack! macro sometimes fails to create block matrices in the situation where

  1. one of the input matrices is statically sized with generics
  2. horizontal stack + row size bound with generics
use nalgebra::{stack, Const, DMatrix, DVector, Dyn, OMatrix, SMatrix, SVector};

fn calc<const D: usize>() -> OMatrix<f64, Const<{ D }>, Dyn> {
    let mat_a: SMatrix<f64, D, D> = SMatrix::from_element(1.0);
    let mat_b: SVector<f64, D> = SVector::from_element(1.0);

    let ret = stack![mat_a, mat_b];
    ret
}

fn calc_dyn1<const D: usize>() -> OMatrix<f64, Const<{ D }>, Dyn> {
    let mat_a: SMatrix<f64, D, D> = SMatrix::from_element(1.0);
    let mat_b: DVector<f64> = DVector::from_element(D, 1.0);

    let ret = stack![mat_a, mat_b];
    ret
}

fn calc_dyn2<const D: usize>() -> OMatrix<f64, Const<{ D }>, Dyn> {
    let mat_a: SMatrix<f64, D, D> = SMatrix::from_element(1.0);
    let mat_b: DVector<f64> = DVector::from_element(D, 1.0);

    let ret = stack![mat_b, mat_a];
    ret
}

fn calc_dyn3<const D: usize>() -> OMatrix<f64, Const<{ D }>, Dyn> {
    let mat_a = DMatrix::from_element(D, D, 1.0);
    let mat_b: SVector<f64, D> = SVector::from_element(1.0);

    let ret = stack![mat_a, mat_b];
    ret
}


fn main() {
    println!("Hello, world!");
    println!("{}", calc::<3>());        // invalid
    println!("{}", calc_dyn1::<3>());   // invalid
    println!("{}", calc_dyn2::<3>());   // invalid
    println!("{}", calc_dyn3::<3>());   // valid
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant