SigUtil  0.95
Utility modules for modern C++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
comparable_check.hpp
Go to the documentation of this file.
1 /*
2 Copyright© 2014 Akihiro Nishimura
3 
4 This software is released under the MIT License.
5 http://opensource.org/licenses/mit-license.php
6 */
7 
8 #ifndef SIG_UTIL_COMPARE_CHECK_HPP
9 #define SIG_UTIL_COMPARE_CHECK_HPP
10 
11 #include "../helper/helper_modules.hpp"
12 
13 namespace sig
14 {
15 namespace impl
16 {
18 struct DistributionTag{};
19 }
20 
21 // 2つのコンテナのサイズが同じか確認
22 template <class C1, class C2>
23 bool is_same_size(C1 const& v1, C2 const& v2)
24 {
25  return v1.size() == v2.size(); //todo: define like sig::size()
26 }
27 
29 template <class C1, class C2>
30 bool is_valid_distribution(C1 const& v1, C2 const& v2)
31 {
32  return sig::equal(std::accumulate(std::begin(v1), std::end(v1), 0.0), 1)
33  && sig::equal(std::accumulate(std::begin(v2), std::end(v2), 0.0), 1);
34 }
35 
37 template <class C>
38 bool has_zero(C const& v)
39 {
40  return !std::accumulate(std::begin(v), std::end(v), true, [](bool s, bool e){ return s && e != 0; });
41 }
42 
44 template <class C1, class C2>
45 bool is_comparable(C1 const& v1, C2 const& v2, impl::NumericVectorTag)
46 {
47  return is_same_size(v1, v2);
48 }
49 
51 template <class C1, class C2>
52 bool is_comparable(C1 const& v1, C2 const& v2, impl::DistributionTag)
53 {
54  return is_same_size(v1, v2) && is_valid_distribution(v1, v2);
55 }
56 
57 }
58 #endif
bool is_valid_distribution(C1 const &v1, C2 const &v2)
離散確率分布の性質を満たしているか確認
auto end(C &&c) -> std::move_iterator< typename RC::iterator >
bool is_comparable(C1 const &v1, C2 const &v2, impl::NumericVectorTag)
2つのベクトルが比較可能か確認
bool has_zero(C const &v)
要素の値に0があるか確認
bool equal(T1 &&v1, T2 &&v2)
数値の簡易等値比較(厳密な計算でない場合の使用を想定)
bool is_same_size(C1 const &v1, C2 const &v2)
Definition: array.hpp:15
auto begin(C &&c) -> std::move_iterator< typename RC::iterator >