fn_prod.hpp
Go to the documentation of this file.
1 // Copyright (C) 2009-2011 NICTA (www.nicta.com.au)
2 // Copyright (C) 2009-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 
25 
26 template<typename T1>
28 const Op<T1, op_prod>
29 prod(const Base<typename T1::elem_type,T1>& X, const uword dim = 0)
30  {
32 
33  return Op<T1, op_prod>(X.get_ref(), dim, 0);
34  }
35 
36 
37 
40 template<typename eT>
41 inline
43 eT
44 prod(const Row<eT>& X)
45  {
47 
48  return arrayops::product(X.memptr(), X.n_elem);
49  }
50 
51 
52 
55 template<typename eT>
56 inline
58 eT
59 prod(const Col<eT>& X)
60  {
62 
63  return arrayops::product(X.memptr(), X.n_elem);
64  }
65 
66 
67 
71 
72 template<typename T1>
73 inline
74 typename T1::elem_type
76  {
78  arma_extra_debug_print("prod(): two consecutive prod() calls detected");
79 
80  typedef typename T1::elem_type eT;
81 
82  const unwrap<T1> tmp(in.m);
83  const Mat<eT>& X = tmp.M;
84 
85  return arrayops::product( X.memptr(), X.n_elem );
86  }
87 
88 
89 
90 template<typename T1>
91 inline
93 prod(const Op<T1, op_prod>& in, const uword dim)
94  {
96 
97  return Op<Op<T1, op_prod>, op_prod>(in, dim, 0);
98  }
99 
100 
101 
103 template<typename eT>
104 inline
106 eT
108  {
110 
111  const Mat<eT>& X = S.m;
112 
113  const uword n_elem = S.n_elem;
114  const uword row = S.aux_row1;
115  const uword start_col = S.aux_col1;
116  const uword end_col_plus_1 = start_col + S.n_cols;
117 
118  eT val = eT(1);
119 
120  if(n_elem > 0)
121  {
122  for(uword col=start_col; col<end_col_plus_1; ++col)
123  {
124  val *= X.at(row,col);
125  }
126  }
127 
128  return val;
129  }
130 
131 
132 
134 template<typename eT>
135 inline
137 eT
139  {
141 
142  return (S.n_elem > 0) ? arrayops::product( S.colptr(0), S.n_rows ) : eT(1);
143  }
144 
145 
146 
148 template<typename eT>
150 inline
151 eT
153  {
155 
156  const uword X_n_elem = X.n_elem;
157 
158  eT val = eT(1);
159 
160  for(uword i=0; i<X_n_elem; ++i)
161  {
162  val *= X[i];
163  }
164 
165  return val;
166  }
167 
168 
169 
170 template<typename eT, typename T1>
171 inline
173 eT
175  {
177 
178  const Col<eT> X(A);
179 
180  return prod(X);
181  }
182 
183 
184 
const uword aux_col1
arma_inline arma_warn_unused eT * memptr()
returns a pointer to array of eTs used by the matrix
Definition: Mat_meat.hpp:4024
arma_inline const derived & get_ref() const
Definition: Base_meat.hpp:22
const uword n_cols
const uword n_rows
const uword n_elem
number of elements in the matrix (read-only)
Definition: Mat_bones.hpp:31
#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
arma_hot static arma_pure eT product(const eT *src, const uword n_elem)
const uword n_elem
u32 uword
Definition: typedef.hpp:85
Class for column vectors (matrices with only one column)
Definition: Col_bones.hpp:20
const uword aux_row1
const Mat< eT > M
Definition: unwrap.hpp:32
arma_inline arma_warn_unused eT & at(const uword i)
linear element accessor (treats the matrix as a vector); no bounds check.
Definition: Mat_meat.hpp:3692
arma_aligned const Mat< eT > & m
arma_inline eT * colptr(const uword in_col)
arma_inline const Op< T1, op_prod > prod(const Base< typename T1::elem_type, T1 > &X, const uword dim=0)
Delayed product of elements of a matrix along a specified dimension (either rows or columns)...
Definition: fn_prod.hpp:29
Class for row vectors (matrices with only one row)
#define arma_extra_debug_sigprint
Definition: debug.hpp:1116
#define arma_warn_unused
Class for finding products of values in a matrix (e.g. along rows or columns)
Dense matrix class.
#define arma_inline
const uword n_elem
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