Skip to content

Commit

Permalink
Finished implementing dense_dbm, major refactorings and revampings
Browse files Browse the repository at this point in the history
- (I'm all over the place here, sorry.)
- (At least I implemented more unit tests!)
  • Loading branch information
flisboac committed Sep 11, 2017
1 parent bae0093 commit f408b89
Show file tree
Hide file tree
Showing 24 changed files with 740 additions and 472 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ target_sources(${api} INTERFACE
"${api_dir_root}/adl/oct/dbm.hpp"
"${api_dir_root}/adl/oct/dbm/traits.hpp"
"${api_dir_root}/adl/oct/dbm/dbm_base_.hpp"
"${api_dir_root}/adl/oct/dbm/dense_dbm.hpp"
"${api_dir_root}/adl/oct/dbm/dense_dbm_base_.hpp"

#adl/oct/cpu
"${api_dir_root}/adl/oct/cpu.hpp"
Expand Down
5 changes: 4 additions & 1 deletion include/adl/crtp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ adl_BEGIN_ROOT_MODULE

template <typename SubClass>
class crtp_base {
public:
friend SubClass;

protected:
using subclass_ = SubClass;

Expand Down Expand Up @@ -50,7 +53,7 @@ constexpr typename crtp_base<SubClass>::subclass_& crtp_base<SubClass>::as_const

template <typename SubClass>
constexpr typename crtp_base<SubClass>::subclass_ const& crtp_base<SubClass>::as_const_() noexcept {
return const_cast<subclass_&>(*this);
return const_cast<subclass_ const&>(*this);
}

template <typename SubClass>
Expand Down
26 changes: 21 additions & 5 deletions include/adl/oct/cons/basic_oct_cons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,16 @@ class basic_oct_cons : public cons_base_<ValueType, VarType> {
typename VarType_,
typename = std::enable_if_t<
common_var<VarType_>::is_oct_space
&& !std::is_same<VarType_, var_type>::value
&& (!std::is_same<VarType_, var_type>::value || !std::is_same<ValueType_, value_type>::value)
&& std::is_convertible<ValueType_, value_type>::value>>
constexpr basic_oct_cons(basic_oct_cons<ValueType_, VarType_> cons);
constexpr basic_oct_cons(basic_oct_cons<ValueType_, VarType_> const& cons);

template <
typename VarType_,
typename = std::enable_if_t<
common_var<VarType_>::is_oct_space
&& !std::is_same<VarType_, var_type>::value>>
explicit constexpr basic_oct_cons(basic_oct_vexpr<VarType_> vexpr);

constexpr basic_oct_cons(var_type xi, value_type c);
constexpr static basic_oct_cons make_upper_limit(var_type xi, value_type c) noexcept; // xi <= c
Expand Down Expand Up @@ -96,6 +103,9 @@ class basic_oct_cons : public cons_base_<ValueType, VarType> {
constexpr octdiff_conjunction_type split() const noexcept;
};

template <typename ValueType> constexpr oct_cons<ValueType> to_identity(oct_cons<ValueType> cons) { return cons; }
template <typename ValueType> constexpr oct_cons<ValueType> to_identity(oct_lcons<ValueType> cons) { return cons.to_identity(); }

template <
typename ValueType,
typename VarType,
Expand Down Expand Up @@ -290,6 +300,7 @@ std::basic_ostream<char, Traits>& operator<<(
// [[ TEMPLATE IMPLEMENTATION ]]
//
#include "adl/oct/cons/basic_octdiff_cons.hpp"
#include "adl/oct/cons/basic_octdiff_conjunction.hpp"

adl_BEGIN_ROOT_MODULE
namespace oct {
Expand All @@ -300,9 +311,14 @@ namespace oct {

template <typename ValueType, typename VarType>
template <typename ValueType_, typename VarType_, typename>
constexpr basic_oct_cons<ValueType, VarType>::basic_oct_cons(basic_oct_cons<ValueType_, VarType_> cons)
constexpr basic_oct_cons<ValueType, VarType>::basic_oct_cons(basic_oct_cons<ValueType_, VarType_> const& cons)
: basic_oct_cons(vexpr_type(var_type(cons.xi()), var_type(cons.xj())), value_type(cons.c())) {};

template <typename ValueType, typename VarType>
template <typename VarType_, typename>
constexpr basic_oct_cons<ValueType, VarType>::basic_oct_cons(basic_oct_vexpr<VarType_> vexpr)
: basic_oct_cons(basic_oct_vexpr<var_type>(vexpr.xi(), vexpr.xj()), value_type()) {};

template <typename ValueType, typename VarType>
constexpr basic_oct_cons<ValueType, VarType>::basic_oct_cons(var_type xi, value_type c) :
superclass_(vexpr_type::make_unit(xi), c) {}
Expand Down Expand Up @@ -398,8 +414,8 @@ basic_oct_cons<ValueType, VarType>::split() const noexcept {
);
}
return octdiff_conjunction_type::from_cons(
octdiff_conjunction_cons_type(octdiff_conjunction_vexpr_type(vexpr.xi(), vexpr.xj()), c_),
octdiff_conjunction_cons_type(octdiff_conjunction_vexpr_type(vexpr.xJ(), vexpr.xI()), constant)
octdiff_conjunction_cons_type(octdiff_conjunction_vexpr_type(vexpr.xi(), vexpr.xJ()), constant),
octdiff_conjunction_cons_type(octdiff_conjunction_vexpr_type(vexpr.xj(), vexpr.xI()), constant)
);
}

Expand Down
8 changes: 4 additions & 4 deletions include/adl/oct/cons/basic_octdiff_conjunction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "adl/oct/var.hpp"
#include "adl/oct/vexpr.hpp"


//
// [[ API ]]
//
Expand Down Expand Up @@ -49,10 +50,9 @@ class basic_octdiff_conjunction {
using identity_vexpr_type = typename var_traits::identity_vexpr_type;

// Cons types
typedef typename var_traits::template cons_type<ValueType> cons_type;
typedef typename var_traits::template counterpart_cons_type<ValueType> counterpart_cons_type; // always basic_oct_cons
typedef typename var_traits::template identity_cons_type<ValueType> identity_cons_type;
typedef typename var_traits::template octdiff_conjunction_type<ValueType> octdiff_conjunction_type;
using cons_type = basic_octdiff_cons<value_type, var_type>;
using counterpart_cons_type = basic_oct_cons<value_type, counterpart_var_type>;
using identity_cons_type = basic_oct_cons<value_type, identity_var_type>;

struct less {
constexpr bool operator()(basic_octdiff_conjunction const& lhs, basic_octdiff_conjunction const& rhs) const noexcept;
Expand Down
33 changes: 28 additions & 5 deletions include/adl/oct/cons/basic_octdiff_cons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,23 @@ class basic_octdiff_cons : public cons_base_<ValueType, VarType> {
constexpr basic_octdiff_cons& operator=(basic_octdiff_cons &&) noexcept = default;

constexpr basic_octdiff_cons(vexpr_type vexpr, value_type c);
constexpr static basic_octdiff_cons make_upper_limit(var_type xi, value_type c) noexcept; // xi <= c
constexpr static basic_octdiff_cons make_upper_limit(vexpr_type vexpr, value_type c) noexcept; // +-xi [+- xj] <= c

template <
typename ValueType_,
typename VarType_,
typename = std::enable_if_t<
common_var<VarType_>::is_octdiff_space
&& !std::is_same<VarType_, var_type>::value
&& (!std::is_same<VarType_, var_type>::value || !std::is_same<ValueType_, value_type>::value)
&& std::is_convertible<ValueType_, value_type>::value>>
constexpr basic_octdiff_cons(basic_octdiff_cons<ValueType_, VarType_> cons);
constexpr basic_octdiff_cons(basic_octdiff_cons<ValueType_, VarType_> cons) noexcept;

template <
typename VarType_,
typename = std::enable_if_t<
common_var<VarType_>::is_octdiff_space
&& !std::is_same<VarType_, var_type>::value>>
explicit constexpr basic_octdiff_cons(basic_octdiff_vexpr<VarType_> vexpr) noexcept;

template <
typename VarType_ = var_type,
Expand All @@ -80,6 +86,9 @@ class basic_octdiff_cons : public cons_base_<ValueType, VarType> {
constexpr basic_octdiff_cons to_commuted() const noexcept;
};

template <typename ValueType> constexpr octdiff_cons<ValueType> to_identity(octdiff_cons<ValueType> cons) { return cons; }
template <typename ValueType> constexpr octdiff_cons<ValueType> to_identity(octdiff_lcons<ValueType> cons) { return cons.to_identity(); }

template <
typename ValueType,
typename VarType,
Expand Down Expand Up @@ -169,6 +178,7 @@ std::basic_ostream<char, Traits>& operator<<(
// [[ TEMPLATE IMPLEMENTATION ]]
//
#include "adl/oct/cons/basic_oct_cons.hpp"
#include "adl/oct/cons/basic_octdiff_conjunction.hpp"

adl_BEGIN_ROOT_MODULE
namespace oct {
Expand All @@ -180,10 +190,23 @@ namespace oct {
template <typename ValueType, typename VarType>
constexpr basic_octdiff_cons<ValueType, VarType>::basic_octdiff_cons(vexpr_type vexpr, value_type c) : superclass_(vexpr, c) {};

template <typename ValueType, typename VarType>
constexpr basic_octdiff_cons<ValueType, VarType>
basic_octdiff_cons<ValueType, VarType>::make_upper_limit(vexpr_type vexpr, value_type c) noexcept {
return basic_octdiff_cons<ValueType, VarType>(vexpr, c);
};

template <typename ValueType, typename VarType>
template <typename ValueType_, typename VarType_, typename>
constexpr basic_octdiff_cons<ValueType, VarType>::basic_octdiff_cons(basic_octdiff_cons<ValueType_, VarType_> cons)
: basic_octdiff_cons(vexpr_type(cons.xi(), cons.xj()), cons.c()) {};
constexpr basic_octdiff_cons<ValueType, VarType>::basic_octdiff_cons(
basic_octdiff_cons<ValueType_, VarType_> cons
) noexcept : basic_octdiff_cons(vexpr_type(cons.xi(), cons.xj()), cons.c()) {};

template <typename ValueType, typename VarType>
template <typename VarType_, typename>
constexpr basic_octdiff_cons<ValueType, VarType>::basic_octdiff_cons(
basic_octdiff_vexpr<VarType_> vexpr
) noexcept : basic_octdiff_cons(vexpr, value_type()) {};

template <typename ValueType, typename VarType>
template <typename VarType_, typename>
Expand Down
29 changes: 15 additions & 14 deletions include/adl/oct/cons/cons_base_.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,22 @@ class cons_base_ {
using counterpart_vexpr_type = typename var_traits::counterpart_vexpr_type;
using identity_vexpr_type = typename var_traits::identity_vexpr_type;

//
// Const-static Variable definitions
//

constexpr static const domain_space space = var_type::space;
constexpr static const domain_space counterpart_space = var_type::counterpart_space;
constexpr static const bool has_unit_cons = vexpr_type::has_unit_vexpr;
constexpr static const bool has_add_cons = vexpr_type::has_add_vexpr;

// Cons types
typedef typename var_traits::template cons_type<ValueType> cons_type;
typedef typename var_traits::template counterpart_cons_type<ValueType> counterpart_cons_type;
typedef typename var_traits::template identity_cons_type<ValueType> identity_cons_type;
typedef typename var_traits::template octdiff_conjunction_type<ValueType> octdiff_conjunction_type;
using octdiff_conjunction_cons_type = typename octdiff_conjunction_type::cons_type;
using octdiff_conjunction_vexpr_type = typename octdiff_conjunction_type::vexpr_type;
using cons_type = typename var_traits::template cons_type<ValueType>;
using counterpart_cons_type = typename var_traits::template counterpart_cons_type<ValueType>;
using identity_cons_type = typename var_traits::template identity_cons_type<ValueType>;
using octdiff_conjunction_type = std::conditional_t<space == domain_space::oct, basic_octdiff_conjunction<value_type, counterpart_var_type>, basic_octdiff_conjunction<value_type, var_type>>;
using octdiff_conjunction_vexpr_type = std::conditional_t<space == domain_space::oct, counterpart_vexpr_type, vexpr_type>;
using octdiff_conjunction_cons_type = std::conditional_t<space == domain_space::oct, counterpart_cons_type, cons_type>;

struct less {
constexpr bool operator()(cons_type const& lhs, cons_type const& rhs) const noexcept;
Expand All @@ -62,14 +71,6 @@ class cons_base_ {
constexpr std::size_t operator()(cons_type const& lhs) const noexcept;
};

//
// Const-static Variable definitions
//

constexpr static const domain_space space = var_type::space;
constexpr static const domain_space counterpart_space = var_type::counterpart_space;
constexpr static const bool has_unit_cons = vexpr_type::has_unit_vexpr;
constexpr static const bool has_add_cons = vexpr_type::has_add_vexpr;

private:
using subclass_ = cons_type;
Expand Down
2 changes: 1 addition & 1 deletion include/adl/oct/cpu/dense_dbm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "adl.cfg.hpp"

#include "adl/oct/dbm/traits.hpp"
#include "adl/oct/dbm/dense_dbm.hpp"
#include "adl/oct/dbm/dense_dbm_base_.hpp"

adl_BEGIN_ROOT_MODULE
namespace oct {
Expand Down
2 changes: 1 addition & 1 deletion include/adl/oct/dbm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

#include "adl/oct/dbm/traits.hpp"
#include "adl/oct/dbm/dbm_base_.hpp"
#include "adl/oct/dbm/dense_dbm.hpp"
#include "adl/oct/dbm/dense_dbm_base_.hpp"

#endif //adl__oct__dbm__hpp__
9 changes: 3 additions & 6 deletions include/adl/oct/dbm/dbm_base_.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class dbm_base_ : public dbm_types_<ValueType, ValueLimits>, public crtp_base<Su

protected:
template <typename VarType_, typename = common_var_t<VarType_>>
constexpr static std::size_t to_end_index_(VarType_ var) noexcept;
constexpr static std::size_t to_end_index_(VarType_ last_var) noexcept;

public:
using typename superclass_::identity_var_type;
Expand Down Expand Up @@ -52,11 +52,8 @@ namespace oct {

template <typename SubClass, typename ValueType, typename ValueLimits>
template <typename VarType_, typename>
constexpr std::size_t dbm_base_<SubClass, ValueType, ValueLimits>::to_end_index_(VarType_ var) noexcept {
auto diff_var = to_octdiff(var);
return diff_var.positive() // Goes to the next positive (that is the end variable if negative-coerced var is the last)
? diff_var.to_incremented(2).to_index() // Var is positive, needs 2 increments in octdiff space instead of one
: diff_var.to_incremented().to_index();
constexpr std::size_t dbm_base_<SubClass, ValueType, ValueLimits>::to_end_index_(VarType_ last_var) noexcept {
return to_octdiff(last_var).normalize().increment(2).to_index();
};

template <typename SubClass, typename ValueType, typename ValueLimits>
Expand Down
Loading

0 comments on commit f408b89

Please sign in to comment.