OPAL (Object Oriented Parallel Accelerator Library)  2024.1
OPAL
BoostMatrix.h
Go to the documentation of this file.
1 //
2 // This header file is made to facilitate boost's matrix and vector_t operations in OPAL.
3 //
4 // Copyright (c) 2023, Paul Scherrer Institute, Villigen PSI, Switzerland
5 // All rights reserved
6 //
7 // This file is part of OPAL.
8 //
9 // OPAL is free software: you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 3 of the License, or
12 // (at your option) any later version.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
16 //
17 
18 #ifndef OPAL_MATRIX_HH
19 #define OPAL_MATRIX_HH
20 
21 #include <boost/numeric/ublas/matrix.hpp>
22 
23 typedef boost::numeric::ublas::matrix<double> matrix_t;
24 
25 template<class T>
26 T prod_boost_vector(const boost::numeric::ublas::matrix<double>& rotation, const T& vector) {
27 
28  // Create a temporary result vector
29  T result;
30 
31  // Perform matrix-vector multiplication directly without copying
32  for (std::size_t i = 0; i < 3; ++i) {
33  result(i) = 0;
34  for (std::size_t j = 0; j < 3; ++j) {
35  result(i) += rotation(i, j) * vector(j);
36  }
37  }
38 
39  return result;
40 }
41 
42 #endif
boost::numeric::ublas::matrix< double > matrix_t
Definition: BoostMatrix.h:23
T prod_boost_vector(const boost::numeric::ublas::matrix< double > &rotation, const T &vector)
Definition: BoostMatrix.h:26
float result
Definition: test.py:2