glue_toeplitz_meat.hpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2011 NICTA (www.nicta.com.au)
2 // Copyright (C) 2010-2011 Conrad Sanderson
3 // Copyright (C) 2011 Alcatel Lucent
4 // Copyright (C) 2011 Gerhard Schreiber
5 //
6 // This file is part of the Armadillo C++ library.
7 // It is provided without any warranty of fitness
8 // for any purpose. You can redistribute this file
9 // and/or modify it under the terms of the GNU
10 // Lesser General Public License (LGPL) as published
11 // by the Free Software Foundation, either version 3
12 // of the License or (at your option) any later version.
13 // (see http://www.opensource.org/licenses for more info)
14 
15 
16 
19 
20 
21 
22 template<typename T1, typename T2>
23 inline
24 void
26  {
28 
29  typedef typename T1::elem_type eT;
30 
31  if( ((void*)(&in.A)) == ((void*)(&in.B)) )
32  {
33  arma_extra_debug_print("glue_toeplitz::apply(): one argument version");
34 
35  const unwrap_check<T1> tmp(in.A, out);
36  const Mat<eT>& A = tmp.M;
37 
38  arma_debug_check( (A.is_vec() == false), "toeplitz(): input argument must be a vector" );
39 
40  const uword N = A.n_elem;
41  const eT* A_mem = A.memptr();
42 
43  out.set_size(N,N);
44 
45  for(uword col=0; col<N; ++col)
46  {
47  eT* col_mem = out.colptr(col);
48 
49  uword i;
50 
51  i = col;
52  for(uword row=0; row<col; ++row, --i)
53  {
54  col_mem[row] = A_mem[i];
55  }
56 
57  i = 0;
58  for(uword row=col; row<N; ++row, ++i)
59  {
60  col_mem[row] = A_mem[i];
61  }
62  }
63  }
64  else
65  {
66  arma_extra_debug_print("glue_toeplitz::apply(): two argument version");
67 
68  const unwrap_check<T1> tmp1(in.A, out);
69  const unwrap_check<T2> tmp2(in.B, out);
70 
71  const Mat<eT>& A = tmp1.M;
72  const Mat<eT>& B = tmp2.M;
73 
74  arma_debug_check( ( (A.is_vec() == false) || (B.is_vec() == false) ), "toeplitz(): input arguments must be vectors" );
75 
76  const uword A_N = A.n_elem;
77  const uword B_N = B.n_elem;
78 
79  const eT* A_mem = A.memptr();
80  const eT* B_mem = B.memptr();
81 
82  out.set_size(A_N, B_N);
83 
84  if( out.is_empty() )
85  {
86  return;
87  }
88 
89  for(uword col=0; col<B_N; ++col)
90  {
91  eT* col_mem = out.colptr(col);
92 
93  uword i = 0;
94  for(uword row=col; row<A_N; ++row, ++i)
95  {
96  col_mem[row] = A_mem[i];
97  }
98  }
99 
100  for(uword row=0; row<A_N; ++row)
101  {
102  uword i = 1;
103  for(uword col=(row+1); col<B_N; ++col, ++i)
104  {
105  out.at(row,col) = B_mem[i];
106  }
107  }
108 
109  }
110 
111 
112  }
113 
114 
115 
116 template<typename T1, typename T2>
117 inline
118 void
120  {
122 
123  typedef typename T1::elem_type eT;
124 
125  if( ((void*)(&in.A)) == ((void*)(&in.B)) )
126  {
127  arma_extra_debug_print("glue_toeplitz_circ::apply(): one argument version");
128 
129  const unwrap_check<T1> tmp(in.A, out);
130  const Mat<eT>& A = tmp.M;
131 
132  arma_debug_check( (A.is_vec() == false), "toeplitz(): input argument must be a vector" );
133 
134  const uword N = A.n_elem;
135  const eT* A_mem = A.memptr();
136 
137  out.set_size(N,N);
138 
139 
140  if(A.is_colvec())
141  {
142  // A is interpreted as colvec
143 
144  for(uword col=0; col<N; ++col)
145  {
146  eT* col_mem = out.colptr(col);
147 
148 
149  uword i = col;
150 
151  for(uword row=0; row<col; ++row, --i)
152  {
153  col_mem[row] = A_mem[N-i];
154  }
155 
156 
157  i = 0;
158 
159  for(uword row=col; row<N; ++row, ++i)
160  {
161  col_mem[row] = A_mem[i];
162  }
163  }
164 
165  }
166  else
167  {
168  // A is interpreted as rowvec - probably not the computationally most efficient way to do this ;-)
169 
170  for(uword row=0; row<N; ++row)
171  {
172  uword i = row;
173 
174  for(uword col=0; col<row; ++col, --i)
175  {
176  out.at(row,col) = A_mem[N-i];
177  }
178 
179  i = 0;
180 
181  for(uword col=row; col<N; ++col, ++i)
182  {
183  out.at(row,col) = A_mem[i];
184  }
185  }
186  }
187  }
188  }
189 
190 
191 
arma_inline arma_warn_unused bool is_vec() const
returns true if the object can be interpreted as a column or row vector
Definition: Mat_meat.hpp:3824
arma_inline arma_warn_unused eT * memptr()
returns a pointer to array of eTs used by the matrix
Definition: Mat_meat.hpp:4024
void set_size(const uword in_elem)
change the matrix to have user specified dimensions (data is not preserved)
Definition: Mat_meat.hpp:4211
static void apply(Mat< typename T1::elem_type > &out, const Glue< T1, T2, glue_toeplitz > &in)
arma_inline arma_warn_unused bool is_colvec() const
returns true if the object can be interpreted as a column vector
Definition: Mat_meat.hpp:3848
static void apply(Mat< typename T1::elem_type > &out, const Glue< T1, T2, glue_toeplitz_circ > &in)
const uword n_elem
number of elements in the matrix (read-only)
Definition: Mat_bones.hpp:31
#define arma_extra_debug_print
Definition: debug.hpp:1118
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 T1 & A
first operand
Definition: Glue_bones.hpp:44
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
const T2 & B
second operand
Definition: Glue_bones.hpp:45
#define arma_extra_debug_sigprint
Definition: debug.hpp:1116
Dense matrix class.
const Mat< eT > M
Definition: unwrap.hpp:142
arma_inline arma_warn_unused bool is_empty() const
returns true if the matrix has no elements
Definition: Mat_meat.hpp:3812


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