20 #define TENSOR_LOAD_IMPL
21 #include <tensor/tensor.h>
26 void permute_12(Tensor<n> &b,
const Tensor<n> &a, index a1, index a2, index a3)
32 typename Tensor<n>::const_iterator ijk_a = a.begin();
33 typename Tensor<n>::iterator k_b = b.begin();
34 for (; a3; a3--, k_b += (a1*a2)) {
35 typename Tensor<n>::iterator jk_b = k_b;
36 for (index j = a2; j--; jk_b++) {
37 typename Tensor<n>::iterator ijk_b = jk_b;
38 for (index i = a1; i--; ijk_a++, ijk_b += a2) {
48 void permute_23(Tensor<n> &b,
const Tensor<n> &a, index a1, index a2, index a3, index a4)
56 typename Tensor<n>::const_iterator ijkl_a = a.begin();
57 typename Tensor<n>::iterator l_b = b.begin();
60 for (; a4--; l_b += a132) {
61 typename Tensor<n>::iterator kl_b = l_b;
62 for (index k = a3; k--; kl_b += a1) {
63 typename Tensor<n>::iterator kjl_b = kl_b;
64 for (index j = a2; j--; kjl_b += a13) {
65 typename Tensor<n>::iterator ikjl_b = kjl_b;
66 for (index i = a1; i--; ijkl_a++, ikjl_b++) {
77 void permute_24(Tensor<n> &b,
const Tensor<n> &a, index a1, index a2, index a3,
86 typename Tensor<n>::const_iterator ijklm_a = a.begin();
87 typename Tensor<n>::iterator m_b = b.begin();
90 index a1432 = a143*a2;
91 for (; a5--; m_b += a1432) {
92 typename Tensor<n>::iterator lm_b = m_b;
93 for (index l = a4; l--; lm_b += a1) {
94 typename Tensor<n>::iterator lkm_b = lm_b;
95 for (index k = a3; k--; lkm_b += a14) {
96 typename Tensor<n>::iterator lkjm_b = lkm_b;
97 for (index j = a2; j--; lkjm_b += a143) {
98 typename Tensor<n>::iterator ilkjm_b = lkjm_b;
99 for (index i = a1; i--; ijklm_a++, ilkjm_b++) {
111 void permute_13(Tensor<n> &b,
const Tensor<n> &a, index a1, index a2, index a3,
120 typename Tensor<n>::const_iterator ijkl_a = a.begin();
121 typename Tensor<n>::iterator l_b = b.begin();
124 for (; a4--; l_b += a321) {
125 typename Tensor<n>::iterator kl_b = l_b;
126 for (index k = a3; k--; kl_b++) {
127 typename Tensor<n>::iterator kjl_b = kl_b;
128 for (index j = a2; j--; kjl_b += a3) {
129 typename Tensor<n>::iterator kjil_b = kjl_b;
130 for (index i = a1; i--; ijkl_a++, kjil_b += a32) {
141 const Tensor<n> do_permute(
const Tensor<n> &a, index ndx1, index ndx2)
143 index n1 = normalize_index(ndx1, a.rank());
144 index n2 = normalize_index(ndx2, a.rank());
147 }
else if (n2 == n1) {
150 Indices new_dims = a.dimensions();
151 index i,a1,a2,a3,a4,a5;
152 for (i = 0, a1 = 1; i < n1; )
155 for (a3 = 1; i < n2;)
158 for (a5 = 1; i < a.rank(); )
161 std::swap(new_dims.at(n1), new_dims.at(n2));
162 Tensor<n> output(new_dims);
167 permute_24(output, a, a1,a2,a3,a4,a5);
169 permute_13(output, a, a2,a3,a4,a5);
172 permute_23(output, a, a1,a2,a4,a5);
174 permute_12(output, a, a2,a4,a5);