max@0: // Copyright (C) 2011 NICTA (www.nicta.com.au) max@0: // Copyright (C) 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 Gen max@0: //! @{ max@0: max@0: max@0: max@0: template max@0: arma_inline max@0: Gen::Gen(const uword in_n_rows, const uword in_n_cols) max@0: : n_rows(in_n_rows) max@0: , n_cols(in_n_cols) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: max@0: max@0: template max@0: arma_inline max@0: Gen::~Gen() max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: max@0: max@0: template max@0: arma_inline max@0: eT max@0: Gen::generate() max@0: { max@0: if(is_same_type::value == true) { return eT(1); } max@0: else if(is_same_type::value == true) { return eT(0); } max@0: else if(is_same_type::value == true) { return eT(eop_aux_randu()); } max@0: else if(is_same_type::value == true) { return eT(eop_aux_randn()); } max@0: else { return eT(); } max@0: } max@0: max@0: max@0: max@0: template max@0: arma_inline max@0: eT max@0: Gen::operator[](const uword i) const max@0: { max@0: if(is_same_type::value == true) max@0: { max@0: return ((i % n_rows) == (i / n_rows)) ? eT(1) : eT(0); max@0: } max@0: else max@0: { max@0: return Gen::generate(); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: arma_inline max@0: eT max@0: Gen::at(const uword row, const uword col) const max@0: { max@0: if(is_same_type::value == true) max@0: { max@0: return (row == col) ? eT(1) : eT(0); max@0: } max@0: else max@0: { max@0: return Gen::generate(); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: Gen::apply(Mat& out) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: // NOTE: we're assuming that the matrix has already been set to the correct size; max@0: // this is done by either the Mat contructor or operator=() max@0: max@0: if(is_same_type::value == true) { out.eye(); } max@0: else if(is_same_type::value == true) { out.ones(); } max@0: else if(is_same_type::value == true) { out.zeros(); } max@0: else if(is_same_type::value == true) { out.randu(); } max@0: else if(is_same_type::value == true) { out.randn(); } max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: Gen::apply_inplace_plus(Mat& out) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "addition"); max@0: max@0: max@0: if(is_same_type::value == true) max@0: { max@0: const uword N = (std::min)(n_rows, n_cols); max@0: max@0: for(uword i=0; i::generate(); max@0: const eT tmp_j = Gen::generate(); max@0: max@0: out_mem[i] += tmp_i; max@0: out_mem[j] += tmp_j; max@0: } max@0: max@0: if(i < n_elem) max@0: { max@0: out_mem[i] += Gen::generate(); max@0: } max@0: } max@0: max@0: } max@0: max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: Gen::apply_inplace_minus(Mat& out) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "subtraction"); max@0: max@0: max@0: if(is_same_type::value == true) max@0: { max@0: const uword N = (std::min)(n_rows, n_cols); max@0: max@0: for(uword i=0; i::generate(); max@0: const eT tmp_j = Gen::generate(); max@0: max@0: out_mem[i] -= tmp_i; max@0: out_mem[j] -= tmp_j; max@0: } max@0: max@0: if(i < n_elem) max@0: { max@0: out_mem[i] -= Gen::generate(); max@0: } max@0: } max@0: max@0: } max@0: max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: Gen::apply_inplace_schur(Mat& out) const max@0: { max@0: arma_extra_debug_sigprint(); 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: max@0: if(is_same_type::value == true) max@0: { max@0: const uword N = (std::min)(n_rows, n_cols); max@0: max@0: for(uword i=0; i::generate(); max@0: const eT tmp_j = Gen::generate(); max@0: max@0: out_mem[i] *= tmp_i; max@0: out_mem[j] *= tmp_j; max@0: } max@0: max@0: if(i < n_elem) max@0: { max@0: out_mem[i] *= Gen::generate(); max@0: } max@0: } max@0: max@0: } max@0: max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: Gen::apply_inplace_div(Mat& out) const max@0: { max@0: arma_extra_debug_sigprint(); 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: max@0: if(is_same_type::value == true) max@0: { max@0: const uword N = (std::min)(n_rows, n_cols); max@0: max@0: for(uword i=0; i::generate(); max@0: const eT tmp_j = Gen::generate(); max@0: max@0: out_mem[i] /= tmp_i; max@0: out_mem[j] /= tmp_j; max@0: } max@0: max@0: if(i < n_elem) max@0: { max@0: out_mem[i] /= Gen::generate(); max@0: } max@0: } max@0: max@0: } max@0: max@0: max@0: max@0: max@0: //! @}