MPQC 3.0.0-alpha
Loading...
Searching...
No Matches
cast.hpp
1#ifndef MPQC_MATH_TENSOR_CAST_HPP
2#define MPQC_MATH_TENSOR_CAST_HPP
3
4#include "mpqc/math/tensor/ref.hpp"
5#include "mpqc/math/tensor/order.hpp"
6#include <Eigen/Dense>
7
8namespace mpqc {
9
10 template<int N, typename T>
11 Eigen::Map< Eigen::Matrix<T, Eigen::Dynamic, 1> >
12 vector_cast(TensorRef<T,N,TensorColumnMajor> &r) {
13 int n = 1;
14 for (int j = 0; j < N; ++j) {
15 n *= r.dims()[j];
16 }
17 return Eigen::Matrix<T, Eigen::Dynamic, 1>::Map(r.data(), n);
18 }
19
20 template<int M, int N, typename T>
21 Eigen::Map< Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> >
22 matrix_cast(TensorRef<T,M+N,TensorRowMajor> &r) {
23 int m = 1;
24 int n = 1;
25 for (int i = 0; i < M; ++i) {
26 m *= r.dims()[i];
27 }
28 for (int j = 0; j < N; ++j) {
29 n *= r.dims()[j+M];
30 }
31 return Eigen::Matrix<
32 T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor
33 >::Map(r.data(), m, n);
34 }
35
36 template<int M, int N, typename T>
37 Eigen::Map< Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor> >
38 matrix_cast(TensorRef<T,M+N,TensorColumnMajor> &r) {
39 int m = 1;
40 int n = 1;
41 for (int i = 0; i < M; ++i) {
42 m *= r.dims()[i];
43 }
44 for (int j = 0; j < N; ++j) {
45 n *= r.dims()[j+M];
46 }
47 return Eigen::Matrix<
48 T, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor
49 >::Map(r.data(), m, n);
50 }
51
52} // mpqc
53
54
55#endif /* MPQC_MATH_TENSOR_CAST_HPP */
Contains new MPQC code since version 3.
Definition integralenginepool.hpp:37

Generated at Wed Sep 25 2024 02:45:30 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.12.0.