123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- // 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<typename T1>
- inline
- void
- op_flipud::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_flipud>& in)
- {
- arma_extra_debug_sigprint();
-
- const Proxy<T1> P(in.m);
-
- if(is_Mat<typename Proxy<T1>::stored_type>::value || P.is_alias(out))
- {
- const unwrap<typename Proxy<T1>::stored_type> U(P.Q);
-
- op_flipud::apply_direct(out, U.M);
- }
- else
- {
- op_flipud::apply_proxy_noalias(out, P);
- }
- }
- template<typename eT>
- inline
- void
- op_flipud::apply_direct(Mat<eT>& out, const Mat<eT>& 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<typename T1>
- inline
- void
- op_flipud::apply_proxy_noalias(Mat<typename T1::elem_type>& out, const Proxy<T1>& P)
- {
- arma_extra_debug_sigprint();
-
- typedef typename T1::elem_type eT;
-
- 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<T1>::use_at == false) )
- {
- eT* out_mem = out.memptr();
-
- const typename Proxy<T1>::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<typename T1>
- inline
- void
- op_fliplr::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_fliplr>& in)
- {
- arma_extra_debug_sigprint();
-
- const Proxy<T1> P(in.m);
-
- if(is_Mat<typename Proxy<T1>::stored_type>::value || P.is_alias(out))
- {
- const unwrap<typename Proxy<T1>::stored_type> U(P.Q);
-
- op_fliplr::apply_direct(out, U.M);
- }
- else
- {
- op_fliplr::apply_proxy_noalias(out, P);
- }
- }
- template<typename eT>
- inline
- void
- op_fliplr::apply_direct(Mat<eT>& out, const Mat<eT>& 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<typename T1>
- inline
- void
- op_fliplr::apply_proxy_noalias(Mat<typename T1::elem_type>& out, const Proxy<T1>& P)
- {
- arma_extra_debug_sigprint();
-
- typedef typename T1::elem_type eT;
-
- 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<T1>::use_at == false) )
- {
- eT* out_mem = out.memptr();
-
- const typename Proxy<T1>::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);
- }
- }
- }
- }
- //! @}
|