1 #ifndef MPQC_MATH_TENSOR_PERMUTE_HPP
2 #define MPQC_MATH_TENSOR_PERMUTE_HPP
4 #include "mpqc/math/tensor/forward.hpp"
5 #include "mpqc/math/tensor/exception.hpp"
7 #include <boost/mpl/int.hpp>
8 #include <boost/mpl/vector_c.hpp>
15 template<
typename T,
class O>
16 void permute_in_place(TensorBase<T,3,O> &t, boost::mpl::vector_c<int,1,0,2>) {
17 const typename TensorBase<T,3,O>::Dims &dims = t.dims();
18 if (dims[0] != dims[1]) {
19 throw TensorDimensionsException(0, 1, dims[0], dims[1]);
21 for (
int k = 0; k < dims[2]; ++k) {
22 for (
int j = 0; j < dims[1]; ++j) {
23 for (
int i = 0; i < j; ++i) {
24 std::swap(t(i,j,k), t(j,i,k));
30 template<
typename T,
class O>
31 void permute_in_place(TensorBase<T,3,O> &t, boost::mpl::vector_c<int,0,2,1>) {
32 const typename TensorBase<T,3,O>::Dims &dims = t.dims();
33 if (dims[1] != dims[2])
34 throw TensorDimensionsException(1, 2, dims[1], dims[2]);
35 for (
int k = 0; k < dims[2]; ++k) {
36 for (
int j = 0; j < k; ++j) {
37 for (
int i = 0; i < dims[0]; ++i) {
38 std::swap(t(i,j,k), t(i,k,j));
44 template<
int I,
int J,
int K,
typename T,
class O>
45 void permute_in_place(TensorBase<T,3,O> &t) {
46 permute_in_place(t, boost::mpl::vector_c<int,I,J,K>());