| 1 | use craterust-analyzer cargo nalgebra-macros 0.3.0 crate/::Matrixrust-analyzer cargo nalgebra-macros 0.3.0 matrix_vector_impl/Matrix#; |
| 2 | use proc_macro2rust-analyzer cargo proc-macro2 1.0.93 crate/::{Spanrust-analyzer cargo proc-macro2 1.0.93 Span#, TokenStreamrust-analyzer cargo proc-macro2 1.0.93 TokenStream# as TokenStream2rust-analyzer cargo proc-macro2 1.0.93 TokenStream#}; |
| 3 | use quoterust-analyzer cargo quote 1.0.38 crate/::{format_identrust-analyzer cargo quote 1.0.38 format/format_ident!, quoterust-analyzer cargo quote 1.0.38 quote!, quote_spannedrust-analyzer cargo quote 1.0.38 quote_spanned!}; |
| 4 | use synrust-analyzer cargo syn 2.0.96 crate/::spannedrust-analyzer cargo syn 2.0.96 spanned/::Spannedrust-analyzer cargo syn 2.0.96 spanned/Spanned#; |
| 5 | use synrust-analyzer cargo syn 2.0.96 crate/::{Errorrust-analyzer cargo syn 2.0.96 error/Error#, Exprrust-analyzer cargo syn 2.0.96 expr/Expr#, Litrust-analyzer cargo syn 2.0.96 lit/Lit#}; |
| 6 | |
| 7 | #[allow(clippy::too_many_lines)] |
| 8 | pub fn stack_implrust-analyzer cargo nalgebra-macros 0.3.0 stack_impl/stack_impl().(matrix: Matrixrust-analyzer cargo nalgebra-macros 0.3.0 matrix_vector_impl/Matrix#) -> synrust-analyzer cargo syn 2.0.96 crate/::Resultrust-analyzer cargo syn 2.0.96 error/Result#<TokenStream2rust-analyzer cargo proc-macro2 1.0.93 TokenStream#> { |
| 9 | // The prefix is used to construct variable names |
| 10 | // that are extremely unlikely to collide with variable names used in e.g. expressions |
| 11 | // by the user. Although we could use a long, pseudo-random string, this makes the generated |
| 12 | // code very painful to parse, so we settle for something more semantic that is still |
| 13 | // very unlikely to collide |
| 14 | let prefix = "___na"; |
| 15 | let n_block_rows = matrix.nrowsrust-analyzer cargo nalgebra-macros 0.3.0 matrix_vector_impl/impl#[Matrix]nrows().(); |
| 16 | let n_block_cols = matrix.ncolsrust-analyzer cargo nalgebra-macros 0.3.0 matrix_vector_impl/impl#[Matrix]ncols().(); |
| 17 | |
| 18 | let mut output = quoterust-analyzer cargo quote 1.0.38 quote!! {}; |
| 19 | |
| 20 | // First assign data and shape for each matrix entry to variables |
| 21 | // (this is important so that we, for example, don't evaluate an expression more than once) |
| 22 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#n_block_rows { |
| 23 | for j in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#n_block_cols { |
| 24 | let expr = &matrix[rust-analyzer cargo nalgebra-macros 0.3.0 matrix_vector_impl/impl#[Matrix][`Index<(usize, usize)>`]index().(i, j)]rust-analyzer cargo nalgebra-macros 0.3.0 matrix_vector_impl/impl#[Matrix][`Index<(usize, usize)>`]index().; |
| 25 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_literal_zerorust-analyzer cargo nalgebra-macros 0.3.0 stack_impl/is_literal_zero().(expr) { |
| 26 | let ident_block = format_identrust-analyzer cargo quote 1.0.38 format/format_ident!!("{prefix}_stack_{i}_{j}_block"); |
| 27 | let ident_shape = format_identrust-analyzer cargo quote 1.0.38 format/format_ident!!("{prefix}_stack_{i}_{j}_shape"); |
| 28 | output.extendrust-analyzer cargo proc-macro2 1.0.93 impl#[TokenStream][`Extend<Self>`]extend().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/once/once().(quote_spannedrust-analyzer cargo quote 1.0.38 quote_spanned!! {expr.spanrust-analyzer cargo syn 2.0.96 spanned/impl#[T][Spanned]span().()=> |
| 29 | let ref #ident_block = #expr; |
| 30 | let #ident_shape = #ident_block.shape_generic(); |
| 31 | })); |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | // Determine the number of rows (dimension) in each block row, |
| 37 | // and write out variables that define block row dimensions and offsets into the |
| 38 | // output matrix |
| 39 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#n_block_rows { |
| 40 | // The dimension of the block row is the result of trying to unify the row shape of |
| 41 | // all blocks in the block row |
| 42 | let dim = (0 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#n_block_cols) |
| 43 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|j| { |
| 44 | let expr = &matrix[rust-analyzer cargo nalgebra-macros 0.3.0 matrix_vector_impl/impl#[Matrix][`Index<(usize, usize)>`]index().(i, j)]rust-analyzer cargo nalgebra-macros 0.3.0 matrix_vector_impl/impl#[Matrix][`Index<(usize, usize)>`]index().; |
| 45 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_literal_zerorust-analyzer cargo nalgebra-macros 0.3.0 stack_impl/is_literal_zero().(expr) { |
| 46 | let mut ident_shape = format_identrust-analyzer cargo quote 1.0.38 format/format_ident!!("{prefix}_stack_{i}_{j}_shape"); |
| 47 | ident_shape.set_spanrust-analyzer cargo proc-macro2 1.0.93 impl#[Ident]set_span().(ident_shape.spanrust-analyzer cargo proc-macro2 1.0.93 impl#[Ident]span().().located_atrust-analyzer cargo proc-macro2 1.0.93 impl#[Span]located_at().(expr.spanrust-analyzer cargo syn 2.0.96 spanned/impl#[T][Spanned]span().())); |
| 48 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(quote_spannedrust-analyzer cargo quote 1.0.38 quote_spanned!!{expr.spanrust-analyzer cargo syn 2.0.96 spanned/impl#[T][Spanned]span().()=> #ident_shape.0 }) |
| 49 | } else { |
| 50 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 51 | } |
| 52 | }).reducerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#reduce().(|a, b| { |
| 53 | let expect_msg = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("All blocks in block row {i} must have the same number of rows"); |
| 54 | quote_spannedrust-analyzer cargo quote 1.0.38 quote_spanned!!{b.spanrust-analyzer cargo syn 2.0.96 spanned/impl#[T][Spanned]span().()=> |
| 55 | <nalgebra::constraint::ShapeConstraint as nalgebra::constraint::SameNumberOfRows<_, _>>::representative(#a, #b) |
| 56 | .expect(#expect_msg) |
| 57 | } |
| 58 | }).ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(Errorrust-analyzer cargo syn 2.0.96 error/Error#::newrust-analyzer cargo syn 2.0.96 error/impl#[Error]new().(Spanrust-analyzer cargo proc-macro2 1.0.93 Span#::call_siterust-analyzer cargo proc-macro2 1.0.93 impl#[Span]call_site().(), formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Block row {i} cannot consist entirely of implicit zero blocks.")))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 59 | |
| 60 | let dim_ident = format_identrust-analyzer cargo quote 1.0.38 format/format_ident!!("{prefix}_stack_row_{i}_dim"); |
| 61 | let offset_ident = format_identrust-analyzer cargo quote 1.0.38 format/format_ident!!("{prefix}_stack_row_{i}_offset"); |
| 62 | |
| 63 | let offset = if i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 { |
| 64 | quoterust-analyzer cargo quote 1.0.38 quote!! { 0 } |
| 65 | } else { |
| 66 | let prev_offset_ident = format_identrust-analyzer cargo quote 1.0.38 format/format_ident!!("{prefix}_stack_row_{}_offset", i -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). 1); |
| 67 | let prev_dim_ident = format_identrust-analyzer cargo quote 1.0.38 format/format_ident!!("{prefix}_stack_row_{}_dim", i -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). 1); |
| 68 | quoterust-analyzer cargo quote 1.0.38 quote!! { #prev_offset_ident + <_ as nalgebra::Dim>::value(&#prev_dim_ident) } |
| 69 | }; |
| 70 | |
| 71 | output.extendrust-analyzer cargo proc-macro2 1.0.93 impl#[TokenStream][`Extend<Self>`]extend().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/once/once().(quoterust-analyzer cargo quote 1.0.38 quote!! { |
| 72 | let #dim_ident = #dim; |
| 73 | let #offset_ident = #offset; |
| 74 | })); |
| 75 | } |
| 76 | |
| 77 | // Do the same thing for the block columns |
| 78 | for j in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#n_block_cols { |
| 79 | let dim = (0 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#n_block_rows) |
| 80 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|i| { |
| 81 | let expr = &matrix[rust-analyzer cargo nalgebra-macros 0.3.0 matrix_vector_impl/impl#[Matrix][`Index<(usize, usize)>`]index().(i, j)]rust-analyzer cargo nalgebra-macros 0.3.0 matrix_vector_impl/impl#[Matrix][`Index<(usize, usize)>`]index().; |
| 82 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_literal_zerorust-analyzer cargo nalgebra-macros 0.3.0 stack_impl/is_literal_zero().(expr) { |
| 83 | let mut ident_shape = format_identrust-analyzer cargo quote 1.0.38 format/format_ident!!("{prefix}_stack_{i}_{j}_shape"); |
| 84 | ident_shape.set_spanrust-analyzer cargo proc-macro2 1.0.93 impl#[Ident]set_span().(ident_shape.spanrust-analyzer cargo proc-macro2 1.0.93 impl#[Ident]span().().located_atrust-analyzer cargo proc-macro2 1.0.93 impl#[Span]located_at().(expr.spanrust-analyzer cargo syn 2.0.96 spanned/impl#[T][Spanned]span().())); |
| 85 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(quote_spannedrust-analyzer cargo quote 1.0.38 quote_spanned!!{expr.spanrust-analyzer cargo syn 2.0.96 spanned/impl#[T][Spanned]span().()=> #ident_shape.1 }) |
| 86 | } else { |
| 87 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 88 | } |
| 89 | }).reducerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#reduce().(|a, b| { |
| 90 | let expect_msg = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("All blocks in block column {j} must have the same number of columns"); |
| 91 | quote_spannedrust-analyzer cargo quote 1.0.38 quote_spanned!!{b.spanrust-analyzer cargo syn 2.0.96 spanned/impl#[T][Spanned]span().()=> |
| 92 | <nalgebra::constraint::ShapeConstraint as nalgebra::constraint::SameNumberOfColumns<_, _>>::representative(#a, #b) |
| 93 | .expect(#expect_msg) |
| 94 | } |
| 95 | }).ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(Errorrust-analyzer cargo syn 2.0.96 error/Error#::newrust-analyzer cargo syn 2.0.96 error/impl#[Error]new().(Spanrust-analyzer cargo proc-macro2 1.0.93 Span#::call_siterust-analyzer cargo proc-macro2 1.0.93 impl#[Span]call_site().(), formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Block column {j} cannot consist entirely of implicit zero blocks.")))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 96 | |
| 97 | let dim_ident = format_identrust-analyzer cargo quote 1.0.38 format/format_ident!!("{prefix}_stack_col_{j}_dim"); |
| 98 | let offset_ident = format_identrust-analyzer cargo quote 1.0.38 format/format_ident!!("{prefix}_stack_col_{j}_offset"); |
| 99 | |
| 100 | let offset = if j rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 { |
| 101 | quoterust-analyzer cargo quote 1.0.38 quote!! { 0 } |
| 102 | } else { |
| 103 | let prev_offset_ident = format_identrust-analyzer cargo quote 1.0.38 format/format_ident!!("{prefix}_stack_col_{}_offset", j -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). 1); |
| 104 | let prev_dim_ident = format_identrust-analyzer cargo quote 1.0.38 format/format_ident!!("{prefix}_stack_col_{}_dim", j -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). 1); |
| 105 | quoterust-analyzer cargo quote 1.0.38 quote!! { #prev_offset_ident + <_ as nalgebra::Dim>::value(&#prev_dim_ident) } |
| 106 | }; |
| 107 | |
| 108 | output.extendrust-analyzer cargo proc-macro2 1.0.93 impl#[TokenStream][`Extend<Self>`]extend().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/once/once().(quoterust-analyzer cargo quote 1.0.38 quote!! { |
| 109 | let #dim_ident = #dim; |
| 110 | let #offset_ident = #offset; |
| 111 | })); |
| 112 | } |
| 113 | |
| 114 | // Determine number of rows and cols in output matrix, |
| 115 | // by adding together dimensions of all block rows/cols |
| 116 | let num_rows = (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#n_block_rows) |
| 117 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|i| { |
| 118 | let ident = format_identrust-analyzer cargo quote 1.0.38 format/format_ident!!("{prefix}_stack_row_{i}_dim"); |
| 119 | quoterust-analyzer cargo quote 1.0.38 quote!! { #ident } |
| 120 | }) |
| 121 | .reducerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#reduce().(|a, b| { |
| 122 | quoterust-analyzer cargo quote 1.0.38 quote!! { |
| 123 | <_ as nalgebra::DimAdd<_>>::add(#a, #b) |
| 124 | } |
| 125 | }) |
| 126 | .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(quoterust-analyzer cargo quote 1.0.38 quote!! { nalgebra::dimension::U0 }); |
| 127 | |
| 128 | let num_cols = (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#n_block_cols) |
| 129 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|j| { |
| 130 | let ident = format_identrust-analyzer cargo quote 1.0.38 format/format_ident!!("{prefix}_stack_col_{j}_dim"); |
| 131 | quoterust-analyzer cargo quote 1.0.38 quote!! { #ident } |
| 132 | }) |
| 133 | .reducerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#reduce().(|a, b| { |
| 134 | quoterust-analyzer cargo quote 1.0.38 quote!! { |
| 135 | <_ as nalgebra::DimAdd<_>>::add(#a, #b) |
| 136 | } |
| 137 | }) |
| 138 | .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(quoterust-analyzer cargo quote 1.0.38 quote!! { nalgebra::dimension::U0 }); |
| 139 | |
| 140 | // It should be possible to use `uninitialized_generic` here instead |
| 141 | // however that would mean that the macro needs to generate unsafe code |
| 142 | // which does not seem like a great idea. |
| 143 | output.extendrust-analyzer cargo proc-macro2 1.0.93 impl#[TokenStream][`Extend<Self>`]extend().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/once/once().(quoterust-analyzer cargo quote 1.0.38 quote!! { |
| 144 | let mut matrix = nalgebra::Matrix::zeros_generic(#num_rows, #num_cols); |
| 145 | })); |
| 146 | |
| 147 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#n_block_rows { |
| 148 | for j in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#n_block_cols { |
| 149 | let row_dim = format_identrust-analyzer cargo quote 1.0.38 format/format_ident!!("{prefix}_stack_row_{i}_dim"); |
| 150 | let col_dim = format_identrust-analyzer cargo quote 1.0.38 format/format_ident!!("{prefix}_stack_col_{j}_dim"); |
| 151 | let row_offset = format_identrust-analyzer cargo quote 1.0.38 format/format_ident!!("{prefix}_stack_row_{i}_offset"); |
| 152 | let col_offset = format_identrust-analyzer cargo quote 1.0.38 format/format_ident!!("{prefix}_stack_col_{j}_offset"); |
| 153 | let expr = &matrix[rust-analyzer cargo nalgebra-macros 0.3.0 matrix_vector_impl/impl#[Matrix][`Index<(usize, usize)>`]index().(i, j)]rust-analyzer cargo nalgebra-macros 0.3.0 matrix_vector_impl/impl#[Matrix][`Index<(usize, usize)>`]index().; |
| 154 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_literal_zerorust-analyzer cargo nalgebra-macros 0.3.0 stack_impl/is_literal_zero().(expr) { |
| 155 | let expr_ident = format_identrust-analyzer cargo quote 1.0.38 format/format_ident!!("{prefix}_stack_{i}_{j}_block"); |
| 156 | output.extendrust-analyzer cargo proc-macro2 1.0.93 impl#[TokenStream][`Extend<Self>`]extend().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/once/once().(quoterust-analyzer cargo quote 1.0.38 quote!! { |
| 157 | let start = (#row_offset, #col_offset); |
| 158 | let shape = (#row_dim, #col_dim); |
| 159 | let input_view = #expr_ident.generic_view((0, 0), shape); |
| 160 | let mut output_view = matrix.generic_view_mut(start, shape); |
| 161 | output_view.copy_from(&input_view); |
| 162 | })); |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(quoterust-analyzer cargo quote 1.0.38 quote!! { |
| 168 | { |
| 169 | #output |
| 170 | matrix |
| 171 | } |
| 172 | }) |
| 173 | } |
| 174 | |
| 175 | fn is_literal_zerorust-analyzer cargo nalgebra-macros 0.3.0 stack_impl/is_literal_zero().(expr: &Exprrust-analyzer cargo syn 2.0.96 expr/Expr#) -> bool { |
| 176 | matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(expr, |
| 177 | Exprrust-analyzer cargo syn 2.0.96 expr/Expr#::Litrust-analyzer cargo syn 2.0.96 expr/Expr#Lit#(synrust-analyzer cargo syn 2.0.96 crate/::ExprLitrust-analyzer cargo syn 2.0.96 expr/ExprLit# { litrust-analyzer cargo syn 2.0.96 expr/ExprLit#lit.: Litrust-analyzer cargo syn 2.0.96 lit/Lit#::Intrust-analyzer cargo syn 2.0.96 lit/Lit#Int#(integer_literal), .. }) |
| 178 | if integer_literal.base10_digitsrust-analyzer cargo syn 2.0.96 lit/impl#[LitInt]base10_digits().() == "0") |
| 179 | } |
| 180 | |
| 181 | #[cfg(test)] |
| 182 | mod testsrust-analyzer cargo nalgebra-macros 0.3.0 stack_impl/tests/ { |
| 183 | use craterust-analyzer cargo nalgebra-macros 0.3.0 crate/::Matrixrust-analyzer cargo nalgebra-macros 0.3.0 matrix_vector_impl/Matrix#; |
| 184 | use craterust-analyzer cargo nalgebra-macros 0.3.0 crate/::stack_implrust-analyzer cargo nalgebra-macros 0.3.0 stack_impl/::stack_implrust-analyzer cargo nalgebra-macros 0.3.0 stack_impl/stack_impl().; |
| 185 | use quoterust-analyzer cargo quote 1.0.38 crate/::quoterust-analyzer cargo quote 1.0.38 quote!; |
| 186 | |
| 187 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 188 | fn stack_simple_generationrust-analyzer cargo nalgebra-macros 0.3.0 stack_impl/tests/stack_simple_generation().() { |
| 189 | let input: Matrixrust-analyzer cargo nalgebra-macros 0.3.0 matrix_vector_impl/Matrix# = synrust-analyzer cargo syn 2.0.96 crate/::parse_quoterust-analyzer cargo syn 2.0.96 parse_quote/parse_quote!![ |
| 190 | a, 0; |
| 191 | 0, b; |
| 192 | ]; |
| 193 | |
| 194 | let result = stack_implrust-analyzer cargo nalgebra-macros 0.3.0 stack_impl/stack_impl().(input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 195 | |
| 196 | let expected = quoterust-analyzer cargo quote 1.0.38 quote!! {{ |
| 197 | let ref ___na_stack_0_0_block = a; |
| 198 | let ___na_stack_0_0_shape = ___na_stack_0_0_block.shape_generic(); |
| 199 | let ref ___na_stack_1_1_block = b; |
| 200 | let ___na_stack_1_1_shape = ___na_stack_1_1_block.shape_generic(); |
| 201 | let ___na_stack_row_0_dim = ___na_stack_0_0_shape.0; |
| 202 | let ___na_stack_row_0_offset = 0; |
| 203 | let ___na_stack_row_1_dim = ___na_stack_1_1_shape.0; |
| 204 | let ___na_stack_row_1_offset = ___na_stack_row_0_offset + <_ as nalgebra::Dim>::value(&___na_stack_row_0_dim); |
| 205 | let ___na_stack_col_0_dim = ___na_stack_0_0_shape.1; |
| 206 | let ___na_stack_col_0_offset = 0; |
| 207 | let ___na_stack_col_1_dim = ___na_stack_1_1_shape.1; |
| 208 | let ___na_stack_col_1_offset = ___na_stack_col_0_offset + <_ as nalgebra::Dim>::value(&___na_stack_col_0_dim); |
| 209 | let mut matrix = nalgebra::Matrix::zeros_generic( |
| 210 | <_ as nalgebra::DimAdd<_>>::add(___na_stack_row_0_dim, ___na_stack_row_1_dim), |
| 211 | <_ as nalgebra::DimAdd<_>>::add(___na_stack_col_0_dim, ___na_stack_col_1_dim) |
| 212 | ); |
| 213 | let start = (___na_stack_row_0_offset, ___na_stack_col_0_offset); |
| 214 | let shape = (___na_stack_row_0_dim, ___na_stack_col_0_dim); |
| 215 | let input_view = ___na_stack_0_0_block.generic_view((0,0), shape); |
| 216 | let mut output_view = matrix.generic_view_mut(start, shape); |
| 217 | output_view.copy_from(&input_view); |
| 218 | let start = (___na_stack_row_1_offset, ___na_stack_col_1_offset); |
| 219 | let shape = (___na_stack_row_1_dim, ___na_stack_col_1_dim); |
| 220 | let input_view = ___na_stack_1_1_block.generic_view((0,0), shape); |
| 221 | let mut output_view = matrix.generic_view_mut(start, shape); |
| 222 | output_view.copy_from(&input_view); |
| 223 | matrix |
| 224 | }}; |
| 225 | |
| 226 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{result}"), formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}", expected)); |
| 227 | } |
| 228 | |
| 229 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 230 | fn stack_complex_generationrust-analyzer cargo nalgebra-macros 0.3.0 stack_impl/tests/stack_complex_generation().() { |
| 231 | let input: Matrixrust-analyzer cargo nalgebra-macros 0.3.0 matrix_vector_impl/Matrix# = synrust-analyzer cargo syn 2.0.96 crate/::parse_quoterust-analyzer cargo syn 2.0.96 parse_quote/parse_quote!![ |
| 232 | a, 0, b; |
| 233 | 0, c, d; |
| 234 | e, 0, 0; |
| 235 | ]; |
| 236 | |
| 237 | let result = stack_implrust-analyzer cargo nalgebra-macros 0.3.0 stack_impl/stack_impl().(input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 238 | |
| 239 | let expected = quoterust-analyzer cargo quote 1.0.38 quote!! {{ |
| 240 | let ref ___na_stack_0_0_block = a; |
| 241 | let ___na_stack_0_0_shape = ___na_stack_0_0_block.shape_generic(); |
| 242 | let ref ___na_stack_0_2_block = b; |
| 243 | let ___na_stack_0_2_shape = ___na_stack_0_2_block.shape_generic(); |
| 244 | let ref ___na_stack_1_1_block = c; |
| 245 | let ___na_stack_1_1_shape = ___na_stack_1_1_block.shape_generic(); |
| 246 | let ref ___na_stack_1_2_block = d; |
| 247 | let ___na_stack_1_2_shape = ___na_stack_1_2_block.shape_generic(); |
| 248 | let ref ___na_stack_2_0_block = e; |
| 249 | let ___na_stack_2_0_shape = ___na_stack_2_0_block.shape_generic(); |
| 250 | let ___na_stack_row_0_dim = < nalgebra :: constraint :: ShapeConstraint as nalgebra :: constraint :: SameNumberOfRows < _ , _ >> :: representative (___na_stack_0_0_shape . 0 , ___na_stack_0_2_shape . 0) . expect ("All blocks in block row 0 must have the same number of rows") ; |
| 251 | let ___na_stack_row_0_offset = 0; |
| 252 | let ___na_stack_row_1_dim = < nalgebra :: constraint :: ShapeConstraint as nalgebra :: constraint :: SameNumberOfRows < _ , _ >> :: representative (___na_stack_1_1_shape . 0 , ___na_stack_1_2_shape . 0) . expect ("All blocks in block row 1 must have the same number of rows") ; |
| 253 | let ___na_stack_row_1_offset = ___na_stack_row_0_offset + <_ as nalgebra::Dim>::value(&___na_stack_row_0_dim); |
| 254 | let ___na_stack_row_2_dim = ___na_stack_2_0_shape.0; |
| 255 | let ___na_stack_row_2_offset = ___na_stack_row_1_offset + <_ as nalgebra::Dim>::value(&___na_stack_row_1_dim); |
| 256 | let ___na_stack_col_0_dim = < nalgebra :: constraint :: ShapeConstraint as nalgebra :: constraint :: SameNumberOfColumns < _ , _ >> :: representative (___na_stack_0_0_shape . 1 , ___na_stack_2_0_shape . 1) . expect ("All blocks in block column 0 must have the same number of columns") ; |
| 257 | let ___na_stack_col_0_offset = 0; |
| 258 | let ___na_stack_col_1_dim = ___na_stack_1_1_shape.1; |
| 259 | let ___na_stack_col_1_offset = ___na_stack_col_0_offset + <_ as nalgebra::Dim>::value(&___na_stack_col_0_dim); |
| 260 | let ___na_stack_col_2_dim = < nalgebra :: constraint :: ShapeConstraint as nalgebra :: constraint :: SameNumberOfColumns < _ , _ >> :: representative (___na_stack_0_2_shape . 1 , ___na_stack_1_2_shape . 1) . expect ("All blocks in block column 2 must have the same number of columns") ; |
| 261 | let ___na_stack_col_2_offset = ___na_stack_col_1_offset + <_ as nalgebra::Dim>::value(&___na_stack_col_1_dim); |
| 262 | let mut matrix = nalgebra::Matrix::zeros_generic( |
| 263 | <_ as nalgebra::DimAdd<_>>::add( |
| 264 | <_ as nalgebra::DimAdd<_>>::add(___na_stack_row_0_dim, ___na_stack_row_1_dim), |
| 265 | ___na_stack_row_2_dim |
| 266 | ), |
| 267 | <_ as nalgebra::DimAdd<_>>::add( |
| 268 | <_ as nalgebra::DimAdd<_>>::add(___na_stack_col_0_dim, ___na_stack_col_1_dim), |
| 269 | ___na_stack_col_2_dim |
| 270 | ) |
| 271 | ); |
| 272 | let start = (___na_stack_row_0_offset, ___na_stack_col_0_offset); |
| 273 | let shape = (___na_stack_row_0_dim, ___na_stack_col_0_dim); |
| 274 | let input_view = ___na_stack_0_0_block.generic_view((0,0), shape); |
| 275 | let mut output_view = matrix.generic_view_mut(start, shape); |
| 276 | output_view.copy_from(&input_view); |
| 277 | let start = (___na_stack_row_0_offset, ___na_stack_col_2_offset); |
| 278 | let shape = (___na_stack_row_0_dim, ___na_stack_col_2_dim); |
| 279 | let input_view = ___na_stack_0_2_block.generic_view((0,0), shape); |
| 280 | let mut output_view = matrix.generic_view_mut(start, shape); |
| 281 | output_view.copy_from(&input_view); |
| 282 | let start = (___na_stack_row_1_offset, ___na_stack_col_1_offset); |
| 283 | let shape = (___na_stack_row_1_dim, ___na_stack_col_1_dim); |
| 284 | let input_view = ___na_stack_1_1_block.generic_view((0,0), shape); |
| 285 | let mut output_view = matrix.generic_view_mut(start, shape); |
| 286 | output_view.copy_from(&input_view); |
| 287 | let start = (___na_stack_row_1_offset, ___na_stack_col_2_offset); |
| 288 | let shape = (___na_stack_row_1_dim, ___na_stack_col_2_dim); |
| 289 | let input_view = ___na_stack_1_2_block.generic_view((0,0), shape); |
| 290 | let mut output_view = matrix.generic_view_mut(start, shape); |
| 291 | output_view.copy_from(&input_view); |
| 292 | let start = (___na_stack_row_2_offset, ___na_stack_col_0_offset); |
| 293 | let shape = (___na_stack_row_2_dim, ___na_stack_col_0_dim); |
| 294 | let input_view = ___na_stack_2_0_block.generic_view((0,0), shape); |
| 295 | let mut output_view = matrix.generic_view_mut(start, shape); |
| 296 | output_view.copy_from(&input_view); |
| 297 | matrix |
| 298 | }}; |
| 299 | |
| 300 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{result}"), formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}", expected)); |
| 301 | } |
| 302 | } |