fn_prod.hpp 2.1 KB

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