Mercurial > hg > segmenter-vamp-plugin
comparison armadillo-2.4.4/include/armadillo_bits/fn_sum.hpp @ 0:8b6102e2a9b0
Armadillo Library
author | maxzanoni76 <max.zanoni@eecs.qmul.ac.uk> |
---|---|
date | Wed, 11 Apr 2012 09:27:06 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:8b6102e2a9b0 |
---|---|
1 // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) | |
2 // Copyright (C) 2008-2010 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 | |
14 //! \addtogroup fn_sum | |
15 //! @{ | |
16 | |
17 | |
18 //! \brief | |
19 //! Delayed sum of elements of a matrix along a specified dimension (either rows or columns). | |
20 //! The result is stored in a dense matrix that has either one column or one row. | |
21 //! For dim = 0, find the sum of each column. | |
22 //! For dim = 1, find the sum of each row. | |
23 //! The default is dim = 0. | |
24 //! NOTE: this function works differently than in Matlab/Octave. | |
25 | |
26 template<typename T1> | |
27 arma_inline | |
28 const Op<T1, op_sum> | |
29 sum(const Base<typename T1::elem_type,T1>& X, const uword dim = 0) | |
30 { | |
31 arma_extra_debug_sigprint(); | |
32 | |
33 return Op<T1, op_sum>(X.get_ref(), dim, 0); | |
34 } | |
35 | |
36 | |
37 //! \brief | |
38 //! Immediate 'sum all values' operation for a row vector | |
39 template<typename eT> | |
40 inline | |
41 arma_warn_unused | |
42 eT | |
43 sum(const Row<eT>& X) | |
44 { | |
45 arma_extra_debug_sigprint(); | |
46 | |
47 return accu(X); | |
48 } | |
49 | |
50 | |
51 | |
52 //! \brief | |
53 //! Immediate 'sum all values' operation for a column vector | |
54 template<typename eT> | |
55 inline | |
56 arma_warn_unused | |
57 eT | |
58 sum(const Col<eT>& X) | |
59 { | |
60 arma_extra_debug_sigprint(); | |
61 | |
62 return accu(X); | |
63 } | |
64 | |
65 | |
66 | |
67 //! \brief | |
68 //! Immediate 'sum all values' operation, | |
69 //! invoked, for example, by: sum(sum(A)) | |
70 | |
71 template<typename T1> | |
72 inline | |
73 arma_warn_unused | |
74 typename T1::elem_type | |
75 sum(const Op<T1, op_sum>& in) | |
76 { | |
77 arma_extra_debug_sigprint(); | |
78 arma_extra_debug_print("sum(): two consecutive sum() calls detected"); | |
79 | |
80 return accu(in.m); | |
81 } | |
82 | |
83 | |
84 | |
85 template<typename T1> | |
86 arma_inline | |
87 const Op<Op<T1, op_sum>, op_sum> | |
88 sum(const Op<T1, op_sum>& in, const uword dim) | |
89 { | |
90 arma_extra_debug_sigprint(); | |
91 | |
92 return Op<Op<T1, op_sum>, op_sum>(in, dim, 0); | |
93 } | |
94 | |
95 | |
96 | |
97 //! sum all values of a subview_row | |
98 template<typename eT> | |
99 inline | |
100 arma_warn_unused | |
101 eT | |
102 sum(const subview_row<eT>& X) | |
103 { | |
104 arma_extra_debug_sigprint(); | |
105 | |
106 return accu(X); | |
107 } | |
108 | |
109 | |
110 | |
111 //! sum all values of a subview_col | |
112 template<typename eT> | |
113 inline | |
114 arma_warn_unused | |
115 eT | |
116 sum(const subview_col<eT>& X) | |
117 { | |
118 arma_extra_debug_sigprint(); | |
119 | |
120 return accu(X); | |
121 } | |
122 | |
123 | |
124 | |
125 //! sum all values of a diagview | |
126 template<typename eT> | |
127 inline | |
128 arma_warn_unused | |
129 eT | |
130 sum(const diagview<eT>& X) | |
131 { | |
132 arma_extra_debug_sigprint(); | |
133 | |
134 return accu(X); | |
135 } | |
136 | |
137 | |
138 | |
139 template<typename eT, typename T1> | |
140 inline | |
141 arma_warn_unused | |
142 eT | |
143 sum(const subview_elem1<eT,T1>& A) | |
144 { | |
145 arma_extra_debug_sigprint(); | |
146 | |
147 return accu(A); | |
148 } | |
149 | |
150 | |
151 | |
152 //! @} |