annotate armadillo-3.900.4/include/armadillo_bits/GenCube_meat.hpp @ 84:55a047986812 tip

Update library URI so as not to be document-local
author Chris Cannam
date Wed, 22 Apr 2020 14:21:57 +0100
parents 1ec0e2823891
children
rev   line source
Chris@49 1 // Copyright (C) 2011-2013 NICTA (www.nicta.com.au)
Chris@49 2 // Copyright (C) 2011-2013 Conrad Sanderson
Chris@49 3 //
Chris@49 4 // This Source Code Form is subject to the terms of the Mozilla Public
Chris@49 5 // License, v. 2.0. If a copy of the MPL was not distributed with this
Chris@49 6 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
Chris@49 7
Chris@49 8
Chris@49 9 //! \addtogroup Gen
Chris@49 10 //! @{
Chris@49 11
Chris@49 12
Chris@49 13
Chris@49 14 template<typename eT, typename gen_type>
Chris@49 15 arma_inline
Chris@49 16 GenCube<eT, gen_type>::GenCube(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices)
Chris@49 17 : n_rows (in_n_rows )
Chris@49 18 , n_cols (in_n_cols )
Chris@49 19 , n_slices(in_n_slices)
Chris@49 20 {
Chris@49 21 arma_extra_debug_sigprint();
Chris@49 22 }
Chris@49 23
Chris@49 24
Chris@49 25
Chris@49 26 template<typename eT, typename gen_type>
Chris@49 27 arma_inline
Chris@49 28 GenCube<eT, gen_type>::~GenCube()
Chris@49 29 {
Chris@49 30 arma_extra_debug_sigprint();
Chris@49 31 }
Chris@49 32
Chris@49 33
Chris@49 34
Chris@49 35 template<typename eT, typename gen_type>
Chris@49 36 arma_inline
Chris@49 37 eT
Chris@49 38 GenCube<eT, gen_type>::generate()
Chris@49 39 {
Chris@49 40 if(is_same_type<gen_type, gen_ones_full>::value == true) { return eT(1); }
Chris@49 41 else if(is_same_type<gen_type, gen_zeros >::value == true) { return eT(0); }
Chris@49 42 else if(is_same_type<gen_type, gen_randu >::value == true) { return eT(eop_aux_randu<eT>()); }
Chris@49 43 else if(is_same_type<gen_type, gen_randn >::value == true) { return eT(eop_aux_randn<eT>()); }
Chris@49 44 else { return eT(); }
Chris@49 45 }
Chris@49 46
Chris@49 47
Chris@49 48
Chris@49 49 template<typename eT, typename gen_type>
Chris@49 50 arma_inline
Chris@49 51 eT
Chris@49 52 GenCube<eT, gen_type>::operator[](const uword) const
Chris@49 53 {
Chris@49 54 return GenCube<eT, gen_type>::generate();
Chris@49 55 }
Chris@49 56
Chris@49 57
Chris@49 58
Chris@49 59 template<typename eT, typename gen_type>
Chris@49 60 arma_inline
Chris@49 61 eT
Chris@49 62 GenCube<eT, gen_type>::at(const uword, const uword, const uword) const
Chris@49 63 {
Chris@49 64 return GenCube<eT, gen_type>::generate();
Chris@49 65 }
Chris@49 66
Chris@49 67
Chris@49 68
Chris@49 69 template<typename eT, typename gen_type>
Chris@49 70 arma_inline
Chris@49 71 eT
Chris@49 72 GenCube<eT, gen_type>::at_alt(const uword) const
Chris@49 73 {
Chris@49 74 return GenCube<eT, gen_type>::generate();
Chris@49 75 }
Chris@49 76
Chris@49 77
Chris@49 78
Chris@49 79 template<typename eT, typename gen_type>
Chris@49 80 inline
Chris@49 81 void
Chris@49 82 GenCube<eT, gen_type>::apply(Cube<eT>& out) const
Chris@49 83 {
Chris@49 84 arma_extra_debug_sigprint();
Chris@49 85
Chris@49 86 // NOTE: we're assuming that the cube has already been set to the correct size;
Chris@49 87 // this is done by either the Cube contructor or operator=()
Chris@49 88
Chris@49 89 if(is_same_type<gen_type, gen_ones_full>::value == true) { out.ones(); }
Chris@49 90 else if(is_same_type<gen_type, gen_zeros >::value == true) { out.zeros(); }
Chris@49 91 else if(is_same_type<gen_type, gen_randu >::value == true) { out.randu(); }
Chris@49 92 else if(is_same_type<gen_type, gen_randn >::value == true) { out.randn(); }
Chris@49 93 }
Chris@49 94
Chris@49 95
Chris@49 96
Chris@49 97 template<typename eT, typename gen_type>
Chris@49 98 inline
Chris@49 99 void
Chris@49 100 GenCube<eT, gen_type>::apply_inplace_plus(Cube<eT>& out) const
Chris@49 101 {
Chris@49 102 arma_extra_debug_sigprint();
Chris@49 103
Chris@49 104 arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "addition");
Chris@49 105
Chris@49 106
Chris@49 107 eT* out_mem = out.memptr();
Chris@49 108 const uword n_elem = out.n_elem;
Chris@49 109
Chris@49 110 uword i,j;
Chris@49 111
Chris@49 112 for(i=0, j=1; j<n_elem; i+=2, j+=2)
Chris@49 113 {
Chris@49 114 const eT tmp_i = GenCube<eT, gen_type>::generate();
Chris@49 115 const eT tmp_j = GenCube<eT, gen_type>::generate();
Chris@49 116
Chris@49 117 out_mem[i] += tmp_i;
Chris@49 118 out_mem[j] += tmp_j;
Chris@49 119 }
Chris@49 120
Chris@49 121 if(i < n_elem)
Chris@49 122 {
Chris@49 123 out_mem[i] += GenCube<eT, gen_type>::generate();
Chris@49 124 }
Chris@49 125 }
Chris@49 126
Chris@49 127
Chris@49 128
Chris@49 129
Chris@49 130 template<typename eT, typename gen_type>
Chris@49 131 inline
Chris@49 132 void
Chris@49 133 GenCube<eT, gen_type>::apply_inplace_minus(Cube<eT>& out) const
Chris@49 134 {
Chris@49 135 arma_extra_debug_sigprint();
Chris@49 136
Chris@49 137 arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "subtraction");
Chris@49 138
Chris@49 139
Chris@49 140 eT* out_mem = out.memptr();
Chris@49 141 const uword n_elem = out.n_elem;
Chris@49 142
Chris@49 143 uword i,j;
Chris@49 144
Chris@49 145 for(i=0, j=1; j<n_elem; i+=2, j+=2)
Chris@49 146 {
Chris@49 147 const eT tmp_i = GenCube<eT, gen_type>::generate();
Chris@49 148 const eT tmp_j = GenCube<eT, gen_type>::generate();
Chris@49 149
Chris@49 150 out_mem[i] -= tmp_i;
Chris@49 151 out_mem[j] -= tmp_j;
Chris@49 152 }
Chris@49 153
Chris@49 154 if(i < n_elem)
Chris@49 155 {
Chris@49 156 out_mem[i] -= GenCube<eT, gen_type>::generate();
Chris@49 157 }
Chris@49 158 }
Chris@49 159
Chris@49 160
Chris@49 161
Chris@49 162
Chris@49 163 template<typename eT, typename gen_type>
Chris@49 164 inline
Chris@49 165 void
Chris@49 166 GenCube<eT, gen_type>::apply_inplace_schur(Cube<eT>& out) const
Chris@49 167 {
Chris@49 168 arma_extra_debug_sigprint();
Chris@49 169
Chris@49 170 arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise multiplication");
Chris@49 171
Chris@49 172
Chris@49 173 eT* out_mem = out.memptr();
Chris@49 174 const uword n_elem = out.n_elem;
Chris@49 175
Chris@49 176 uword i,j;
Chris@49 177
Chris@49 178 for(i=0, j=1; j<n_elem; i+=2, j+=2)
Chris@49 179 {
Chris@49 180 const eT tmp_i = GenCube<eT, gen_type>::generate();
Chris@49 181 const eT tmp_j = GenCube<eT, gen_type>::generate();
Chris@49 182
Chris@49 183 out_mem[i] *= tmp_i;
Chris@49 184 out_mem[j] *= tmp_j;
Chris@49 185 }
Chris@49 186
Chris@49 187 if(i < n_elem)
Chris@49 188 {
Chris@49 189 out_mem[i] *= GenCube<eT, gen_type>::generate();
Chris@49 190 }
Chris@49 191 }
Chris@49 192
Chris@49 193
Chris@49 194
Chris@49 195
Chris@49 196 template<typename eT, typename gen_type>
Chris@49 197 inline
Chris@49 198 void
Chris@49 199 GenCube<eT, gen_type>::apply_inplace_div(Cube<eT>& out) const
Chris@49 200 {
Chris@49 201 arma_extra_debug_sigprint();
Chris@49 202
Chris@49 203 arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise division");
Chris@49 204
Chris@49 205
Chris@49 206 eT* out_mem = out.memptr();
Chris@49 207 const uword n_elem = out.n_elem;
Chris@49 208
Chris@49 209 uword i,j;
Chris@49 210
Chris@49 211 for(i=0, j=1; j<n_elem; i+=2, j+=2)
Chris@49 212 {
Chris@49 213 const eT tmp_i = GenCube<eT, gen_type>::generate();
Chris@49 214 const eT tmp_j = GenCube<eT, gen_type>::generate();
Chris@49 215
Chris@49 216 out_mem[i] /= tmp_i;
Chris@49 217 out_mem[j] /= tmp_j;
Chris@49 218 }
Chris@49 219
Chris@49 220 if(i < n_elem)
Chris@49 221 {
Chris@49 222 out_mem[i] /= GenCube<eT, gen_type>::generate();
Chris@49 223 }
Chris@49 224 }
Chris@49 225
Chris@49 226
Chris@49 227
Chris@49 228
Chris@49 229 //! @}