eigen_initializers.hpp
Go to the documentation of this file.
1 // Copyright 2023 Ekumen, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef BELUGA_TEST_UTILS_EIGEN_INITIALIZERS_HPP
16 #define BELUGA_TEST_UTILS_EIGEN_INITIALIZERS_HPP
17 
18 #include <initializer_list>
19 
20 #include <range/v3/view/enumerate.hpp>
21 
22 namespace testing {
23 
24 template <typename Matrix, typename Scalar = typename Matrix::Scalar>
25 Matrix as(std::initializer_list<std::initializer_list<Scalar>> rows) {
26  Matrix matrix;
27  for (auto&& [i, row] : ranges::views::enumerate(rows)) {
28  for (auto&& [j, coeff] : ranges::views::enumerate(row)) {
29  matrix(static_cast<typename Matrix::StorageIndex>(i), static_cast<typename Matrix::StorageIndex>(j)) = coeff;
30  }
31  }
32  return matrix;
33 }
34 
35 } // namespace testing
36 
37 #endif
testing
Definition: eigen_initializers.hpp:22
Matrix
Eigen::Matrix< Scalar, M, N > Matrix
testing::as
Matrix as(std::initializer_list< std::initializer_list< Scalar >> rows)
Definition: eigen_initializers.hpp:25


beluga
Author(s):
autogenerated on Tue Jul 16 2024 02:59:53