comparison armadillo-3.900.4/include/armadillo_bits/glue_conv_meat.hpp @ 49:1ec0e2823891

Switch to using subrepo copies of qm-dsp, nnls-chroma, vamp-plugin-sdk; update Armadillo version; assume build without external BLAS/LAPACK
author Chris Cannam
date Thu, 13 Jun 2013 10:25:24 +0100
parents
children
comparison
equal deleted inserted replaced
48:69251e11a913 49:1ec0e2823891
1 // Copyright (C) 2010-2013 NICTA (www.nicta.com.au)
2 // Copyright (C) 2010-2013 Conrad Sanderson
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 glue_conv
10 //! @{
11
12
13 //! rudimentary implementation of the convolution operation
14
15 template<typename T1, typename T2>
16 inline
17 void
18 glue_conv::apply(Mat<typename T1::elem_type>& out, const Glue<T1,T2,glue_conv>& X)
19 {
20 arma_extra_debug_sigprint();
21
22 typedef typename T1::elem_type eT;
23
24 const unwrap_check<T1> A_tmp(X.A, out);
25 const unwrap_check<T2> B_tmp(X.B, out);
26
27 const Mat<eT>& A = A_tmp.M;
28 const Mat<eT>& B = B_tmp.M;
29
30 arma_debug_check
31 (
32 ( ((A.is_vec() == false) && (A.is_empty() == false)) || ((B.is_vec() == false) && (B.is_empty() == false)) ),
33 "conv(): given object is not a vector"
34 );
35
36
37 const Mat<eT>& h = (A.n_elem <= B.n_elem) ? A : B;
38 const Mat<eT>& x = (A.n_elem <= B.n_elem) ? B : A;
39
40
41 const uword h_n_elem = h.n_elem;
42 const uword x_n_elem = x.n_elem;
43 const uword out_n_elem = h_n_elem + x_n_elem - 1;
44
45
46 if( (h_n_elem == 0) || (x_n_elem == 0) )
47 {
48 out.reset();
49 return;
50 }
51
52
53 (A.n_cols == 1) ? out.set_size(out_n_elem, 1) : out.set_size(1, out_n_elem);
54
55
56 const eT* h_mem = h.memptr();
57 const eT* x_mem = x.memptr();
58 eT* out_mem = out.memptr();
59
60
61 for(uword out_i = 0; out_i < (h_n_elem-1); ++out_i)
62 {
63 eT acc = eT(0);
64
65 uword h_i = out_i;
66
67 for(uword x_i = 0; x_i <= out_i; ++x_i, --h_i)
68 {
69 acc += h_mem[h_i] * x_mem[x_i];
70 }
71
72 out_mem[out_i] = acc;
73 }
74
75
76 for(uword out_i = h_n_elem-1; out_i < out_n_elem - (h_n_elem-1); ++out_i)
77 {
78 eT acc = eT(0);
79
80 uword h_i = h_n_elem - 1;
81
82 for(uword x_i = out_i - h_n_elem + 1; x_i <= out_i; ++x_i, --h_i)
83 {
84 acc += h_mem[h_i] * x_mem[x_i];
85 }
86
87 out_mem[out_i] = acc;
88 }
89
90
91 for(uword out_i = out_n_elem - (h_n_elem-1); out_i < out_n_elem; ++out_i)
92 {
93 eT acc = eT(0);
94
95 uword h_i = h_n_elem - 1;
96
97 for(uword x_i = out_i - h_n_elem + 1; x_i < x_n_elem; ++x_i, --h_i)
98 {
99 acc += h_mem[h_i] * x_mem[x_i];
100 }
101
102 out_mem[out_i] = acc;
103 }
104
105
106 }
107
108
109
110 //! @}