Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions include/samurai/subset/apply.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ namespace samurai
template <std::size_t dim, class Set, class Func, class Container>
void apply_impl(Set&& global_set, Func&& func, Container& index)
{
auto set = global_set.template get_local_set<dim>(global_set.level(), index);
auto start_and_stop = global_set.template get_start_and_stop_function<dim>();
auto set = global_set.template get_local_set<dim>(global_set.level(), index);

if constexpr (dim != 1)
{
Expand All @@ -26,15 +25,15 @@ namespace samurai
apply_impl<dim - 1>(std::forward<Set>(global_set), std::forward<Func>(func), index);
}
};
apply(set, start_and_stop, func_int);
apply(set, func_int);
}
else
{
auto func_int = [&](const auto& interval)
{
func(interval, index);
};
apply(set, start_and_stop, func_int);
apply(set, func_int);
}
}
}
Expand All @@ -50,16 +49,16 @@ namespace samurai
}
}

template <class Set, class StartEnd, class Func>
template <class Set, class Func>
requires IsSetOp<Set> || IsIntervalListVisitor<Set>
void apply(Set&& set, StartEnd&& start_and_stop, Func&& func)
void apply(Set&& set, Func&& func)
{
using interval_t = typename std::decay_t<Set>::interval_t;
using value_t = typename interval_t::value_t;

interval_t result;
int r_ipos = 0;
set.next(0, std::forward<StartEnd>(start_and_stop));
set.next(0);
auto scan = set.min();

while (scan < sentinel<value_t> && !set.is_empty())
Expand All @@ -81,7 +80,7 @@ namespace samurai
func(true_result);
}

set.next(scan, std::forward<StartEnd>(start_and_stop));
set.next(scan);
scan = set.min();
}
}
Expand Down
2 changes: 1 addition & 1 deletion include/samurai/subset/concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace samurai

// namespace samurai::experimental
// {
template <class Operator, class... S>
template <class Operator, class StartAndStopOp, class... S>
class SetTraverser;

template <class container_t>
Expand Down
74 changes: 21 additions & 53 deletions include/samurai/subset/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ namespace samurai
public:

static constexpr std::size_t dim = get_set_dim_v<S...>;
using set_type = std::tuple<S...>;
using set_type = std::tuple<std::decay_t<S>...>;
using interval_t = get_interval_t<S...>;

