comparison armadillo-3.900.4/include/armadillo_bits/fn_sum.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) 2008-2012 NICTA (www.nicta.com.au)
2 // Copyright (C) 2008-2012 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 fn_sum
10 //! @{
11
12
13 //! \brief
14 //! Delayed sum of elements of a matrix along a specified dimension (either rows or columns).
15 //! The result is stored in a dense matrix that has either one column or one row.
16 //! For dim = 0, find the sum of each column (traverse across rows)
17 //! For dim = 1, find the sum of each row (traverse across columns)
18 //! The default is dim = 0.
19 //! NOTE: the dim argument is different than in Matlab/Octave.
20
21 template<typename T1>
22 arma_inline
23 const Op<T1, op_sum>
24 sum
25 (
26 const T1& X,
27 const uword dim = 0,
28 const typename enable_if< is_arma_type<T1>::value == true >::result* junk1 = 0,
29 const typename enable_if< resolves_to_vector<T1>::value == false >::result* junk2 = 0
30 )
31 {
32 arma_extra_debug_sigprint();
33 arma_ignore(junk1);
34 arma_ignore(junk2);
35
36 return Op<T1, op_sum>(X, dim, 0);
37 }
38
39
40
41 template<typename T1>
42 arma_inline
43 const Op<T1, op_sum>
44 sum
45 (
46 const T1& X,
47 const uword dim,
48 const typename enable_if< resolves_to_vector<T1>::value == true >::result* junk = 0
49 )
50 {
51 arma_extra_debug_sigprint();
52 arma_ignore(junk);
53
54 return Op<T1, op_sum>(X, dim, 0);
55 }
56
57
58
59 //! \brief
60 //! Immediate 'sum all values' operation for expressions which resolve to a vector
61 template<typename T1>
62 inline
63 arma_warn_unused
64 typename T1::elem_type
65 sum
66 (
67 const T1& X,
68 const arma_empty_class junk1 = arma_empty_class(),
69 const typename enable_if< resolves_to_vector<T1>::value == true >::result* junk2 = 0
70 )
71 {
72 arma_extra_debug_sigprint();
73 arma_ignore(junk1);
74 arma_ignore(junk2);
75
76 return accu(X);
77 }
78
79
80
81 //! \brief
82 //! Immediate 'sum all values' operation,
83 //! invoked, for example, by: sum(sum(A))
84
85 template<typename T1>
86 inline
87 arma_warn_unused
88 typename T1::elem_type
89 sum(const Op<T1, op_sum>& in)
90 {
91 arma_extra_debug_sigprint();
92 arma_extra_debug_print("sum(): two consecutive sum() calls detected");
93
94 return accu(in.m);
95 }
96
97
98
99 template<typename T1>
100 arma_inline
101 const Op<Op<T1, op_sum>, op_sum>
102 sum(const Op<T1, op_sum>& in, const uword dim)
103 {
104 arma_extra_debug_sigprint();
105
106 return Op<Op<T1, op_sum>, op_sum>(in, dim, 0);
107 }
108
109
110
111 template<typename T>
112 arma_inline
113 arma_warn_unused
114 const typename arma_scalar_only<T>::result &
115 sum(const T& x)
116 {
117 return x;
118 }
119
120
121
122 //! sum of sparse object
123 template<typename T1>
124 inline
125 typename
126 enable_if2
127 <
128 (is_arma_sparse_type<T1>::value == true) && (resolves_to_sparse_vector<T1>::value == true),
129 typename T1::elem_type
130 >::result
131 sum(const T1& x)
132 {
133 arma_extra_debug_sigprint();
134
135 // sum elements
136 return accu(x);
137 }
138
139
140
141 template<typename T1>
142 inline
143 typename
144 enable_if2
145 <
146 (is_arma_sparse_type<T1>::value == true) && (resolves_to_sparse_vector<T1>::value == false),
147 const SpOp<T1,spop_sum>
148 >::result
149 sum(const T1& x, const uword dim = 0)
150 {
151 arma_extra_debug_sigprint();
152
153 return SpOp<T1,spop_sum>(x, dim, 0);
154 }
155
156
157
158 template<typename T1>
159 inline
160 arma_warn_unused
161 typename T1::elem_type
162 sum(const SpOp<T1, spop_sum>& in)
163 {
164 arma_extra_debug_sigprint();
165 arma_extra_debug_print("sum(): two consecutive sum() calls detected");
166
167 return accu(in.m);
168 }
169
170
171
172 template<typename T1>
173 arma_inline
174 const SpOp<SpOp<T1, spop_sum>, spop_sum>
175 sum(const SpOp<T1, spop_sum>& in, const uword dim)
176 {
177 arma_extra_debug_sigprint();
178
179 return SpOp<SpOp<T1, spop_sum>, spop_sum>(in, dim, 0);
180 }
181
182
183
184 //! @}