max@0: // Copyright (C) 2010-2011 NICTA (www.nicta.com.au) max@0: // Copyright (C) 2010-2011 Conrad Sanderson max@0: // max@0: // This file is part of the Armadillo C++ library. max@0: // It is provided without any warranty of fitness max@0: // for any purpose. You can redistribute this file max@0: // and/or modify it under the terms of the GNU max@0: // Lesser General Public License (LGPL) as published max@0: // by the Free Software Foundation, either version 3 max@0: // of the License or (at your option) any later version. max@0: // (see http://www.opensource.org/licenses for more info) max@0: max@0: max@0: //! \addtogroup eop_core max@0: //! @{ max@0: max@0: max@0: #undef arma_applier_1 max@0: #undef arma_applier_2 max@0: #undef arma_applier_3 max@0: #undef operatorA max@0: max@0: #define arma_applier_1(operatorA) \ max@0: {\ max@0: uword i,j;\ max@0: \ max@0: for(i=0, j=1; j::process(tmp_i, k);\ max@0: tmp_j = eop_core::process(tmp_j, k);\ max@0: \ max@0: out_mem[i] operatorA tmp_i;\ max@0: out_mem[j] operatorA tmp_j;\ max@0: }\ max@0: \ max@0: if(i < n_elem)\ max@0: {\ max@0: out_mem[i] operatorA eop_core::process(P[i], k);\ max@0: }\ max@0: } max@0: max@0: max@0: #define arma_applier_2(operatorA) \ max@0: {\ max@0: uword count = 0;\ max@0: \ max@0: for(uword col=0; col::process(tmp_i, k);\ max@0: tmp_j = eop_core::process(tmp_j, k);\ max@0: \ max@0: out_mem[count ] operatorA tmp_i;\ max@0: out_mem[count+1] operatorA tmp_j;\ max@0: }\ max@0: \ max@0: if(i < n_rows)\ max@0: {\ max@0: out_mem[count] operatorA eop_core::process(P.at(i,col), k);\ max@0: ++count;\ max@0: }\ max@0: }\ max@0: } max@0: max@0: max@0: max@0: #define arma_applier_3(operatorA) \ max@0: {\ max@0: uword count = 0;\ max@0: \ max@0: for(uword slice=0; slice::process(tmp_i, k);\ max@0: tmp_j = eop_core::process(tmp_j, k);\ max@0: \ max@0: out_mem[count ] operatorA tmp_i;\ max@0: out_mem[count+1] operatorA tmp_j;\ max@0: }\ max@0: \ max@0: if(i < n_rows)\ max@0: {\ max@0: out_mem[count] operatorA eop_core::process(P.at(i,col,slice), k);\ max@0: ++count;\ max@0: }\ max@0: }\ max@0: }\ max@0: } max@0: max@0: max@0: max@0: // max@0: // matrices max@0: max@0: max@0: max@0: template max@0: template max@0: arma_hot max@0: inline max@0: void max@0: eop_core::apply(Mat& out, const eOp& x) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: typedef typename T1::elem_type eT; max@0: max@0: const uword n_rows = out.n_rows; max@0: const uword n_cols = out.n_cols; max@0: const uword n_elem = out.n_elem; max@0: max@0: // NOTE: we're assuming that the matrix has already been set to the correct size and there is no aliasing; max@0: // size setting and alias checking is done by either the Mat contructor or operator=() max@0: max@0: const eT k = x.aux; max@0: eT* out_mem = out.memptr(); max@0: max@0: if(Proxy::prefer_at_accessor == false) max@0: { max@0: typename Proxy::ea_type P = x.P.get_ea(); max@0: max@0: arma_applier_1(=); max@0: } max@0: else max@0: { max@0: const Proxy& P = x.P; max@0: max@0: arma_applier_2(=); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: arma_hot max@0: inline max@0: void max@0: eop_core::apply_inplace_plus(Mat& out, const eOp& x) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: typedef typename T1::elem_type eT; max@0: max@0: const uword n_rows = x.get_n_rows(); max@0: const uword n_cols = x.get_n_cols(); max@0: max@0: arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "addition"); max@0: max@0: eT* out_mem = out.memptr(); max@0: const uword n_elem = out.n_elem; max@0: max@0: const eT k = x.aux; max@0: max@0: if(Proxy::prefer_at_accessor == false) max@0: { max@0: typename Proxy::ea_type P = x.P.get_ea(); max@0: max@0: arma_applier_1(+=); max@0: } max@0: else max@0: { max@0: const Proxy& P = x.P; max@0: max@0: arma_applier_2(+=); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: arma_hot max@0: inline max@0: void max@0: eop_core::apply_inplace_minus(Mat& out, const eOp& x) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: typedef typename T1::elem_type eT; max@0: max@0: const uword n_rows = x.get_n_rows(); max@0: const uword n_cols = x.get_n_cols(); max@0: max@0: arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "subtraction"); max@0: max@0: eT* out_mem = out.memptr(); max@0: const uword n_elem = out.n_elem; max@0: max@0: const eT k = x.aux; max@0: max@0: if(Proxy::prefer_at_accessor == false) max@0: { max@0: typename Proxy::ea_type P = x.P.get_ea(); max@0: max@0: arma_applier_1(-=); max@0: } max@0: else max@0: { max@0: const Proxy& P = x.P; max@0: max@0: arma_applier_2(-=); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: arma_hot max@0: inline max@0: void max@0: eop_core::apply_inplace_schur(Mat& out, const eOp& x) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: typedef typename T1::elem_type eT; max@0: max@0: const uword n_rows = x.get_n_rows(); max@0: const uword n_cols = x.get_n_cols(); max@0: max@0: arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "element-wise multiplication"); max@0: max@0: eT* out_mem = out.memptr(); max@0: const uword n_elem = out.n_elem; max@0: max@0: const eT k = x.aux; max@0: max@0: if(Proxy::prefer_at_accessor == false) max@0: { max@0: typename Proxy::ea_type P = x.P.get_ea(); max@0: max@0: arma_applier_1(*=); max@0: } max@0: else max@0: { max@0: const Proxy& P = x.P; max@0: max@0: arma_applier_2(*=); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: arma_hot max@0: inline max@0: void max@0: eop_core::apply_inplace_div(Mat& out, const eOp& x) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: typedef typename T1::elem_type eT; max@0: max@0: const uword n_rows = x.get_n_rows(); max@0: const uword n_cols = x.get_n_cols(); max@0: max@0: arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "element-wise division"); max@0: max@0: eT* out_mem = out.memptr(); max@0: const uword n_elem = out.n_elem; max@0: max@0: const eT k = x.aux; max@0: max@0: if(Proxy::prefer_at_accessor == false) max@0: { max@0: typename Proxy::ea_type P = x.P.get_ea(); max@0: max@0: arma_applier_1(/=); max@0: } max@0: else max@0: { max@0: const Proxy& P = x.P; max@0: max@0: arma_applier_2(/=); max@0: } max@0: } max@0: max@0: max@0: max@0: // max@0: // cubes max@0: max@0: max@0: max@0: template max@0: template max@0: arma_hot max@0: inline max@0: void max@0: eop_core::apply(Cube& out, const eOpCube& x) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: typedef typename T1::elem_type eT; max@0: max@0: const uword n_rows = out.n_rows; max@0: const uword n_cols = out.n_cols; max@0: const uword n_slices = out.n_slices; max@0: const uword n_elem = out.n_elem; max@0: max@0: // NOTE: we're assuming that the matrix has already been set to the correct size and there is no aliasing; max@0: // size setting and alias checking is done by either the Mat contructor or operator=() max@0: max@0: const eT k = x.aux; max@0: eT* out_mem = out.memptr(); max@0: max@0: if(ProxyCube::prefer_at_accessor == false) max@0: { max@0: typename ProxyCube::ea_type P = x.P.get_ea(); max@0: max@0: arma_applier_1(=); max@0: } max@0: else max@0: { max@0: const ProxyCube& P = x.P; max@0: max@0: arma_applier_3(=); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: arma_hot max@0: inline max@0: void max@0: eop_core::apply_inplace_plus(Cube& out, const eOpCube& x) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: typedef typename T1::elem_type eT; max@0: max@0: const uword n_rows = x.get_n_rows(); max@0: const uword n_cols = x.get_n_cols(); max@0: const uword n_slices = x.get_n_slices(); max@0: max@0: arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "addition"); max@0: max@0: eT* out_mem = out.memptr(); max@0: const uword n_elem = out.n_elem; max@0: max@0: const eT k = x.aux; max@0: max@0: if(ProxyCube::prefer_at_accessor == false) max@0: { max@0: typename ProxyCube::ea_type P = x.P.get_ea(); max@0: max@0: arma_applier_1(+=); max@0: } max@0: else max@0: { max@0: const ProxyCube& P = x.P; max@0: max@0: arma_applier_3(+=); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: arma_hot max@0: inline max@0: void max@0: eop_core::apply_inplace_minus(Cube& out, const eOpCube& x) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: typedef typename T1::elem_type eT; max@0: max@0: const uword n_rows = x.get_n_rows(); max@0: const uword n_cols = x.get_n_cols(); max@0: const uword n_slices = x.get_n_slices(); max@0: max@0: arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "subtraction"); max@0: max@0: eT* out_mem = out.memptr(); max@0: const uword n_elem = out.n_elem; max@0: max@0: const eT k = x.aux; max@0: max@0: if(ProxyCube::prefer_at_accessor == false) max@0: { max@0: typename ProxyCube::ea_type P = x.P.get_ea(); max@0: max@0: arma_applier_1(-=); max@0: } max@0: else max@0: { max@0: const ProxyCube& P = x.P; max@0: max@0: arma_applier_3(-=); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: arma_hot max@0: inline max@0: void max@0: eop_core::apply_inplace_schur(Cube& out, const eOpCube& x) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: typedef typename T1::elem_type eT; max@0: max@0: const uword n_rows = x.get_n_rows(); max@0: const uword n_cols = x.get_n_cols(); max@0: const uword n_slices = x.get_n_slices(); max@0: max@0: arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise multiplication"); max@0: max@0: eT* out_mem = out.memptr(); max@0: const uword n_elem = out.n_elem; max@0: max@0: const eT k = x.aux; max@0: max@0: if(ProxyCube::prefer_at_accessor == false) max@0: { max@0: typename ProxyCube::ea_type P = x.P.get_ea(); max@0: max@0: arma_applier_1(*=); max@0: } max@0: else max@0: { max@0: const ProxyCube& P = x.P; max@0: max@0: arma_applier_3(*=); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: arma_hot max@0: inline max@0: void max@0: eop_core::apply_inplace_div(Cube& out, const eOpCube& x) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: typedef typename T1::elem_type eT; max@0: max@0: const uword n_rows = x.get_n_rows(); max@0: const uword n_cols = x.get_n_cols(); max@0: const uword n_slices = x.get_n_slices(); max@0: max@0: arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise division"); max@0: max@0: eT* out_mem = out.memptr(); max@0: const uword n_elem = out.n_elem; max@0: max@0: const eT k = x.aux; max@0: max@0: if(ProxyCube::prefer_at_accessor == false) max@0: { max@0: typename ProxyCube::ea_type P = x.P.get_ea(); max@0: max@0: arma_applier_1(/=); max@0: } max@0: else max@0: { max@0: const ProxyCube& P = x.P; max@0: max@0: arma_applier_3(/=); max@0: } max@0: } max@0: max@0: max@0: max@0: // max@0: // common max@0: max@0: max@0: max@0: template max@0: template max@0: arma_hot max@0: arma_pure max@0: arma_inline max@0: eT max@0: eop_core::process(const eT val, const eT k) max@0: { max@0: arma_ignore(val); max@0: arma_ignore(k); max@0: max@0: arma_stop("eop_core::process(): unhandled eop_type"); max@0: return eT(0); max@0: } max@0: max@0: max@0: max@0: template<> template arma_hot arma_const arma_inline eT max@0: eop_core::process(const eT val, const eT k) { return val + k; } max@0: max@0: template<> template arma_hot arma_const arma_inline eT max@0: eop_core::process(const eT val, const eT k) { return k - val; } max@0: max@0: template<> template arma_hot arma_const arma_inline eT max@0: eop_core::process(const eT val, const eT k) { return val - k; } max@0: max@0: template<> template arma_hot arma_const arma_inline eT max@0: eop_core::process(const eT val, const eT k) { return val * k; } max@0: max@0: template<> template arma_hot arma_const arma_inline eT max@0: eop_core::process(const eT val, const eT k) { return k / val; } max@0: max@0: template<> template arma_hot arma_const arma_inline eT max@0: eop_core::process(const eT val, const eT k) { return val / k; } max@0: max@0: template<> template arma_hot arma_const arma_inline eT max@0: eop_core::process(const eT val, const eT ) { return val*val; } max@0: max@0: template<> template arma_hot arma_const arma_inline eT max@0: eop_core::process(const eT val, const eT ) { return eop_aux::neg(val); } max@0: max@0: template<> template arma_hot arma_pure arma_inline eT max@0: eop_core::process(const eT val, const eT ) { return eop_aux::sqrt(val); } max@0: max@0: template<> template arma_hot arma_pure arma_inline eT max@0: eop_core::process(const eT val, const eT ) { return eop_aux::log(val); } max@0: max@0: template<> template arma_hot arma_pure arma_inline eT max@0: eop_core::process(const eT val, const eT ) { return eop_aux::log2(val); } max@0: max@0: template<> template arma_hot arma_pure arma_inline eT max@0: eop_core::process(const eT val, const eT ) { return eop_aux::log10(val); } max@0: max@0: template<> template arma_hot arma_pure arma_inline eT max@0: eop_core::process(const eT val, const eT ) { return arma::trunc_log(val); } max@0: max@0: template<> template arma_hot arma_pure arma_inline eT max@0: eop_core::process(const eT val, const eT ) { return eop_aux::exp(val); } max@0: max@0: template<> template arma_hot arma_pure arma_inline eT max@0: eop_core::process(const eT val, const eT ) { return eop_aux::exp2(val); } max@0: max@0: template<> template arma_hot arma_pure arma_inline eT max@0: eop_core::process(const eT val, const eT ) { return eop_aux::exp10(val); } max@0: max@0: template<> template arma_hot arma_pure arma_inline eT max@0: eop_core::process(const eT val, const eT ) { return arma::trunc_exp(val); } max@0: max@0: template<> template arma_hot arma_pure arma_inline eT max@0: eop_core::process(const eT val, const eT ) { return eop_aux::cos(val); } max@0: max@0: template<> template arma_hot arma_pure arma_inline eT max@0: eop_core::process(const eT val, const eT ) { return eop_aux::sin(val); } max@0: max@0: template<> template arma_hot arma_pure arma_inline eT max@0: eop_core::process(const eT val, const eT ) { return eop_aux::tan(val); } max@0: max@0: template<> template arma_hot arma_pure arma_inline eT max@0: eop_core::process(const eT val, const eT ) { return eop_aux::acos(val); } max@0: max@0: template<> template arma_hot arma_pure arma_inline eT max@0: eop_core::process(const eT val, const eT ) { return eop_aux::asin(val); } max@0: max@0: template<> template arma_hot arma_pure arma_inline eT max@0: eop_core::process(const eT val, const eT ) { return eop_aux::atan(val); } max@0: max@0: template<> template arma_hot arma_pure arma_inline eT max@0: eop_core::process(const eT val, const eT ) { return eop_aux::cosh(val); } max@0: max@0: template<> template arma_hot arma_pure arma_inline eT max@0: eop_core::process(const eT val, const eT ) { return eop_aux::sinh(val); } max@0: max@0: template<> template arma_hot arma_pure arma_inline eT max@0: eop_core::process(const eT val, const eT ) { return eop_aux::tanh(val); } max@0: max@0: template<> template arma_hot arma_pure arma_inline eT max@0: eop_core::process(const eT val, const eT ) { return eop_aux::acosh(val); } max@0: max@0: template<> template arma_hot arma_pure arma_inline eT max@0: eop_core::process(const eT val, const eT ) { return eop_aux::asinh(val); } max@0: max@0: template<> template arma_hot arma_pure arma_inline eT max@0: eop_core::process(const eT val, const eT ) { return eop_aux::atanh(val); } max@0: max@0: template<> template arma_hot arma_pure arma_inline eT max@0: eop_core::process(const eT val, const eT ) { return eop_aux::direct_eps(val); } max@0: max@0: template<> template arma_hot arma_pure arma_inline eT max@0: eop_core::process(const eT val, const eT ) { return eop_aux::arma_abs(val); } max@0: max@0: template<> template arma_hot arma_pure arma_inline eT max@0: eop_core::process(const eT val, const eT ) { return eop_aux::conj(val); } max@0: max@0: template<> template arma_hot arma_pure arma_inline eT max@0: eop_core::process(const eT val, const eT k) { return eop_aux::pow(val, k); } max@0: max@0: template<> template arma_hot arma_pure arma_inline eT max@0: eop_core::process(const eT val, const eT ) { return eop_aux::floor(val); } max@0: max@0: template<> template arma_hot arma_pure arma_inline eT max@0: eop_core::process(const eT val, const eT ) { return eop_aux::ceil(val); } max@0: max@0: max@0: max@0: #undef arma_applier_1 max@0: #undef arma_applier_2 max@0: #undef arma_applier_3 max@0: max@0: max@0: max@0: //! @}