OGS
TransposeInPlace.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
6#include <vector>
7
9
10namespace ProcessLib
11{
16template <int Components, typename StoreValuesFunction>
17std::vector<double> transposeInPlace(
18 StoreValuesFunction const& store_values_function)
19{
20 std::vector<double> result;
21 store_values_function(result);
23 Eigen::Matrix<double, Eigen::Dynamic, Components, Eigen::RowMajor>>(
24 result, result.size() / Components, Components) =
26 Eigen::Matrix<double, Components, Eigen::Dynamic, Eigen::RowMajor>>(
27 result, Components, result.size() / Components)
28 .transpose()
29 .eval();
30
31 return result;
32}
33
34template <int Components>
35void transposeInPlace(std::vector<double>& values)
36{
38 Eigen::Matrix<double, Eigen::Dynamic, Components, Eigen::RowMajor>>(
39 values, values.size() / Components, Components) =
41 Eigen::Matrix<double, Components, Eigen::Dynamic, Eigen::RowMajor>>(
42 values, Components, values.size() / Components)
43 .transpose()
44 .eval();
45}
46
47inline void transposeInPlace(std::vector<double>& values,
48 unsigned const num_components)
49{
51 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>>(
52 values, values.size() / num_components, num_components) =
53 MathLib::toMatrix<Eigen::Matrix<double,
54 Eigen::Dynamic,
55 Eigen::Dynamic,
56 Eigen::RowMajor>>(
57 values, num_components, values.size() / num_components)
58 .transpose()
59 .eval();
60}
61
62} // namespace ProcessLib
Eigen::Map< const Matrix > toMatrix(std::vector< double > const &data, Eigen::MatrixXd::Index rows, Eigen::MatrixXd::Index cols)
std::vector< double > transposeInPlace(StoreValuesFunction const &store_values_function)