Subset(Op&& op, StartEndOp&& start_end_op, S&&... s)
Subset(Op&& op, StartEndOp&& start_end_op, const S&... s)
: m_operator(std::forward<Op>(op))
, m_start_end_op(std::forward<StartEndOp>(start_end_op))
, m_s(std::forward<S>(s)...)
, m_s(s...)
, m_ref_level(compute_max(s.ref_level()...))
, m_level(compute_max(s.level()...))
, m_dest_level(m_level)
, m_min_level(m_level)
{
std::apply(
Expand All @@ -57,8 +58,8 @@ namespace samurai
{
ref_level(ilevel);
}
m_min_level = std::min(m_min_level, ilevel);
m_level = ilevel;
m_min_level = std::min(m_min_level, ilevel);
m_dest_level = ilevel;
return *this;
}

Expand All @@ -73,22 +74,22 @@ namespace samurai
{
auto func = [&](auto& interval, auto& index)
{
(op(m_level, interval, index), ...);
(op(m_dest_level, interval, index), ...);
};
apply(*this, func);
}

template <std::size_t d, class Func_goback_beg, class Func_goback_end>
auto get_local_set(auto level, auto& index, Func_goback_beg&& goback_fct_beg, Func_goback_end&& goback_fct_end)
{
int shift = static_cast<int>(this->ref_level()) - static_cast<int>(this->level());
m_start_end_op(m_level, m_min_level, m_ref_level);
int shift = static_cast<int>(m_ref_level) - static_cast<int>(m_dest_level);

return std::apply(
[this, &index, shift, level, &goback_fct_beg, &goback_fct_end](auto&&... args)
{
return SetTraverser(shift,
get_operator<d>(m_operator),
m_start_end_op.template get_local_function<d>(m_level, m_min_level, m_ref_level),
args.template get_local_set<d>(
level,
index,
Expand All @@ -104,45 +105,9 @@ namespace samurai
return get_local_set<d>(level, index, default_function_(), default_function_());
}

template <std::size_t d, class Func_start, class Func_end>
auto get_start_and_stop_function(Func_start&& start_fct, Func_end&& end_fct)
{
m_start_end_op(m_level, m_min_level, m_ref_level);

return std::apply(
[this, &start_fct, &end_fct](auto&& arg, auto&&... args)
{
if constexpr (std::is_same_v<Op, DifferenceOp>)
{
return std::make_tuple(std::move(arg.template get_start_and_stop_function<d>(
m_start_end_op.template start<d>(std::forward<Func_start>(start_fct)),
m_start_end_op.template end<d>(std::forward<Func_end>(end_fct)))),
std::move(args.template get_start_and_stop_function<d>(
m_start_end_op.template start<d, true>(std::forward<Func_start>(start_fct)),
m_start_end_op.template end<d, true>(std::forward<Func_end>(end_fct))))...);
}
else
{
return std::make_tuple(std::move(arg.template get_start_and_stop_function<d>(
m_start_end_op.template start<d>(std::forward<Func_start>(start_fct)),
m_start_end_op.template end<d>(std::forward<Func_end>(end_fct)))),
std::move(args.template get_start_and_stop_function<d>(
m_start_end_op.template start<d>(std::forward<Func_start>(start_fct)),
m_start_end_op.template end<d>(std::forward<Func_end>(end_fct))))...);
}
},
m_s);
}

template <std::size_t d>
auto get_start_and_stop_function()
{
return get_start_and_stop_function<d>(default_function(), default_function());
}

auto level() const
{
return m_level;
return m_dest_level;
}

auto ref_level() const
Expand Down Expand Up @@ -178,6 +143,7 @@ namespace samurai
set_type m_s;
std::size_t m_ref_level;
std::size_t m_level;
std::size_t m_dest_level;
std::size_t m_min_level;
};

Expand Down Expand Up @@ -228,6 +194,7 @@ namespace samurai

return IntervalListVisitor(m_lca.level(),
m_level,
m_min_level,
m_ref_level,
IntervalListRange(m_lca[d - 1], 0, static_cast<std::ptrdiff_t>(m_lca[d - 1].size())));
}
Expand All @@ -241,6 +208,7 @@ namespace samurai
auto new_goback_fct_beg = m_func.template goback<d + 1>(std::forward<Func_goback_beg>(goback_fct_beg));

if (level <= m_level && level >= m_lca.level())
// if (level > 500)
{
m_offsets[d - 1].clear();

Expand All @@ -259,6 +227,7 @@ namespace samurai

return IntervalListVisitor(m_lca.level(),
m_level,
m_min_level,
m_ref_level,
IntervalListRange(m_lca[d - 1],
static_cast<std::ptrdiff_t>(offsets[io]),
Expand All @@ -274,6 +243,10 @@ namespace samurai
auto max_index = end_shift(new_goback_fct_end(level, index[d - 1] + 1).second,
static_cast<int>(m_lca.level()) - static_cast<int>(m_level));

// std::cout << "get_local_set: d = " << d << ", min_index = " << min_index << ", max_index = " << max_index
// << " goback_start = " << goback_start << " goback_end = " << new_goback_fct_end(level, index[d - 1] +
// 1).second
// << " level = " << level << " m_level = " << m_level << " lca_level = " << m_lca.level() << std::endl;
m_work[d - 1].clear();
m_offsets[d - 1].clear();

Expand Down Expand Up @@ -301,6 +274,7 @@ namespace samurai

if (start_offset == end_offset)
{
// std::cout << "get_local_set: start_offset == end_offset, returning empty range" << std::endl;
return IntervalListVisitor(IntervalListRange(m_lca[d - 1], 0, 0));
}

Expand Down Expand Up @@ -376,9 +350,10 @@ namespace samurai
}
if (m_work[d - 1].empty())
{
// std::cout << "get_local_set: m_work is empty, returning empty range" << std::endl;
return IntervalListVisitor(IntervalListRange(m_lca[d - 1], 0, 0));
}
return IntervalListVisitor(m_lca.level(), m_level, m_ref_level, IntervalListRange(m_lca[d - 1], m_work[d - 1]));
return IntervalListVisitor(m_lca.level(), m_level, m_min_level, m_ref_level, IntervalListRange(m_lca[d - 1], m_work[d - 1]));
}
}
}
Expand Down Expand Up @@ -509,13 +484,6 @@ namespace samurai
detail::transform(std::forward<set_t>(set)));
}

template <class set_t>
auto contraction(set_t&& set, int c)
{
constexpr std::size_t dim = std::decay_t<set_t>::dim;
return Subset(SelfOp(), start_end_contraction_function<dim>(c), detail::transform(std::forward<set_t>(set)));
}

template <class lca_t>
auto self(lca_t&& lca)
{
Expand Down
Loading
Loading