15 #include "etl/temporary.hpp" 24 void inplace_square_transpose(C&& c) {
27 const size_t N = etl::dim<0>(c);
29 for (
size_t i = 0; i < N - 1; ++i) {
32 for (; j + 1 < N; j += 2) {
33 swap(c(i, j + 0), c(j + 0, i));
34 swap(c(i, j + 1), c(j + 1, i));
38 swap(c(i, j), c(j, i));
48 void inplace_rectangular_transpose(C&& mat) {
54 const size_t N = etl::dim<0>(mat);
55 const size_t M = etl::dim<1>(mat);
60 if constexpr (row_major) {
61 for (
size_t i = 0; i < N; ++i) {
64 for (; j + 1 < M; j += 2) {
65 mat[(j + 0) * N + i] = copy(i, (j + 0));
66 mat[(j + 1) * N + i] = copy(i, (j + 1));
70 mat[j * N + i] = copy(i, j);
74 for (
size_t i = 0; i < N; ++i) {
77 for (; j + 1 < M; j += 2) {
78 mat[(j + 0) + M * i] = copy(i, (j + 0));
79 mat[(j + 1) + M * i] = copy(i, (j + 1));
83 mat[j + M * i] = copy(i, j);
101 const size_t N = etl::dim<0>(mat);
102 const size_t M = etl::dim<1>(mat);
104 mat.ensure_cpu_up_to_date();
106 auto data = mat.memory_start();
108 for (
size_t k = 0; k < N * M; k++) {
111 idx = (idx % N) * M + (idx / N);
122 template <
typename A,
typename C>
126 if (etl::dim<0>(a) == etl::dim<1>(a)) {
127 inplace_square_transpose(c);
129 inplace_rectangular_transpose(c);
132 const size_t m = etl::dim<0>(a);
133 const size_t n = etl::dim<1>(a);
139 for (
size_t i = 0; i < m; ++i) {
142 for (; j + 3 < n; j += 4) {
143 c[(j + 0) * m + i] = a[i * n + j + 0];
144 c[(j + 1) * m + i] = a[i * n + j + 1];
145 c[(j + 2) * m + i] = a[i * n + j + 2];
146 c[(j + 3) * m + i] = a[i * n + j + 3];
149 for (; j + 1 < n; j += 2) {
150 c[(j + 0) * m + i] = a[i * n + j + 0];
151 c[(j + 1) * m + i] = a[i * n + j + 1];
155 c[(j + 0) * m + i] = a[i * n + j];
159 for (
size_t j = 0; j < n; ++j) {
160 for (
size_t i = 0; i < m; ++i) {
161 c[i * n + j] = a[j * m + i];
Definition: prob_pooling.hpp:10
auto transpose(const E &value)
Returns the transpose of the given expression.
Definition: expression_builder.hpp:528
Traits to get information about ETL types.
Definition: tmp.hpp:68
void swap(custom_dyn_matrix_impl< T, SO, D > &lhs, custom_dyn_matrix_impl< T, SO, D > &rhs)
Swap two dyn matrix.
Definition: custom_dyn.hpp:403
decltype(auto) force_temporary(E &&expr)
Force a temporary out of the expression.
Definition: temporary.hpp:91
void real_inplace(C &&mat)
Perform an inplace matrix transposition in O(1).
Definition: transpose.hpp:98