source: mmcs/armadillo_bits/op_symmat_meat.hpp @ 8daa049

matrices
Last change on this file since 8daa049 was 9dd61b1, checked in by rboet <rboet@…>, 9 years ago

Avance del proyecto 60%

  • Property mode set to 100644
File size: 4.7 KB
Line 
1// Copyright (C) 2011-2014 Conrad Sanderson
2// Copyright (C) 2011-2014 NICTA (www.nicta.com.au)
3//
4// This Source Code Form is subject to the terms of the Mozilla Public
5// License, v. 2.0. If a copy of the MPL was not distributed with this
6// file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
8
9//! \addtogroup op_symmat
10//! @{
11
12
13
14template<typename T1>
15inline
16void
17op_symmat::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_symmat>& in)
18  {
19  arma_extra_debug_sigprint();
20 
21  typedef typename T1::elem_type eT;
22 
23  const unwrap<T1>   tmp(in.m);
24  const Mat<eT>& A = tmp.M;
25 
26  arma_debug_check( (A.is_square() == false), "symmatu()/symmatl(): given matrix must be square" );
27 
28  const uword N     = A.n_rows;
29  const bool  upper = (in.aux_uword_a == 0);
30 
31  if(&out != &A)
32    {
33    out.copy_size(A);
34   
35    if(upper)
36      {
37      // upper triangular: copy the diagonal and the elements above the diagonal
38     
39      for(uword i=0; i<N; ++i)
40        {
41        const eT* A_data   = A.colptr(i);
42              eT* out_data = out.colptr(i);
43       
44        arrayops::copy( out_data, A_data, i+1 );
45        }
46      }
47    else
48      {
49      // lower triangular: copy the diagonal and the elements below the diagonal
50     
51      for(uword i=0; i<N; ++i)
52        {
53        const eT* A_data   = A.colptr(i);
54              eT* out_data = out.colptr(i);
55       
56        arrayops::copy( &out_data[i], &A_data[i], N-i );
57        }
58      }
59    }
60 
61 
62  if(upper)
63    {
64    // reflect elements across the diagonal from upper triangle to lower triangle
65   
66    for(uword col=1; col < N; ++col)
67      {
68      const eT* coldata = out.colptr(col);
69     
70      for(uword row=0; row < col; ++row)
71        {
72        out.at(col,row) = coldata[row];
73        }
74      }
75    }
76  else
77    {
78    // reflect elements across the diagonal from lower triangle to upper triangle
79   
80    for(uword col=0; col < N; ++col)
81      {
82      const eT* coldata = out.colptr(col);
83     
84      for(uword row=(col+1); row < N; ++row)
85        {
86        out.at(col,row) = coldata[row];
87        }
88      }
89    }
90  }
91
92
93
94template<typename T1>
95inline
96void
97op_symmat_cx::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_symmat_cx>& in)
98  {
99  arma_extra_debug_sigprint();
100 
101  typedef typename T1::elem_type eT;
102 
103  const unwrap<T1>   tmp(in.m);
104  const Mat<eT>& A = tmp.M;
105 
106  arma_debug_check( (A.is_square() == false), "symmatu()/symmatl(): given matrix must be square" );
107 
108  const uword N  = A.n_rows;
109 
110  const bool upper   = (in.aux_uword_a == 0);
111  const bool do_conj = (in.aux_uword_b == 1);
112 
113  if(&out != &A)
114    {
115    out.copy_size(A);
116   
117    if(upper)
118      {
119      // upper triangular: copy the diagonal and the elements above the diagonal
120     
121      for(uword i=0; i<N; ++i)
122        {
123        const eT* A_data   = A.colptr(i);
124              eT* out_data = out.colptr(i);
125       
126        arrayops::copy( out_data, A_data, i+1 );
127        }
128      }
129    else
130      {
131      // lower triangular: copy the diagonal and the elements below the diagonal
132     
133      for(uword i=0; i<N; ++i)
134        {
135        const eT* A_data   = A.colptr(i);
136              eT* out_data = out.colptr(i);
137       
138        arrayops::copy( &out_data[i], &A_data[i], N-i );
139        }
140      }
141    }
142 
143 
144  if(do_conj)
145    {
146    if(upper)
147      {
148      // reflect elements across the diagonal from upper triangle to lower triangle
149     
150      for(uword col=1; col < N; ++col)
151        {
152        const eT* coldata = out.colptr(col);
153       
154        for(uword row=0; row < col; ++row)
155          {
156          out.at(col,row) = std::conj(coldata[row]);
157          }
158        }
159      }
160    else
161      {
162      // reflect elements across the diagonal from lower triangle to upper triangle
163     
164      for(uword col=0; col < N; ++col)
165        {
166        const eT* coldata = out.colptr(col);
167       
168        for(uword row=(col+1); row < N; ++row)
169          {
170          out.at(col,row) = std::conj(coldata[row]);
171          }
172        }
173      }
174    }
175  else  // don't do complex conjugation
176    {
177    if(upper)
178      {
179      // reflect elements across the diagonal from upper triangle to lower triangle
180     
181      for(uword col=1; col < N; ++col)
182        {
183        const eT* coldata = out.colptr(col);
184       
185        for(uword row=0; row < col; ++row)
186          {
187          out.at(col,row) = coldata[row];
188          }
189        }
190      }
191    else
192      {
193      // reflect elements across the diagonal from lower triangle to upper triangle
194     
195      for(uword col=0; col < N; ++col)
196        {
197        const eT* coldata = out.colptr(col);
198       
199        for(uword row=(col+1); row < N; ++row)
200          {
201          out.at(col,row) = coldata[row];
202          }
203        }
204      }
205    }
206  }
207
208
209
210//! @}
Note: See TracBrowser for help on using the repository browser.