annotate armadillo-2.4.4/include/armadillo_bits/GenCube_meat.hpp @ 18:8d046a9d36aa slimline

Back out rev 13:ac07c60aa798. Like an idiot, I committed a whole pile of unrelated changes in the guise of a single typo fix. Will re-commit in stages
author Chris Cannam
date Thu, 10 May 2012 10:45:44 +0100
parents 8b6102e2a9b0
children
rev   line source
max@0 1 // Copyright (C) 2011 NICTA (www.nicta.com.au)
max@0 2 // Copyright (C) 2011 Conrad Sanderson
max@0 3 //
max@0 4 // This file is part of the Armadillo C++ library.
max@0 5 // It is provided without any warranty of fitness
max@0 6 // for any purpose. You can redistribute this file
max@0 7 // and/or modify it under the terms of the GNU
max@0 8 // Lesser General Public License (LGPL) as published
max@0 9 // by the Free Software Foundation, either version 3
max@0 10 // of the License or (at your option) any later version.
max@0 11 // (see http://www.opensource.org/licenses for more info)
max@0 12
max@0 13
max@0 14 //! \addtogroup Gen
max@0 15 //! @{
max@0 16
max@0 17
max@0 18
max@0 19 template<typename eT, typename gen_type>
max@0 20 arma_inline
max@0 21 GenCube<eT, gen_type>::GenCube(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices)
max@0 22 : n_rows (in_n_rows )
max@0 23 , n_cols (in_n_cols )
max@0 24 , n_slices(in_n_slices)
max@0 25 {
max@0 26 arma_extra_debug_sigprint();
max@0 27 }
max@0 28
max@0 29
max@0 30
max@0 31 template<typename eT, typename gen_type>
max@0 32 arma_inline
max@0 33 GenCube<eT, gen_type>::~GenCube()
max@0 34 {
max@0 35 arma_extra_debug_sigprint();
max@0 36 }
max@0 37
max@0 38
max@0 39
max@0 40 template<typename eT, typename gen_type>
max@0 41 arma_inline
max@0 42 eT
max@0 43 GenCube<eT, gen_type>::generate()
max@0 44 {
max@0 45 if(is_same_type<gen_type, gen_ones_full>::value == true) { return eT(1); }
max@0 46 else if(is_same_type<gen_type, gen_zeros >::value == true) { return eT(0); }
max@0 47 else if(is_same_type<gen_type, gen_randu >::value == true) { return eT(eop_aux_randu<eT>()); }
max@0 48 else if(is_same_type<gen_type, gen_randn >::value == true) { return eT(eop_aux_randn<eT>()); }
max@0 49 else { return eT(); }
max@0 50 }
max@0 51
max@0 52
max@0 53
max@0 54 template<typename eT, typename gen_type>
max@0 55 arma_inline
max@0 56 eT
max@0 57 GenCube<eT, gen_type>::operator[](const uword) const
max@0 58 {
max@0 59 return GenCube<eT, gen_type>::generate();
max@0 60 }
max@0 61
max@0 62
max@0 63
max@0 64 template<typename eT, typename gen_type>
max@0 65 arma_inline
max@0 66 eT
max@0 67 GenCube<eT, gen_type>::at(const uword, const uword, const uword) const
max@0 68 {
max@0 69 return GenCube<eT, gen_type>::generate();
max@0 70 }
max@0 71
max@0 72
max@0 73
max@0 74 template<typename eT, typename gen_type>
max@0 75 inline
max@0 76 void
max@0 77 GenCube<eT, gen_type>::apply(Cube<eT>& out) const
max@0 78 {
max@0 79 arma_extra_debug_sigprint();
max@0 80
max@0 81 // NOTE: we're assuming that the cube has already been set to the correct size;
max@0 82 // this is done by either the Cube contructor or operator=()
max@0 83
max@0 84 if(is_same_type<gen_type, gen_ones_full>::value == true) { out.ones(); }
max@0 85 else if(is_same_type<gen_type, gen_zeros >::value == true) { out.zeros(); }
max@0 86 else if(is_same_type<gen_type, gen_randu >::value == true) { out.randu(); }
max@0 87 else if(is_same_type<gen_type, gen_randn >::value == true) { out.randn(); }
max@0 88 }
max@0 89
max@0 90
max@0 91
max@0 92 template<typename eT, typename gen_type>
max@0 93 inline
max@0 94 void
max@0 95 GenCube<eT, gen_type>::apply_inplace_plus(Cube<eT>& out) const
max@0 96 {
max@0 97 arma_extra_debug_sigprint();
max@0 98
max@0 99 arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "addition");
max@0 100
max@0 101
max@0 102 eT* out_mem = out.memptr();
max@0 103 const uword n_elem = out.n_elem;
max@0 104
max@0 105 uword i,j;
max@0 106
max@0 107 for(i=0, j=1; j<n_elem; i+=2, j+=2)
max@0 108 {
max@0 109 const eT tmp_i = GenCube<eT, gen_type>::generate();
max@0 110 const eT tmp_j = GenCube<eT, gen_type>::generate();
max@0 111
max@0 112 out_mem[i] += tmp_i;
max@0 113 out_mem[j] += tmp_j;
max@0 114 }
max@0 115
max@0 116 if(i < n_elem)
max@0 117 {
max@0 118 out_mem[i] += GenCube<eT, gen_type>::generate();
max@0 119 }
max@0 120 }
max@0 121
max@0 122
max@0 123
max@0 124
max@0 125 template<typename eT, typename gen_type>
max@0 126 inline
max@0 127 void
max@0 128 GenCube<eT, gen_type>::apply_inplace_minus(Cube<eT>& out) const
max@0 129 {
max@0 130 arma_extra_debug_sigprint();
max@0 131
max@0 132 arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "subtraction");
max@0 133
max@0 134
max@0 135 eT* out_mem = out.memptr();
max@0 136 const uword n_elem = out.n_elem;
max@0 137
max@0 138 uword i,j;
max@0 139
max@0 140 for(i=0, j=1; j<n_elem; i+=2, j+=2)
max@0 141 {
max@0 142 const eT tmp_i = GenCube<eT, gen_type>::generate();
max@0 143 const eT tmp_j = GenCube<eT, gen_type>::generate();
max@0 144
max@0 145 out_mem[i] -= tmp_i;
max@0 146 out_mem[j] -= tmp_j;
max@0 147 }
max@0 148
max@0 149 if(i < n_elem)
max@0 150 {
max@0 151 out_mem[i] -= GenCube<eT, gen_type>::generate();
max@0 152 }
max@0 153 }
max@0 154
max@0 155
max@0 156
max@0 157
max@0 158 template<typename eT, typename gen_type>
max@0 159 inline
max@0 160 void
max@0 161 GenCube<eT, gen_type>::apply_inplace_schur(Cube<eT>& out) const
max@0 162 {
max@0 163 arma_extra_debug_sigprint();
max@0 164
max@0 165 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 166
max@0 167
max@0 168 eT* out_mem = out.memptr();
max@0 169 const uword n_elem = out.n_elem;
max@0 170
max@0 171 uword i,j;
max@0 172
max@0 173 for(i=0, j=1; j<n_elem; i+=2, j+=2)
max@0 174 {
max@0 175 const eT tmp_i = GenCube<eT, gen_type>::generate();
max@0 176 const eT tmp_j = GenCube<eT, gen_type>::generate();
max@0 177
max@0 178 out_mem[i] *= tmp_i;
max@0 179 out_mem[j] *= tmp_j;
max@0 180 }
max@0 181
max@0 182 if(i < n_elem)
max@0 183 {
max@0 184 out_mem[i] *= GenCube<eT, gen_type>::generate();
max@0 185 }
max@0 186 }
max@0 187
max@0 188
max@0 189
max@0 190
max@0 191 template<typename eT, typename gen_type>
max@0 192 inline
max@0 193 void
max@0 194 GenCube<eT, gen_type>::apply_inplace_div(Cube<eT>& out) const
max@0 195 {
max@0 196 arma_extra_debug_sigprint();
max@0 197
max@0 198 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 199
max@0 200
max@0 201 eT* out_mem = out.memptr();
max@0 202 const uword n_elem = out.n_elem;
max@0 203
max@0 204 uword i,j;
max@0 205
max@0 206 for(i=0, j=1; j<n_elem; i+=2, j+=2)
max@0 207 {
max@0 208 const eT tmp_i = GenCube<eT, gen_type>::generate();
max@0 209 const eT tmp_j = GenCube<eT, gen_type>::generate();
max@0 210
max@0 211 out_mem[i] /= tmp_i;
max@0 212 out_mem[j] /= tmp_j;
max@0 213 }
max@0 214
max@0 215 if(i < n_elem)
max@0 216 {
max@0 217 out_mem[i] /= GenCube<eT, gen_type>::generate();
max@0 218 }
max@0 219 }
max@0 220
max@0 221
max@0 222
max@0 223
max@0 224 //! @}