source: mmcs/armadillo_bits/op_diagvec_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: 2.9 KB
Line 
1// Copyright (C) 2008-2012 Conrad Sanderson
2// Copyright (C) 2008-2012 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_diagvec
10//! @{
11
12
13
14template<typename T1>
15inline
16void
17op_diagvec::apply(Mat<typename T1::elem_type>& out, const Op<T1, op_diagvec>& X)
18  {
19  arma_extra_debug_sigprint();
20 
21  typedef typename T1::elem_type eT;
22 
23  const uword a = X.aux_uword_a;
24  const uword b = X.aux_uword_b;
25 
26  const uword row_offset = (b >  0) ? a : 0;
27  const uword col_offset = (b == 0) ? a : 0;
28 
29  const Proxy<T1> P(X.m);
30 
31  const uword n_rows = P.get_n_rows();
32  const uword n_cols = P.get_n_cols();
33 
34  arma_debug_check
35    (
36    ((row_offset > 0) && (row_offset >= n_rows)) || ((col_offset > 0) && (col_offset >= n_cols)),
37    "diagvec(): requested diagonal is out of bounds"
38    );
39 
40  const uword len = (std::min)(n_rows - row_offset, n_cols - col_offset);
41 
42  if( (is_Mat<typename Proxy<T1>::stored_type>::value) && (Proxy<T1>::fake_mat == false) )
43    {
44    op_diagvec::apply_unwrap(out, P.Q, row_offset, col_offset, len);
45    }
46  else
47    {
48    if(P.is_alias(out) == false)
49      {
50      op_diagvec::apply_proxy(out, P, row_offset, col_offset, len);
51      }
52    else
53      {
54      Mat<eT> tmp;
55     
56      op_diagvec::apply_proxy(tmp, P, row_offset, col_offset, len);
57     
58      out.steal_mem(tmp);
59      }
60    }
61  }
62
63
64
65template<typename T1>
66arma_hot
67inline
68void
69op_diagvec::apply_unwrap(Mat<typename T1::elem_type>& out, const T1& X, const uword row_offset, const uword col_offset, const uword len)
70  {
71  arma_extra_debug_sigprint();
72 
73  typedef typename T1::elem_type eT;
74 
75  const unwrap_check<T1> tmp_A(X, out);
76  const Mat<eT>& A =     tmp_A.M;
77 
78  out.set_size(len, 1);
79 
80  eT* out_mem = out.memptr();
81 
82  uword i,j;
83  for(i=0, j=1; j < len; i+=2, j+=2)
84    {
85    const eT tmp_i = A.at( i + row_offset, i + col_offset );
86    const eT tmp_j = A.at( j + row_offset, j + col_offset );
87   
88    out_mem[i] = tmp_i;
89    out_mem[j] = tmp_j;
90    }
91 
92  if(i < len)
93    {
94    out_mem[i] = A.at( i + row_offset, i + col_offset );
95    }
96  }
97
98
99
100template<typename T1>
101arma_hot
102inline
103void
104op_diagvec::apply_proxy(Mat<typename T1::elem_type>& out, const Proxy<T1>& P, const uword row_offset, const uword col_offset, const uword len)
105  {
106  arma_extra_debug_sigprint();
107 
108  typedef typename T1::elem_type eT;
109 
110  out.set_size(len, 1);
111 
112  eT* out_mem = out.memptr();
113 
114  uword i,j;
115  for(i=0, j=1; j < len; i+=2, j+=2)
116    {
117    const eT tmp_i = P.at( i + row_offset, i + col_offset );
118    const eT tmp_j = P.at( j + row_offset, j + col_offset );
119   
120    out_mem[i] = tmp_i;
121    out_mem[j] = tmp_j;
122    }
123 
124  if(i < len)
125    {
126    out_mem[i] = P.at( i + row_offset, i + col_offset );
127    }
128  }
129
130
131
132//! @}
Note: See TracBrowser for help on using the repository browser.