$search
00001 // Copyright (C) 2011 NICTA (www.nicta.com.au) 00002 // Copyright (C) 2011 Conrad Sanderson 00003 // 00004 // This file is part of the Armadillo C++ library. 00005 // It is provided without any warranty of fitness 00006 // for any purpose. You can redistribute this file 00007 // and/or modify it under the terms of the GNU 00008 // Lesser General Public License (LGPL) as published 00009 // by the Free Software Foundation, either version 3 00010 // of the License or (at your option) any later version. 00011 // (see http://www.opensource.org/licenses for more info) 00012 00013 00016 00017 00018 00019 template<typename eT, typename gen_type> 00020 arma_inline 00021 GenCube<eT, gen_type>::GenCube(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices) 00022 : n_rows (in_n_rows ) 00023 , n_cols (in_n_cols ) 00024 , n_slices(in_n_slices) 00025 { 00026 arma_extra_debug_sigprint(); 00027 } 00028 00029 00030 00031 template<typename eT, typename gen_type> 00032 arma_inline 00033 GenCube<eT, gen_type>::~GenCube() 00034 { 00035 arma_extra_debug_sigprint(); 00036 } 00037 00038 00039 00040 template<typename eT, typename gen_type> 00041 arma_inline 00042 eT 00043 GenCube<eT, gen_type>::generate() 00044 { 00045 if(is_same_type<gen_type, gen_ones_full>::value == true) { return eT(1); } 00046 else if(is_same_type<gen_type, gen_zeros >::value == true) { return eT(0); } 00047 else if(is_same_type<gen_type, gen_randu >::value == true) { return eT(eop_aux_randu<eT>()); } 00048 else if(is_same_type<gen_type, gen_randn >::value == true) { return eT(eop_aux_randn<eT>()); } 00049 else { return eT(); } 00050 } 00051 00052 00053 00054 template<typename eT, typename gen_type> 00055 arma_inline 00056 eT 00057 GenCube<eT, gen_type>::operator[](const uword) const 00058 { 00059 return GenCube<eT, gen_type>::generate(); 00060 } 00061 00062 00063 00064 template<typename eT, typename gen_type> 00065 arma_inline 00066 eT 00067 GenCube<eT, gen_type>::at(const uword, const uword, const uword) const 00068 { 00069 return GenCube<eT, gen_type>::generate(); 00070 } 00071 00072 00073 00074 template<typename eT, typename gen_type> 00075 inline 00076 void 00077 GenCube<eT, gen_type>::apply(Cube<eT>& out) const 00078 { 00079 arma_extra_debug_sigprint(); 00080 00081 // NOTE: we're assuming that the cube has already been set to the correct size; 00082 // this is done by either the Cube contructor or operator=() 00083 00084 if(is_same_type<gen_type, gen_ones_full>::value == true) { out.ones(); } 00085 else if(is_same_type<gen_type, gen_zeros >::value == true) { out.zeros(); } 00086 else if(is_same_type<gen_type, gen_randu >::value == true) { out.randu(); } 00087 else if(is_same_type<gen_type, gen_randn >::value == true) { out.randn(); } 00088 } 00089 00090 00091 00092 template<typename eT, typename gen_type> 00093 inline 00094 void 00095 GenCube<eT, gen_type>::apply_inplace_plus(Cube<eT>& out) const 00096 { 00097 arma_extra_debug_sigprint(); 00098 00099 arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "addition"); 00100 00101 00102 eT* out_mem = out.memptr(); 00103 const uword n_elem = out.n_elem; 00104 00105 uword i,j; 00106 00107 for(i=0, j=1; j<n_elem; i+=2, j+=2) 00108 { 00109 const eT tmp_i = GenCube<eT, gen_type>::generate(); 00110 const eT tmp_j = GenCube<eT, gen_type>::generate(); 00111 00112 out_mem[i] += tmp_i; 00113 out_mem[j] += tmp_j; 00114 } 00115 00116 if(i < n_elem) 00117 { 00118 out_mem[i] += GenCube<eT, gen_type>::generate(); 00119 } 00120 } 00121 00122 00123 00124 00125 template<typename eT, typename gen_type> 00126 inline 00127 void 00128 GenCube<eT, gen_type>::apply_inplace_minus(Cube<eT>& out) const 00129 { 00130 arma_extra_debug_sigprint(); 00131 00132 arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "subtraction"); 00133 00134 00135 eT* out_mem = out.memptr(); 00136 const uword n_elem = out.n_elem; 00137 00138 uword i,j; 00139 00140 for(i=0, j=1; j<n_elem; i+=2, j+=2) 00141 { 00142 const eT tmp_i = GenCube<eT, gen_type>::generate(); 00143 const eT tmp_j = GenCube<eT, gen_type>::generate(); 00144 00145 out_mem[i] -= tmp_i; 00146 out_mem[j] -= tmp_j; 00147 } 00148 00149 if(i < n_elem) 00150 { 00151 out_mem[i] -= GenCube<eT, gen_type>::generate(); 00152 } 00153 } 00154 00155 00156 00157 00158 template<typename eT, typename gen_type> 00159 inline 00160 void 00161 GenCube<eT, gen_type>::apply_inplace_schur(Cube<eT>& out) const 00162 { 00163 arma_extra_debug_sigprint(); 00164 00165 arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise multiplication"); 00166 00167 00168 eT* out_mem = out.memptr(); 00169 const uword n_elem = out.n_elem; 00170 00171 uword i,j; 00172 00173 for(i=0, j=1; j<n_elem; i+=2, j+=2) 00174 { 00175 const eT tmp_i = GenCube<eT, gen_type>::generate(); 00176 const eT tmp_j = GenCube<eT, gen_type>::generate(); 00177 00178 out_mem[i] *= tmp_i; 00179 out_mem[j] *= tmp_j; 00180 } 00181 00182 if(i < n_elem) 00183 { 00184 out_mem[i] *= GenCube<eT, gen_type>::generate(); 00185 } 00186 } 00187 00188 00189 00190 00191 template<typename eT, typename gen_type> 00192 inline 00193 void 00194 GenCube<eT, gen_type>::apply_inplace_div(Cube<eT>& out) const 00195 { 00196 arma_extra_debug_sigprint(); 00197 00198 arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise division"); 00199 00200 00201 eT* out_mem = out.memptr(); 00202 const uword n_elem = out.n_elem; 00203 00204 uword i,j; 00205 00206 for(i=0, j=1; j<n_elem; i+=2, j+=2) 00207 { 00208 const eT tmp_i = GenCube<eT, gen_type>::generate(); 00209 const eT tmp_j = GenCube<eT, gen_type>::generate(); 00210 00211 out_mem[i] /= tmp_i; 00212 out_mem[j] /= tmp_j; 00213 } 00214 00215 if(i < n_elem) 00216 { 00217 out_mem[i] /= GenCube<eT, gen_type>::generate(); 00218 } 00219 } 00220 00221 00222 00223