fn_sum.hpp
Go to the documentation of this file.
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 
16 
17 
25 
26 template<typename T1>
28 const Op<T1, op_sum>
29 sum(const Base<typename T1::elem_type,T1>& X, const uword dim = 0)
30  {
32 
33  return Op<T1, op_sum>(X.get_ref(), dim, 0);
34  }
35 
36 
39 template<typename eT>
40 inline
42 eT
43 sum(const Row<eT>& X)
44  {
46 
47  return accu(X);
48  }
49 
50 
51 
54 template<typename eT>
55 inline
57 eT
58 sum(const Col<eT>& X)
59  {
61 
62  return accu(X);
63  }
64 
65 
66 
70 
71 template<typename T1>
72 inline
74 typename T1::elem_type
75 sum(const Op<T1, op_sum>& in)
76  {
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>
88 sum(const Op<T1, op_sum>& in, const uword dim)
89  {
91 
92  return Op<Op<T1, op_sum>, op_sum>(in, dim, 0);
93  }
94 
95 
96 
98 template<typename eT>
99 inline
101 eT
103  {
105 
106  return accu(X);
107  }
108 
109 
110 
112 template<typename eT>
113 inline
115 eT
117  {
119 
120  return accu(X);
121  }
122 
123 
124 
126 template<typename eT>
127 inline
129 eT
130 sum(const diagview<eT>& X)
131  {
133 
134  return accu(X);
135  }
136 
137 
138 
139 template<typename eT, typename T1>
140 inline
142 eT
144  {
146 
147  return accu(A);
148  }
149 
150 
151 
arma_inline const Op< T1, op_sum > sum(const Base< typename T1::elem_type, T1 > &X, const uword dim=0)
Delayed sum of elements of a matrix along a specified dimension (either rows or columns). The result is stored in a dense matrix that has either one column or one row. For dim = 0, find the sum of each column. For dim = 1, find the sum of each row. The default is dim = 0. NOTE: this function works differently than in Matlab/Octave.
Definition: fn_sum.hpp:29
arma_inline const derived & get_ref() const
Definition: Base_meat.hpp:22
arma_hot T1::elem_type accu(const Base< typename T1::elem_type, T1 > &X)
accumulate the elements of a matrix
Definition: fn_accu.hpp:24
#define arma_extra_debug_print
Definition: debug.hpp:1118
arma_aligned const T1 & m
storage of reference to the operand (eg. a matrix)
Definition: Op_bones.hpp:45
u32 uword
Definition: typedef.hpp:85
Class for finding sums of values in a matrix (e.g. along rows or columns)
Class for column vectors (matrices with only one column)
Definition: Col_bones.hpp:20
Class for row vectors (matrices with only one row)
#define arma_extra_debug_sigprint
Definition: debug.hpp:1116
#define arma_warn_unused
#define arma_inline
Class for storing data required to extract and set the diagonals of a matrix.


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