Gen_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 Gen<eT, gen_type>::Gen(const uword in_n_rows, const uword in_n_cols)
22  : n_rows(in_n_rows)
23  , n_cols(in_n_cols)
24  {
26  }
27 
28 
29 
30 template<typename eT, typename gen_type>
33  {
35  }
36 
37 
38 
39 template<typename eT, typename gen_type>
41 eT
43  {
44  if(is_same_type<gen_type, gen_ones_full>::value == true) { return eT(1); }
45  else if(is_same_type<gen_type, gen_zeros >::value == true) { return eT(0); }
46  else if(is_same_type<gen_type, gen_randu >::value == true) { return eT(eop_aux_randu<eT>()); }
47  else if(is_same_type<gen_type, gen_randn >::value == true) { return eT(eop_aux_randn<eT>()); }
48  else { return eT(); }
49  }
50 
51 
52 
53 template<typename eT, typename gen_type>
55 eT
57  {
59  {
60  return ((i % n_rows) == (i / n_rows)) ? eT(1) : eT(0);
61  }
62  else
63  {
65  }
66  }
67 
68 
69 
70 template<typename eT, typename gen_type>
72 eT
73 Gen<eT, gen_type>::at(const uword row, const uword col) const
74  {
76  {
77  return (row == col) ? eT(1) : eT(0);
78  }
79  else
80  {
82  }
83  }
84 
85 
86 
87 template<typename eT, typename gen_type>
88 inline
89 void
91  {
93 
94  // NOTE: we're assuming that the matrix has already been set to the correct size;
95  // this is done by either the Mat contructor or operator=()
96 
98  else if(is_same_type<gen_type, gen_ones_full>::value == true) { out.ones(); }
99  else if(is_same_type<gen_type, gen_zeros >::value == true) { out.zeros(); }
100  else if(is_same_type<gen_type, gen_randu >::value == true) { out.randu(); }
101  else if(is_same_type<gen_type, gen_randn >::value == true) { out.randn(); }
102  }
103 
104 
105 
106 template<typename eT, typename gen_type>
107 inline
108 void
110  {
112 
113  arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "addition");
114 
115 
117  {
118  const uword N = (std::min)(n_rows, n_cols);
119 
120  for(uword i=0; i<N; ++i)
121  {
122  out.at(i,i) += eT(1);
123  }
124  }
125  else
126  {
127  eT* out_mem = out.memptr();
128  const uword n_elem = out.n_elem;
129 
130  uword i,j;
131 
132  for(i=0, j=1; j<n_elem; i+=2, j+=2)
133  {
134  const eT tmp_i = Gen<eT, gen_type>::generate();
135  const eT tmp_j = Gen<eT, gen_type>::generate();
136 
137  out_mem[i] += tmp_i;
138  out_mem[j] += tmp_j;
139  }
140 
141  if(i < n_elem)
142  {
143  out_mem[i] += Gen<eT, gen_type>::generate();
144  }
145  }
146 
147  }
148 
149 
150 
151 
152 template<typename eT, typename gen_type>
153 inline
154 void
156  {
158 
159  arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "subtraction");
160 
161 
163  {
164  const uword N = (std::min)(n_rows, n_cols);
165 
166  for(uword i=0; i<N; ++i)
167  {
168  out.at(i,i) -= eT(1);
169  }
170  }
171  else
172  {
173  eT* out_mem = out.memptr();
174  const uword n_elem = out.n_elem;
175 
176  uword i,j;
177 
178  for(i=0, j=1; j<n_elem; i+=2, j+=2)
179  {
180  const eT tmp_i = Gen<eT, gen_type>::generate();
181  const eT tmp_j = Gen<eT, gen_type>::generate();
182 
183  out_mem[i] -= tmp_i;
184  out_mem[j] -= tmp_j;
185  }
186 
187  if(i < n_elem)
188  {
189  out_mem[i] -= Gen<eT, gen_type>::generate();
190  }
191  }
192 
193  }
194 
195 
196 
197 
198 template<typename eT, typename gen_type>
199 inline
200 void
202  {
204 
205  arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "element-wise multiplication");
206 
207 
209  {
210  const uword N = (std::min)(n_rows, n_cols);
211 
212  for(uword i=0; i<N; ++i)
213  {
214  for(uword row=0; row<i; ++row) { out.at(row,i) = eT(0); }
215  for(uword row=i+1; row<n_rows; ++row) { out.at(row,i) = eT(0); }
216  }
217  }
218  else
219  {
220  eT* out_mem = out.memptr();
221  const uword n_elem = out.n_elem;
222 
223  uword i,j;
224 
225  for(i=0, j=1; j<n_elem; i+=2, j+=2)
226  {
227  const eT tmp_i = Gen<eT, gen_type>::generate();
228  const eT tmp_j = Gen<eT, gen_type>::generate();
229 
230  out_mem[i] *= tmp_i;
231  out_mem[j] *= tmp_j;
232  }
233 
234  if(i < n_elem)
235  {
236  out_mem[i] *= Gen<eT, gen_type>::generate();
237  }
238  }
239 
240  }
241 
242 
243 
244 
245 template<typename eT, typename gen_type>
246 inline
247 void
249  {
251 
252  arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "element-wise division");
253 
254 
256  {
257  const uword N = (std::min)(n_rows, n_cols);
258 
259  for(uword i=0; i<N; ++i)
260  {
261  const eT zero = eT(0);
262 
263  for(uword row=0; row<i; ++row) { out.at(row,i) /= zero; }
264  for(uword row=i+1; row<n_rows; ++row) { out.at(row,i) /= zero; }
265  }
266  }
267  else
268  {
269  eT* out_mem = out.memptr();
270  const uword n_elem = out.n_elem;
271 
272  uword i,j;
273 
274  for(i=0, j=1; j<n_elem; i+=2, j+=2)
275  {
276  const eT tmp_i = Gen<eT, gen_type>::generate();
277  const eT tmp_j = Gen<eT, gen_type>::generate();
278 
279  out_mem[i] /= tmp_i;
280  out_mem[j] /= tmp_j;
281  }
282 
283  if(i < n_elem)
284  {
285  out_mem[i] /= Gen<eT, gen_type>::generate();
286  }
287  }
288 
289  }
290 
291 
292 
293 
arma_inline arma_warn_unused eT * memptr()
returns a pointer to array of eTs used by the matrix
Definition: Mat_meat.hpp:4024
const Mat & eye()
Definition: Mat_meat.hpp:4518
void apply_inplace_minus(Mat< eT > &out) const
Definition: Gen_meat.hpp:155
void apply(Mat< eT > &out) const
Definition: Gen_meat.hpp:90
arma_aligned const uword n_cols
Definition: Gen_bones.hpp:30
const uword n_cols
number of columns in the matrix (read-only)
Definition: Mat_bones.hpp:30
#define arma_debug_assert_same_size
Definition: debug.hpp:1086
const uword n_elem
number of elements in the matrix (read-only)
Definition: Mat_bones.hpp:31
const uword n_rows
number of rows in the matrix (read-only)
Definition: Mat_bones.hpp:29
arma_inline const Op< T1, op_min > min(const Base< typename T1::elem_type, T1 > &X, const uword dim=0)
Delayed &#39;minimum values&#39; operation. The dimension, along which the minima are found, is set via &#39;dim&#39;. For dim = 0, the minimum value of each column is found (i.e. searches by traversing across rows). For dim = 1, the minimum value of each row is found (i.e. searches by traversing across columns). The default is dim = 0.
Definition: fn_min.hpp:27
u32 uword
Definition: typedef.hpp:85
arma_aligned const uword n_rows
Definition: Gen_bones.hpp:29
const Mat & ones()
Definition: Mat_meat.hpp:4371
static arma_inline eT generate()
Definition: Gen_meat.hpp:42
arma_inline arma_warn_unused eT & at(const uword i)
linear element accessor (treats the matrix as a vector); no bounds check.
Definition: Mat_meat.hpp:3692
arma_inline ~Gen()
Definition: Gen_meat.hpp:32
#define arma_extra_debug_sigprint
Definition: debug.hpp:1116
void apply_inplace_div(Mat< eT > &out) const
Definition: Gen_meat.hpp:248
arma_inline Gen(const uword in_n_rows, const uword in_n_cols)
Definition: Gen_meat.hpp:21
Dense matrix class.
#define arma_inline
const Mat & zeros()
Definition: Mat_meat.hpp:4331
arma_inline eT operator[](const uword i) const
Definition: Gen_meat.hpp:56
void apply_inplace_schur(Mat< eT > &out) const
Definition: Gen_meat.hpp:201
void apply_inplace_plus(Mat< eT > &out) const
Definition: Gen_meat.hpp:109
const Mat & randu()
Definition: Mat_meat.hpp:4411
arma_inline eT at(const uword row, const uword col) const
Definition: Gen_meat.hpp:73
const Mat & randn()
Definition: Mat_meat.hpp:4470


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