1 // SPDX-License-Identifier: Apache-2.0
2 //
3 // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
4 // Copyright 2008-2016 National ICT Australia (NICTA)
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 // ------------------------------------------------------------------------
17 
18 
19 //! \addtogroup fn_prod
20 //! @{
21 
22 
23 //! \brief
24 //! Delayed product of elements of a matrix along a specified dimension (either rows or columns).
25 //! The result is stored in a dense matrix that has either one column or one row.
26 //! For dim = 0, find the sum of each column (ie. traverse across rows)
27 //! For dim = 1, find the sum of each row (ie. traverse across columns)
28 //! The default is dim = 0.
29 //! NOTE: this function works differently than in Matlab/Octave.
30 
31 template<typename T1>
32 arma_warn_unused
33 inline
34 typename enable_if2< is_arma_type<T1>::value && resolves_to_vector<T1>::yes, typename T1::elem_type >::result
prod(const T1 & X)35 prod(const T1& X)
36   {
37   arma_extra_debug_sigprint();
38 
39   return op_prod::prod(X);
40   }
41 
42 
43 
44 template<typename T1>
45 arma_warn_unused
46 arma_inline
47 typename enable_if2< is_arma_type<T1>::value && resolves_to_vector<T1>::no, const Op<T1, op_prod> >::result
prod(const T1 & X)48 prod(const T1& X)
49   {
50   arma_extra_debug_sigprint();
51 
52   return Op<T1, op_prod>(X, 0, 0);
53   }
54 
55 
56 
57 template<typename T1>
58 arma_warn_unused
59 arma_inline
60 typename enable_if2< is_arma_type<T1>::value, const Op<T1, op_prod> >::result
prod(const T1 & X,const uword dim)61 prod(const T1& X, const uword dim)
62   {
63   arma_extra_debug_sigprint();
64 
65   return Op<T1, op_prod>(X, dim, 0);
66   }
67 
68 
69 
70 template<typename T>
71 arma_warn_unused
72 arma_inline
73 typename arma_scalar_only<T>::result
prod(const T & x)74 prod(const T& x)
75   {
76   return x;
77   }
78 
79 
80 
81 //! @}
82