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: GenCube::GenCube(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices) max@0: : n_rows (in_n_rows ) max@0: , n_cols (in_n_cols ) max@0: , n_slices(in_n_slices) 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: GenCube::~GenCube() 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: GenCube::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: GenCube::operator[](const uword) const max@0: { max@0: return GenCube::generate(); max@0: } max@0: max@0: max@0: max@0: template max@0: arma_inline max@0: eT max@0: GenCube::at(const uword, const uword, const uword) const max@0: { max@0: return GenCube::generate(); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: GenCube::apply(Cube& out) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: // NOTE: we're assuming that the cube has already been set to the correct size; max@0: // this is done by either the Cube contructor or operator=() max@0: max@0: 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: GenCube::apply_inplace_plus(Cube& 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, out.n_slices, n_rows, n_cols, n_slices, "addition"); max@0: max@0: max@0: eT* out_mem = out.memptr(); max@0: const uword n_elem = out.n_elem; max@0: max@0: uword i,j; max@0: max@0: for(i=0, j=1; j::generate(); max@0: const eT tmp_j = GenCube::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] += GenCube::generate(); max@0: } max@0: } max@0: max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: GenCube::apply_inplace_minus(Cube& 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, out.n_slices, n_rows, n_cols, n_slices, "subtraction"); max@0: max@0: max@0: eT* out_mem = out.memptr(); max@0: const uword n_elem = out.n_elem; max@0: max@0: uword i,j; max@0: max@0: for(i=0, j=1; j::generate(); max@0: const eT tmp_j = GenCube::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] -= GenCube::generate(); max@0: } max@0: } max@0: max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: GenCube::apply_inplace_schur(Cube& 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, out.n_slices, n_rows, n_cols, n_slices, "element-wise multiplication"); max@0: max@0: max@0: eT* out_mem = out.memptr(); max@0: const uword n_elem = out.n_elem; max@0: max@0: uword i,j; max@0: max@0: for(i=0, j=1; j::generate(); max@0: const eT tmp_j = GenCube::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] *= GenCube::generate(); max@0: } max@0: } max@0: max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: GenCube::apply_inplace_div(Cube& 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, out.n_slices, n_rows, n_cols, n_slices, "element-wise division"); max@0: max@0: max@0: eT* out_mem = out.memptr(); max@0: const uword n_elem = out.n_elem; max@0: max@0: uword i,j; max@0: max@0: for(i=0, j=1; j::generate(); max@0: const eT tmp_j = GenCube::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] /= GenCube::generate(); max@0: } max@0: } max@0: max@0: max@0: max@0: max@0: //! @}