GenCube_meat.hpp
Go to the documentation of this file.
1 // Copyright (C) 2011 NICTA (www.nicta.com.au)
2 // Copyright (C) 2011 Conrad Sanderson
3 //
4 // This file is part of the Armadillo C++ library.
5 // It is provided without any warranty of fitness
6 // for any purpose. You can redistribute this file
7 // and/or modify it under the terms of the GNU
8 // Lesser General Public License (LGPL) as published
9 // by the Free Software Foundation, either version 3
10 // of the License or (at your option) any later version.
11 // (see http://www.opensource.org/licenses for more info)
12 
13 
16 
17 
18 
19 template<typename eT, typename gen_type>
21 GenCube<eT, gen_type>::GenCube(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices)
22  : n_rows (in_n_rows )
23  , n_cols (in_n_cols )
24  , n_slices(in_n_slices)
25  {
27  }
28 
29 
30 
31 template<typename eT, typename gen_type>
34  {
36  }
37 
38 
39 
40 template<typename eT, typename gen_type>
42 eT
44  {
45  if(is_same_type<gen_type, gen_ones_full>::value == true) { return eT(1); }
46  else if(is_same_type<gen_type, gen_zeros >::value == true) { return eT(0); }
47  else if(is_same_type<gen_type, gen_randu >::value == true) { return eT(eop_aux_randu<eT>()); }
48  else if(is_same_type<gen_type, gen_randn >::value == true) { return eT(eop_aux_randn<eT>()); }
49  else { return eT(); }
50  }
51 
52 
53 
54 template<typename eT, typename gen_type>
56 eT
58  {
60  }
61 
62 
63 
64 template<typename eT, typename gen_type>
66 eT
67 GenCube<eT, gen_type>::at(const uword, const uword, const uword) const
68  {
70  }
71 
72 
73 
74 template<typename eT, typename gen_type>
75 inline
76 void
78  {
80 
81  // NOTE: we're assuming that the cube has already been set to the correct size;
82  // this is done by either the Cube contructor or operator=()
83 
85  else if(is_same_type<gen_type, gen_zeros >::value == true) { out.zeros(); }
86  else if(is_same_type<gen_type, gen_randu >::value == true) { out.randu(); }
87  else if(is_same_type<gen_type, gen_randn >::value == true) { out.randn(); }
88  }
89 
90 
91 
92 template<typename eT, typename gen_type>
93 inline
94 void
96  {
98 
100 
101 
102  eT* out_mem = out.memptr();
103  const uword n_elem = out.n_elem;
104 
105  uword i,j;
106 
107  for(i=0, j=1; j<n_elem; i+=2, j+=2)
108  {
109  const eT tmp_i = GenCube<eT, gen_type>::generate();
110  const eT tmp_j = GenCube<eT, gen_type>::generate();
111 
112  out_mem[i] += tmp_i;
113  out_mem[j] += tmp_j;
114  }
115 
116  if(i < n_elem)
117  {
118  out_mem[i] += GenCube<eT, gen_type>::generate();
119  }
120  }
121 
122 
123 
124 
125 template<typename eT, typename gen_type>
126 inline
127 void
129  {
131 
132  arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "subtraction");
133 
134 
135  eT* out_mem = out.memptr();
136  const uword n_elem = out.n_elem;
137 
138  uword i,j;
139 
140  for(i=0, j=1; j<n_elem; i+=2, j+=2)
141  {
142  const eT tmp_i = GenCube<eT, gen_type>::generate();
143  const eT tmp_j = GenCube<eT, gen_type>::generate();
144 
145  out_mem[i] -= tmp_i;
146  out_mem[j] -= tmp_j;
147  }
148 
149  if(i < n_elem)
150  {
151  out_mem[i] -= GenCube<eT, gen_type>::generate();
152  }
153  }
154 
155 
156 
157 
158 template<typename eT, typename gen_type>
159 inline
160 void
162  {
164 
165  arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise multiplication");
166 
167 
168  eT* out_mem = out.memptr();
169  const uword n_elem = out.n_elem;
170 
171  uword i,j;
172 
173  for(i=0, j=1; j<n_elem; i+=2, j+=2)
174  {
175  const eT tmp_i = GenCube<eT, gen_type>::generate();
176  const eT tmp_j = GenCube<eT, gen_type>::generate();
177 
178  out_mem[i] *= tmp_i;
179  out_mem[j] *= tmp_j;
180  }
181 
182  if(i < n_elem)
183  {
184  out_mem[i] *= GenCube<eT, gen_type>::generate();
185  }
186  }
187 
188 
189 
190 
191 template<typename eT, typename gen_type>
192 inline
193 void
195  {
197 
198  arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise division");
199 
200 
201  eT* out_mem = out.memptr();
202  const uword n_elem = out.n_elem;
203 
204  uword i,j;
205 
206  for(i=0, j=1; j<n_elem; i+=2, j+=2)
207  {
208  const eT tmp_i = GenCube<eT, gen_type>::generate();
209  const eT tmp_j = GenCube<eT, gen_type>::generate();
210 
211  out_mem[i] /= tmp_i;
212  out_mem[j] /= tmp_j;
213  }
214 
215  if(i < n_elem)
216  {
217  out_mem[i] /= GenCube<eT, gen_type>::generate();
218  }
219  }
220 
221 
222 
223 
const Cube & zeros()
Definition: Cube_meat.hpp:2481
arma_inline eT operator[](const uword i) const
arma_aligned const uword n_cols
arma_inline ~GenCube()
arma_inline GenCube(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices)
#define arma_debug_assert_same_size
Definition: debug.hpp:1086
arma_aligned const uword n_slices
arma_inline eT at(const uword row, const uword col, const uword slice) const
u32 uword
Definition: typedef.hpp:85
arma_inline arma_warn_unused eT * memptr()
returns a pointer to array of eTs used by the cube
Definition: Cube_meat.hpp:2260
const uword n_cols
number of columns in each slice (read-only)
Definition: Cube_bones.hpp:38
const Cube & randu()
Definition: Cube_meat.hpp:2533
Dense cube class.
Definition: Cube_bones.hpp:30
void apply_inplace_minus(Cube< eT > &out) const
const Cube & randn()
Definition: Cube_meat.hpp:2575
#define arma_extra_debug_sigprint
Definition: debug.hpp:1116
void apply_inplace_plus(Cube< eT > &out) const
void apply_inplace_schur(Cube< eT > &out) const
const Cube & ones()
Definition: Cube_meat.hpp:2507
const uword n_elem
number of elements in the cube (read-only)
Definition: Cube_bones.hpp:41
void apply(Cube< eT > &out) const
#define arma_inline
static arma_inline eT generate()
arma_aligned const uword n_rows
void apply_inplace_div(Cube< eT > &out) const
const uword n_slices
number of slices in the cube (read-only)
Definition: Cube_bones.hpp:40
const uword n_rows
number of rows in each slice (read-only)
Definition: Cube_bones.hpp:37


armadillo_matrix
Author(s):
autogenerated on Fri Apr 16 2021 02:31:57