glue_conv_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 //
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 
19 
20 template<typename T1, typename T2>
21 inline
22 void
24  {
26 
27  typedef typename T1::elem_type eT;
28 
29  const unwrap_check<T1> A_tmp(X.A, out);
30  const unwrap_check<T2> B_tmp(X.B, out);
31 
32  const Mat<eT>& A = A_tmp.M;
33  const Mat<eT>& B = B_tmp.M;
34 
35  arma_debug_check( ( (A.is_vec() == false) || (B.is_vec() == false) ), "conv(): inputs must be vectors" );
36 
37 
38  const Mat<eT>& h = (A.n_elem <= B.n_elem) ? A : B;
39  const Mat<eT>& x = (A.n_elem <= B.n_elem) ? B : A;
40 
41 
42  const uword h_n_elem = h.n_elem;
43  const uword x_n_elem = x.n_elem;
44  const uword out_n_elem = h_n_elem + x_n_elem - 1;
45 
46 
47  if( (h_n_elem == 0) || (x_n_elem == 0) )
48  {
49  out.reset();
50  return;
51  }
52 
53 
54  (A.n_cols == 1) ? out.set_size(out_n_elem, 1) : out.set_size(1, out_n_elem);
55 
56 
57  const eT* h_mem = h.memptr();
58  const eT* x_mem = x.memptr();
59  eT* out_mem = out.memptr();
60 
61 
62  for(uword out_i = 0; out_i < (h_n_elem-1); ++out_i)
63  {
64  eT acc = eT(0);
65 
66  uword h_i = out_i;
67 
68  for(uword x_i = 0; x_i <= out_i; ++x_i, --h_i)
69  {
70  acc += h_mem[h_i] * x_mem[x_i];
71  }
72 
73  out_mem[out_i] = acc;
74  }
75 
76 
77  for(uword out_i = h_n_elem-1; out_i < out_n_elem - (h_n_elem-1); ++out_i)
78  {
79  eT acc = eT(0);
80 
81  uword h_i = h_n_elem - 1;
82 
83  for(uword x_i = out_i - h_n_elem + 1; x_i <= out_i; ++x_i, --h_i)
84  {
85  acc += h_mem[h_i] * x_mem[x_i];
86  }
87 
88  out_mem[out_i] = acc;
89  }
90 
91 
92  for(uword out_i = out_n_elem - (h_n_elem-1); out_i < out_n_elem; ++out_i)
93  {
94  eT acc = eT(0);
95 
96  uword h_i = h_n_elem - 1;
97 
98  for(uword x_i = out_i - h_n_elem + 1; x_i < x_n_elem; ++x_i, --h_i)
99  {
100  acc += h_mem[h_i] * x_mem[x_i];
101  }
102 
103  out_mem[out_i] = acc;
104  }
105 
106 
107  }
108 
109 
110 
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
const uword n_cols
number of columns in the matrix (read-only)
Definition: Mat_bones.hpp:30
const uword n_elem
number of elements in the matrix (read-only)
Definition: Mat_bones.hpp:31
u32 uword
Definition: typedef.hpp:85
#define arma_debug_check
Definition: debug.hpp:1084
const T1 & A
first operand
Definition: Glue_bones.hpp:44
static void apply(Mat< typename T1::elem_type > &out, const Glue< T1, T2, glue_conv > &X)
rudimentary implementation of the convolution operation
const T2 & B
second operand
Definition: Glue_bones.hpp:45
void reset()
Definition: Mat_meat.hpp:4553
#define arma_extra_debug_sigprint
Definition: debug.hpp:1116
Dense matrix class.
const Mat< eT > M
Definition: unwrap.hpp:142


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