"Fossies" - the Fresh Open Source Software Archive

Member "armadillo-9.800.3/include/armadillo_bits/fn_sum.hpp" (16 Jun 2016, 2763 Bytes) of package /linux/misc/armadillo-9.800.3.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "fn_sum.hpp" see the Fossies "Dox" file reference documentation.

    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 
   16 
   17 //! \addtogroup fn_sum
   18 //! @{
   19 
   20 
   21 template<typename T1>
   22 arma_warn_unused
   23 inline
   24 typename enable_if2< is_arma_type<T1>::value && resolves_to_vector<T1>::yes, typename T1::elem_type >::result
   25 sum(const T1& X)
   26   {
   27   arma_extra_debug_sigprint();
   28   
   29   return accu(X);
   30   }
   31 
   32 
   33 
   34 template<typename T1>
   35 arma_warn_unused
   36 arma_inline
   37 typename enable_if2< is_arma_type<T1>::value && resolves_to_vector<T1>::no, const Op<T1, op_sum> >::result
   38 sum(const T1& X)
   39   {
   40   arma_extra_debug_sigprint();
   41   
   42   return Op<T1, op_sum>(X, 0, 0);
   43   }
   44 
   45 
   46 
   47 template<typename T1>
   48 arma_warn_unused
   49 arma_inline
   50 typename enable_if2< is_arma_type<T1>::value, const Op<T1, op_sum> >::result
   51 sum(const T1& X, const uword dim)
   52   {
   53   arma_extra_debug_sigprint();
   54   
   55   return Op<T1, op_sum>(X, dim, 0);
   56   }
   57 
   58 
   59 
   60 template<typename T>
   61 arma_warn_unused
   62 arma_inline
   63 typename arma_scalar_only<T>::result
   64 sum(const T& x)
   65   {
   66   return x;
   67   }
   68 
   69 
   70 
   71 //! sum of cube
   72 template<typename T1>
   73 arma_warn_unused
   74 arma_inline
   75 const OpCube<T1, op_sum>
   76 sum
   77   (
   78   const BaseCube<typename T1::elem_type,T1>& X,
   79   const uword dim = 0
   80   )
   81   {
   82   arma_extra_debug_sigprint();
   83   
   84   return OpCube<T1, op_sum>(X.get_ref(), dim, 0);
   85   }
   86 
   87 
   88 
   89 //! sum of sparse object
   90 template<typename T1>
   91 arma_warn_unused
   92 inline
   93 typename
   94 enable_if2
   95   <
   96   is_arma_sparse_type<T1>::value && resolves_to_sparse_vector<T1>::yes,
   97   typename T1::elem_type
   98   >::result
   99 sum(const T1& x)
  100   {
  101   arma_extra_debug_sigprint();
  102   
  103   // sum elements
  104   return accu(x);
  105   }
  106 
  107 
  108 
  109 template<typename T1>
  110 arma_warn_unused
  111 inline
  112 typename
  113 enable_if2
  114   <
  115   is_arma_sparse_type<T1>::value && resolves_to_sparse_vector<T1>::no,
  116   const SpOp<T1,spop_sum>
  117   >::result
  118 sum(const T1& x)
  119   {
  120   arma_extra_debug_sigprint();
  121   
  122   return SpOp<T1,spop_sum>(x, 0, 0);
  123   }
  124 
  125 
  126 
  127 template<typename T1>
  128 arma_warn_unused
  129 inline
  130 typename
  131 enable_if2
  132   <
  133   is_arma_sparse_type<T1>::value,
  134   const SpOp<T1,spop_sum>
  135   >::result
  136 sum(const T1& x, const uword dim)
  137   {
  138   arma_extra_debug_sigprint();
  139   
  140   return SpOp<T1,spop_sum>(x, dim, 0);
  141   }
  142 
  143 
  144 
  145 //! @}