Skip to content

Commit

Permalink
Try to fix Appveyor Bug
Browse files Browse the repository at this point in the history
  • Loading branch information
codejaeger committed Jun 18, 2020
1 parent 9580792 commit 4606a17
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 37 deletions.
4 changes: 2 additions & 2 deletions example/histogram_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ int main() {
h(1,2,1)=1;
h(3,3,1)=1;
h(1,21,21)=1;
auto h1 = h.sub_histogram<0>();
std::cout<<"sub : "<<h1(1)<<"\n";
// auto h1 = h.sub_histogram<0>();
// std::cout<<"sub : "<<h1(1)<<"\n";

auto h2 = h.sub_histogram<0,2>(std::tuple<int, int, int>(1, 0, 1));
std::cout<<"sub : "<<h2(1, 1, 1)<<"\n";
Expand Down
67 changes: 38 additions & 29 deletions include/boost/gil/histogram.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ template<typename... T>
class histogram : public std::unordered_map<std::tuple<T...>, int, detail::hash_tuple<T...> >
{
using parent_t = std::unordered_map<std::tuple<T...>, int, detail::hash_tuple<T...> >;
using bin_t = boost::mp11::mp_list<T...>;
using key_t = typename parent_t::key_type;
using mapped_t = typename parent_t::mapped_type;
using value_t = typename parent_t::value_type;
Expand Down Expand Up @@ -197,37 +198,35 @@ class histogram : public std::unordered_map<std::tuple<T...>, int, detail::hash_
return sub_h;
}

template
<
std::size_t... Dimensions,
typename BinTypes = boost::mp11::mp_list<T...>,
typename SubHistogramType = histogram<boost::mp11::mp_at_c<BinTypes, Dimensions>...>
>
SubHistogramType sub_histogram() {
using index_list = boost::mp11::mp_list_c<std::size_t, Dimensions...>;
const std::size_t index_list_size = boost::mp11::mp_size<index_list>::value;
const std::size_t histogram_dimension = get_dimension();

const std::size_t min = boost::mp11::mp_min_element<
index_list,
boost::mp11::mp_less>::value;
const std::size_t max = boost::mp11::mp_max_element<
index_list,
boost::mp11::mp_less>::value;
// Also check is_tuple_compatible()
static_assert( (0 <= min && max < histogram_dimension) &&
index_list_size < histogram_dimension,
"Index out of Range");
// template
// <
// std::size_t... Dimensions
// >
// histogram<boost::mp11::mp_at_c<bin_t, Dimensions>...> sub_histogram() {
// using index_list = boost::mp11::mp_list_c<std::size_t, Dimensions...>;
// const std::size_t index_list_size = boost::mp11::mp_size<index_list>::value;
// const std::size_t histogram_dimension = get_dimension();

// const std::size_t min = boost::mp11::mp_min_element<
// index_list,
// boost::mp11::mp_less>::value;
// const std::size_t max = boost::mp11::mp_max_element<
// index_list,
// boost::mp11::mp_less>::value;
// // Also check is_tuple_compatible()
// static_assert( (0 <= min && max < histogram_dimension) &&
// index_list_size < histogram_dimension,
// "Index out of Range");

SubHistogramType sub_h;
// // histogram<boost::mp11::mp_at_c<bin_t, Dimensions>...> sub_h;

std::for_each( parent_t::begin(), parent_t::end(), [&](value_t const& k) {
auto sub_key = detail::tuple_to_tuple(k.first,
boost::mp11::index_sequence<Dimensions...>{});
sub_h[sub_key] += parent_t::operator[](k.first);
});
return sub_h;
}
// // std::for_each( parent_t::begin(), parent_t::end(), [&](value_t const& k) {
// // auto sub_key = detail::tuple_to_tuple(k.first,
// // boost::mp11::index_sequence<Dimensions...>{});
// // sub_h[sub_key] += parent_t::operator[](k.first);
// // });
// // return sub_h;
// }

private:

Expand All @@ -240,6 +239,16 @@ class histogram : public std::unordered_map<std::tuple<T...>, int, detail::hash_
}
};

template<typename... T>
struct check_struct {
using type_list = boost::mp11::mp_list<T...>;
template<std::size_t... D>
check_struct<boost::mp11::mp_at_c<type_list, D>...> check() {
check_struct<boost::mp11::mp_at_c<type_list, D>...> f;
return f;
}
};

///
/// fill_histogram - Overload this function to provide support for
/// boost::gil::histogram or any other external histogram
Expand Down
18 changes: 12 additions & 6 deletions test/core/histogram/histogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,11 @@ void check_sub_histogram_without_tuple() {
h(2, 1, "C", 1) = 1;
h(2, 1, "D", 1) = 1;
h(2, 3, "E", 4) = 1;
auto h1 = h.sub_histogram<0,3>();
BOOST_TEST(h1(1, 1) == 2);
BOOST_TEST(h1(2, 1) == 2);
BOOST_TEST(h1(2, 4) == 1);
BOOST_TEST(h1(5, 5) == 0);
// auto h1 = h.sub_histogram<0,3>();
// BOOST_TEST(h1(1, 1) == 2);
// BOOST_TEST(h1(2, 1) == 2);
// BOOST_TEST(h1(2, 4) == 1);
// BOOST_TEST(h1(5, 5) == 0);
}

void check_sub_histogram_with_tuple() {
Expand All @@ -289,6 +289,11 @@ void check_sub_histogram_with_tuple() {
BOOST_TEST(h1(1, 3, "A", 1) == 2);
}

void temporary_check() {
gil::check_struct<int, int, std::string, int> f;
auto k = f.check<1,2>();
}

int main() {

check_helper_fn_pixel_to_tuple();
Expand All @@ -300,8 +305,9 @@ int main() {
check_histogram_key_from_pixel();
check_histogram_fill();
check_histogram_fill_algorithm();
check_sub_histogram_without_tuple();
// check_sub_histogram_without_tuple();
check_sub_histogram_with_tuple();
temporary_check();

return boost::report_errors();
}

0 comments on commit 4606a17

Please sign in to comment.