"Fossies" - the Fresh Open Source Software Archive

Member "armadillo-9.800.3/include/armadillo_bits/op_symmat_meat.hpp" (16 Jun 2016, 5233 Bytes) of package /linux/misc/armadillo-9.800.3.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "op_symmat_meat.hpp" see the Fossies "Dox" file reference documentation.

    1 // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
    2 // Copyright 2008-2016 National ICT Australia (NICTA)
    3 // 
    4 // Licensed under the Apache License, Version 2.0 (the "License");
    5 // you may not use this file except in compliance with the License.
    6 // You may obtain a copy of the License at
    7 // http://www.apache.org/licenses/LICENSE-2.0
    8 // 
    9 // Unless required by applicable law or agreed to in writing, software
   10 // distributed under the License is distributed on an "AS IS" BASIS,
   11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   12 // See the License for the specific language governing permissions and
   13 // limitations under the License.
   14 // ------------------------------------------------------------------------
   15 
   16 
   17 //! \addtogroup op_symmat
   18 //! @{
   19 
   20 
   21 
   22 template<typename T1>
   23 inline
   24 void
   25 op_symmat::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_symmat>& in)
   26   {
   27   arma_extra_debug_sigprint();
   28   
   29   typedef typename T1::elem_type eT;
   30   
   31   const unwrap<T1>   tmp(in.m);
   32   const Mat<eT>& A = tmp.M;
   33   
   34   arma_debug_check( (A.is_square() == false), "symmatu()/symmatl(): given matrix must be square sized" );
   35   
   36   const uword N     = A.n_rows;
   37   const bool  upper = (in.aux_uword_a == 0);
   38   
   39   if(&out != &A)
   40     {
   41     out.copy_size(A);
   42     
   43     if(upper)
   44       {
   45       // upper triangular: copy the diagonal and the elements above the diagonal
   46       
   47       for(uword i=0; i<N; ++i)
   48         {
   49         const eT* A_data   = A.colptr(i);
   50               eT* out_data = out.colptr(i);
   51         
   52         arrayops::copy( out_data, A_data, i+1 );
   53         }
   54       }
   55     else
   56       {
   57       // lower triangular: copy the diagonal and the elements below the diagonal
   58       
   59       for(uword i=0; i<N; ++i)
   60         {
   61         const eT* A_data   = A.colptr(i);
   62               eT* out_data = out.colptr(i);
   63         
   64         arrayops::copy( &out_data[i], &A_data[i], N-i );
   65         }
   66       }
   67     }
   68   
   69   
   70   if(upper)
   71     {
   72     // reflect elements across the diagonal from upper triangle to lower triangle
   73     
   74     for(uword col=1; col < N; ++col)
   75       {
   76       const eT* coldata = out.colptr(col);
   77       
   78       for(uword row=0; row < col; ++row)
   79         {
   80         out.at(col,row) = coldata[row];
   81         }
   82       }
   83     }
   84   else
   85     {
   86     // reflect elements across the diagonal from lower triangle to upper triangle
   87     
   88     for(uword col=0; col < N; ++col)
   89       {
   90       const eT* coldata = out.colptr(col);
   91       
   92       for(uword row=(col+1); row < N; ++row)
   93         {
   94         out.at(col,row) = coldata[row];
   95         }
   96       }
   97     }
   98   }
   99 
  100 
  101 
  102 template<typename T1>
  103 inline
  104 void
  105 op_symmat_cx::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_symmat_cx>& in)
  106   {
  107   arma_extra_debug_sigprint();
  108   
  109   typedef typename T1::elem_type eT;
  110   
  111   const unwrap<T1>   tmp(in.m);
  112   const Mat<eT>& A = tmp.M;
  113   
  114   arma_debug_check( (A.is_square() == false), "symmatu()/symmatl(): given matrix must be square sized" );
  115   
  116   const uword N  = A.n_rows;
  117   
  118   const bool upper   = (in.aux_uword_a == 0);
  119   const bool do_conj = (in.aux_uword_b == 1);
  120   
  121   if(&out != &A)
  122     {
  123     out.copy_size(A);
  124     
  125     if(upper)
  126       {
  127       // upper triangular: copy the diagonal and the elements above the diagonal
  128       
  129       for(uword i=0; i<N; ++i)
  130         {
  131         const eT* A_data   = A.colptr(i);
  132               eT* out_data = out.colptr(i);
  133         
  134         arrayops::copy( out_data, A_data, i+1 );
  135         }
  136       }
  137     else
  138       {
  139       // lower triangular: copy the diagonal and the elements below the diagonal
  140       
  141       for(uword i=0; i<N; ++i)
  142         {
  143         const eT* A_data   = A.colptr(i);
  144               eT* out_data = out.colptr(i);
  145         
  146         arrayops::copy( &out_data[i], &A_data[i], N-i );
  147         }
  148       }
  149     }
  150   
  151   
  152   if(do_conj)
  153     {
  154     if(upper)
  155       {
  156       // reflect elements across the diagonal from upper triangle to lower triangle
  157       
  158       for(uword col=1; col < N; ++col)
  159         {
  160         const eT* coldata = out.colptr(col);
  161         
  162         for(uword row=0; row < col; ++row)
  163           {
  164           out.at(col,row) = std::conj(coldata[row]);
  165           }
  166         }
  167       }
  168     else
  169       {
  170       // reflect elements across the diagonal from lower triangle to upper triangle
  171       
  172       for(uword col=0; col < N; ++col)
  173         {
  174         const eT* coldata = out.colptr(col);
  175         
  176         for(uword row=(col+1); row < N; ++row)
  177           {
  178           out.at(col,row) = std::conj(coldata[row]);
  179           }
  180         }
  181       }
  182     }
  183   else  // don't do complex conjugation
  184     {
  185     if(upper)
  186       {
  187       // reflect elements across the diagonal from upper triangle to lower triangle
  188       
  189       for(uword col=1; col < N; ++col)
  190         {
  191         const eT* coldata = out.colptr(col);
  192         
  193         for(uword row=0; row < col; ++row)
  194           {
  195           out.at(col,row) = coldata[row];
  196           }
  197         }
  198       }
  199     else
  200       {
  201       // reflect elements across the diagonal from lower triangle to upper triangle
  202       
  203       for(uword col=0; col < N; ++col)
  204         {
  205         const eT* coldata = out.colptr(col);
  206         
  207         for(uword row=(col+1); row < N; ++row)
  208           {
  209           out.at(col,row) = coldata[row];
  210           }
  211         }
  212       }
  213     }
  214   }
  215 
  216 
  217 
  218 //! @}