From eda5bc26f44ee9a6f83dcf8c91f17296d7fc509d Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Mon, 12 Feb 2024 14:52:43 +0100 Subject: Move into version control --- .../include/armadillo_bits/op_flip_meat.hpp | 341 +++++++++++++++++++++ 1 file changed, 341 insertions(+) create mode 100644 src/armadillo/include/armadillo_bits/op_flip_meat.hpp (limited to 'src/armadillo/include/armadillo_bits/op_flip_meat.hpp') diff --git a/src/armadillo/include/armadillo_bits/op_flip_meat.hpp b/src/armadillo/include/armadillo_bits/op_flip_meat.hpp new file mode 100644 index 0000000..470ae92 --- /dev/null +++ b/src/armadillo/include/armadillo_bits/op_flip_meat.hpp @@ -0,0 +1,341 @@ +// SPDX-License-Identifier: Apache-2.0 +// +// Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au) +// Copyright 2008-2016 National ICT Australia (NICTA) +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------------------------------------------ + + +//! \addtogroup op_flip +//! @{ + + + +template +inline +void +op_flipud::apply(Mat& out, const Op& in) + { + arma_extra_debug_sigprint(); + + typedef typename T1::elem_type eT; + + if(is_Mat::value) + { + // allow detection of in-place operation + + const unwrap U(in.m); + + op_flipud::apply_direct(out, U.M); + } + else + { + const Proxy P(in.m); + + if(P.is_alias(out)) + { + Mat tmp; + + op_flipud::apply_proxy_noalias(tmp, P); + + out.steal_mem(tmp); + } + else + { + op_flipud::apply_proxy_noalias(out, P); + } + } + } + + + +template +inline +void +op_flipud::apply_direct(Mat& out, const Mat& X) + { + arma_extra_debug_sigprint(); + + const uword X_n_rows = X.n_rows; + const uword X_n_cols = X.n_cols; + + const uword X_n_rows_m1 = X_n_rows - 1; + + if(&out != &X) + { + out.set_size(X_n_rows, X_n_cols); + + if(X_n_cols == 1) + { + const eT* X_mem = X.memptr(); + eT* out_mem = out.memptr(); + + for(uword row=0; row < X_n_rows; ++row) + { + out_mem[X_n_rows_m1 - row] = X_mem[row]; + } + } + else + { + for(uword col=0; col < X_n_cols; ++col) + { + const eT* X_colmem = X.colptr(col); + eT* out_colmem = out.colptr(col); + + for(uword row=0; row < X_n_rows; ++row) + { + out_colmem[X_n_rows_m1 - row] = X_colmem[row]; + } + } + } + } + else // in-place operation + { + const uword N = X_n_rows / 2; + + if(X_n_cols == 1) + { + eT* out_mem = out.memptr(); + + for(uword row=0; row < N; ++row) + { + std::swap(out_mem[X_n_rows_m1 - row], out_mem[row]); + } + } + else + { + for(uword col=0; col < X_n_cols; ++col) + { + eT* out_colmem = out.colptr(col); + + for(uword row=0; row < N; ++row) + { + std::swap(out_colmem[X_n_rows_m1 - row], out_colmem[row]); + } + } + } + } + } + + + +template +inline +void +op_flipud::apply_proxy_noalias(Mat& out, const Proxy& P) + { + arma_extra_debug_sigprint(); + + typedef typename T1::elem_type eT; + + typedef typename Proxy::stored_type P_stored_type; + + if(is_Mat::value) + { + const unwrap U(P.Q); + + op_flipud::apply_direct(out, U.M); + + return; + } + + const uword P_n_rows = P.get_n_rows(); + const uword P_n_cols = P.get_n_cols(); + + const uword P_n_rows_m1 = P_n_rows - 1; + + out.set_size(P_n_rows, P_n_cols); + + if( ((T1::is_col) || (P_n_cols == 1)) && (Proxy::use_at == false) ) + { + eT* out_mem = out.memptr(); + + const typename Proxy::ea_type P_ea = P.get_ea(); + + for(uword row=0; row < P_n_rows; ++row) + { + out_mem[P_n_rows_m1 - row] = P_ea[row]; + } + } + else + { + for(uword col=0; col < P_n_cols; ++col) + { + eT* out_colmem = out.colptr(col); + + for(uword row=0; row < P_n_rows; ++row) + { + out_colmem[P_n_rows_m1 - row] = P.at(row, col); + } + } + } + } + + + +// + + + +template +inline +void +op_fliplr::apply(Mat& out, const Op& in) + { + arma_extra_debug_sigprint(); + + typedef typename T1::elem_type eT; + + if(is_Mat::value) + { + // allow detection of in-place operation + + const unwrap U(in.m); + + op_fliplr::apply_direct(out, U.M); + } + else + { + const Proxy P(in.m); + + if(P.is_alias(out)) + { + Mat tmp; + + op_fliplr::apply_proxy_noalias(tmp, P); + + out.steal_mem(tmp); + } + else + { + op_fliplr::apply_proxy_noalias(out, P); + } + } + } + + + +template +inline +void +op_fliplr::apply_direct(Mat& out, const Mat& X) + { + arma_extra_debug_sigprint(); + + const uword X_n_rows = X.n_rows; + const uword X_n_cols = X.n_cols; + + const uword X_n_cols_m1 = X_n_cols - 1; + + if(&out != &X) + { + out.set_size(X_n_rows, X_n_cols); + + if(X_n_rows == 1) + { + const eT* X_mem = X.memptr(); + eT* out_mem = out.memptr(); + + for(uword col=0; col < X_n_cols; ++col) + { + out_mem[X_n_cols_m1 - col] = X_mem[col]; + } + } + else + { + for(uword col=0; col < X_n_cols; ++col) + { + out.col(X_n_cols_m1 - col) = X.col(col); + } + } + } + else // in-place operation + { + const uword N = X_n_cols / 2; + + if(X_n_rows == 1) + { + eT* out_mem = out.memptr(); + + for(uword col=0; col < N; ++col) + { + std::swap(out_mem[X_n_cols_m1 - col], out_mem[col]); + } + } + else + { + for(uword col=0; col < N; ++col) + { + out.swap_cols(X_n_cols_m1 - col, col); + } + } + } + } + + + +template +inline +void +op_fliplr::apply_proxy_noalias(Mat& out, const Proxy& P) + { + arma_extra_debug_sigprint(); + + typedef typename T1::elem_type eT; + + typedef typename Proxy::stored_type P_stored_type; + + if(is_Mat::value) + { + const unwrap U(P.Q); + + op_fliplr::apply_direct(out, U.M); + + return; + } + + const uword P_n_rows = P.get_n_rows(); + const uword P_n_cols = P.get_n_cols(); + + const uword P_n_cols_m1 = P_n_cols - 1; + + out.set_size(P_n_rows, P_n_cols); + + if( ((T1::is_row) || (P_n_rows == 1)) && (Proxy::use_at == false) ) + { + eT* out_mem = out.memptr(); + + const typename Proxy::ea_type P_ea = P.get_ea(); + + for(uword col=0; col < P_n_cols; ++col) + { + out_mem[P_n_cols_m1 - col] = P_ea[col]; + } + } + else + { + for(uword col=0; col < P_n_cols; ++col) + { + eT* out_colmem = out.colptr(P_n_cols_m1 - col); + + for(uword row=0; row < P_n_rows; ++row) + { + out_colmem[row] = P.at(row,col); + } + } + } + } + + + +//! @} -- cgit v1.2.1