op_symmat_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 T1>
20 inline
21 void
23  (
25  const Op<T1,op_symmat>& in,
27  )
28  {
30  arma_ignore(junk);
31 
32  typedef typename T1::elem_type eT;
33 
34  const unwrap<T1> tmp(in.m);
35  const Mat<eT>& A = tmp.M;
36 
37  arma_debug_check( (A.is_square() == false), "symmatu()/symmatl(): given matrix must be square" );
38 
39  const uword N = A.n_rows;
40  const bool upper = (in.aux_uword_a == 0);
41 
42  if(&out != &A)
43  {
44  out.copy_size(A);
45 
46  if(upper)
47  {
48  // upper triangular: copy the diagonal and the elements above the diagonal
49 
50  for(uword i=0; i<N; ++i)
51  {
52  const eT* A_data = A.colptr(i);
53  eT* out_data = out.colptr(i);
54 
55  arrayops::copy( out_data, A_data, i+1 );
56  }
57  }
58  else
59  {
60  // lower triangular: copy the diagonal and the elements below the diagonal
61 
62  for(uword i=0; i<N; ++i)
63  {
64  const eT* A_data = A.colptr(i);
65  eT* out_data = out.colptr(i);
66 
67  arrayops::copy( &out_data[i], &A_data[i], N-i );
68  }
69  }
70  }
71 
72 
73  if(upper)
74  {
75  // reflect elements across the diagonal from upper triangle to lower triangle
76 
77  for(uword col=1; col < N; ++col)
78  {
79  const eT* coldata = out.colptr(col);
80 
81  for(uword row=0; row < col; ++row)
82  {
83  out.at(col,row) = coldata[row];
84  }
85  }
86  }
87  else
88  {
89  // reflect elements across the diagonal from lower triangle to upper triangle
90 
91  for(uword col=0; col < N; ++col)
92  {
93  const eT* coldata = out.colptr(col);
94 
95  for(uword row=(col+1); row < N; ++row)
96  {
97  out.at(col,row) = coldata[row];
98  }
99  }
100  }
101  }
102 
103 
104 
105 template<typename T1>
106 inline
107 void
109  (
111  const Op<T1,op_symmat>& in,
113  )
114  {
116  arma_ignore(junk);
117 
118  typedef typename T1::elem_type eT;
119 
120  const unwrap<T1> tmp(in.m);
121  const Mat<eT>& A = tmp.M;
122 
123  arma_debug_check( (A.is_square() == false), "symmatu()/symmatl(): given matrix must be square" );
124 
125  const uword N = A.n_rows;
126  const bool upper = (in.aux_uword_a == 0);
127 
128  if(&out != &A)
129  {
130  out.copy_size(A);
131 
132  if(upper)
133  {
134  // upper triangular: copy the diagonal and the elements above the diagonal
135 
136  for(uword i=0; i<N; ++i)
137  {
138  const eT* A_data = A.colptr(i);
139  eT* out_data = out.colptr(i);
140 
141  arrayops::copy( out_data, A_data, i+1 );
142  }
143  }
144  else
145  {
146  // lower triangular: copy the diagonal and the elements below the diagonal
147 
148  for(uword i=0; i<N; ++i)
149  {
150  const eT* A_data = A.colptr(i);
151  eT* out_data = out.colptr(i);
152 
153  arrayops::copy( &out_data[i], &A_data[i], N-i );
154  }
155  }
156  }
157 
158 
159  if(upper)
160  {
161  // reflect elements across the diagonal from upper triangle to lower triangle
162 
163  for(uword col=1; col < N; ++col)
164  {
165  const eT* coldata = out.colptr(col);
166 
167  for(uword row=0; row < col; ++row)
168  {
169  out.at(col,row) = std::conj(coldata[row]);
170  }
171  }
172  }
173  else
174  {
175  // reflect elements across the diagonal from lower triangle to upper triangle
176 
177  for(uword col=0; col < N; ++col)
178  {
179  const eT* coldata = out.colptr(col);
180 
181  for(uword row=(col+1); row < N; ++row)
182  {
183  out.at(col,row) = std::conj(coldata[row]);
184  }
185  }
186  }
187  }
188 
189 
190 
arma_hot static arma_inline void copy(eT *dest, const eT *src, const uword n_elem)
arma_inline const T1 & conj(const Base< typename T1::pod_type, T1 > &A)
Definition: fn_elem.hpp:430
const uword n_rows
number of rows in the matrix (read-only)
Definition: Mat_bones.hpp:29
arma_aligned const T1 & m
storage of reference to the operand (eg. a matrix)
Definition: Op_bones.hpp:45
arma_inline arma_warn_unused eT * colptr(const uword in_col)
returns a pointer to array of eTs for a specified column; no bounds check
Definition: Mat_meat.hpp:4000
u32 uword
Definition: typedef.hpp:85
#define arma_debug_check
Definition: debug.hpp:1084
const Mat< eT > M
Definition: unwrap.hpp:32
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 arma_warn_unused bool is_square() const
returns true if the object has the same number of non-zero rows and columnns
Definition: Mat_meat.hpp:3860
static void apply(Mat< typename T1::elem_type > &out, const Op< T1, op_symmat > &in, const typename arma_not_cx< typename T1::elem_type >::result *junk=0)
#define arma_ignore(variable)
void copy_size(const Mat< eT2 > &m)
change the matrix (without preserving data) to have the same dimensions as the given matrix ...
Definition: Mat_meat.hpp:4303
#define arma_extra_debug_sigprint
Definition: debug.hpp:1116
Dense matrix class.
arma_aligned uword aux_uword_a
storage of auxiliary data, uword format
Definition: Op_bones.hpp:47


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