Skip to content

Commit

Permalink
GTSAM_CONCEPT_ASSERT to replace BOOST equivalent.
Browse files Browse the repository at this point in the history
  • Loading branch information
dellaert committed Feb 6, 2023
1 parent a38d76b commit eb37866
Show file tree
Hide file tree
Showing 34 changed files with 147 additions and 144 deletions.
2 changes: 1 addition & 1 deletion GTSAM-Concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ Concept Checks

Boost provides a nice way to check whether a given type satisfies a concept. For example, the following

BOOST_CONCEPT_ASSERT(IsVectorSpace<Point2>)
GTSAM_CONCEPT_ASSERT(IsVectorSpace<Point2>)

asserts that Point2 indeed is a model for the VectorSpace concept.

Expand Down
2 changes: 1 addition & 1 deletion gtsam/base/FastSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ template<typename VALUE>
class FastSet: public std::set<VALUE, std::less<VALUE>,
typename internal::FastDefaultAllocator<VALUE>::type> {

BOOST_CONCEPT_ASSERT ((IsTestable<VALUE> ));
GTSAM_CONCEPT_ASSERT(IsTestable<VALUE>);

public:

Expand Down
16 changes: 8 additions & 8 deletions gtsam/base/Group.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class IsGroup {
typedef typename traits<G>::group_flavor flavor_tag;
//typedef typename traits<G>::identity::value_type identity_value_type;

BOOST_CONCEPT_USAGE(IsGroup) {
BOOST_STATIC_ASSERT_MSG(
GTSAM_CONCEPT_USAGE(IsGroup) {
static_assert(
(std::is_base_of<group_tag, structure_category_tag>::value),
"This type's structure_category trait does not assert it as a group (or derived)");
e = traits<G>::Identity();
Expand Down Expand Up @@ -82,7 +82,7 @@ class IsGroup {

/// Check invariants
template<typename G>
BOOST_CONCEPT_REQUIRES(((IsGroup<G>)),(bool)) //
GTSAM_CONCEPT_REQUIRES(IsGroup<G>,bool) //
check_group_invariants(const G& a, const G& b, double tol = 1e-9) {
G e = traits<G>::Identity();
return traits<G>::Equals(traits<G>::Compose(a, traits<G>::Inverse(a)), e, tol)
Expand Down Expand Up @@ -128,7 +128,7 @@ struct AdditiveGroup : AdditiveGroupTraits<Class>, Testable<Class> {};

/// compose multiple times
template<typename G>
BOOST_CONCEPT_REQUIRES(((IsGroup<G>)),(G)) //
GTSAM_CONCEPT_REQUIRES(IsGroup<G>,G) //
compose_pow(const G& g, size_t n) {
if (n == 0) return traits<G>::Identity();
else if (n == 1) return g;
Expand All @@ -139,8 +139,8 @@ compose_pow(const G& g, size_t n) {
/// Assumes nothing except group structure and Testable from G and H
template<typename G, typename H>
class DirectProduct: public std::pair<G, H> {
BOOST_CONCEPT_ASSERT((IsGroup<G>));
BOOST_CONCEPT_ASSERT((IsGroup<H>));
GTSAM_CONCEPT_ASSERT1(IsGroup<G>);
GTSAM_CONCEPT_ASSERT2(IsGroup<H>);

public:
/// Default constructor yields identity
Expand Down Expand Up @@ -170,8 +170,8 @@ struct traits<DirectProduct<G, H> > :
/// Assumes existence of three additive operators for both groups
template<typename G, typename H>
class DirectSum: public std::pair<G, H> {
BOOST_CONCEPT_ASSERT((IsGroup<G>)); // TODO(frank): check additive
BOOST_CONCEPT_ASSERT((IsGroup<H>)); // TODO(frank): check additive
GTSAM_CONCEPT_ASSERT1(IsGroup<G>); // TODO(frank): check additive
GTSAM_CONCEPT_ASSERT2(IsGroup<H>); // TODO(frank): check additive

const G& g() const { return this->first; }
const H& h() const { return this->second;}
Expand Down
4 changes: 2 additions & 2 deletions gtsam/base/Lie.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ class IsLieGroup: public IsGroup<T>, public IsManifold<T> {
typedef typename traits<T>::TangentVector TangentVector;
typedef typename traits<T>::ChartJacobian ChartJacobian;

BOOST_CONCEPT_USAGE(IsLieGroup) {
BOOST_STATIC_ASSERT_MSG(
GTSAM_CONCEPT_USAGE(IsLieGroup) {
static_assert(
(std::is_base_of<lie_group_tag, structure_category_tag>::value),
"This type's trait does not assert it is a Lie group (or derived)");

Expand Down
21 changes: 8 additions & 13 deletions gtsam/base/Manifold.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@
#include <gtsam/base/Matrix.h>
#include <gtsam/base/Testable.h>
#include <gtsam/base/OptionalJacobian.h>

#ifdef GTSAM_USE_BOOST_FEATURES
#include <boost/concept_check.hpp>
#include <boost/concept/requires.hpp>
#include <boost/type_traits/is_base_of.hpp>
#endif
#include <gtsam/base/concepts.h>

namespace gtsam {

Expand Down Expand Up @@ -66,7 +61,7 @@ struct HasManifoldPrereqs {
Eigen::Matrix<double, dim, 1> v;
OptionalJacobian<dim, dim> Hp, Hq, Hv;

BOOST_CONCEPT_USAGE(HasManifoldPrereqs) {
GTSAM_CONCEPT_USAGE(HasManifoldPrereqs) {
v = p.localCoordinates(q);
q = p.retract(v);
}
Expand Down Expand Up @@ -97,7 +92,7 @@ template<class Class>
struct ManifoldTraits: GetDimensionImpl<Class, Class::dimension> {

// Check that Class has the necessary machinery
BOOST_CONCEPT_ASSERT((HasManifoldPrereqs<Class>));
GTSAM_CONCEPT_ASSERT(HasManifoldPrereqs<Class>);

// Dimension of the manifold
enum { dimension = Class::dimension };
Expand Down Expand Up @@ -125,7 +120,7 @@ template<class Class> struct Manifold: ManifoldTraits<Class>, Testable<Class> {}

/// Check invariants for Manifold type
template<typename T>
BOOST_CONCEPT_REQUIRES(((IsTestable<T>)),(bool)) //
GTSAM_CONCEPT_REQUIRES(IsTestable<T>, bool) //
check_manifold_invariants(const T& a, const T& b, double tol=1e-9) {
typename traits<T>::TangentVector v0 = traits<T>::Local(a,a);
typename traits<T>::TangentVector v = traits<T>::Local(a,b);
Expand All @@ -144,11 +139,11 @@ class IsManifold {
typedef typename traits<T>::ManifoldType ManifoldType;
typedef typename traits<T>::TangentVector TangentVector;

BOOST_CONCEPT_USAGE(IsManifold) {
BOOST_STATIC_ASSERT_MSG(
GTSAM_CONCEPT_USAGE(IsManifold) {
static_assert(
(std::is_base_of<manifold_tag, structure_category_tag>::value),
"This type's structure_category trait does not assert it as a manifold (or derived)");
BOOST_STATIC_ASSERT(TangentVector::SizeAtCompileTime == dim);
static_assert(TangentVector::SizeAtCompileTime == dim);

// make sure Chart methods are defined
v = traits<T>::Local(p, q);
Expand All @@ -166,7 +161,7 @@ template<typename T>
struct FixedDimension {
typedef const int value_type;
static const int value = traits<T>::dimension;
BOOST_STATIC_ASSERT_MSG(value != Eigen::Dynamic,
static_assert(value != Eigen::Dynamic,
"FixedDimension instantiated for dymanically-sized type.");
};
} // \ namespace gtsam
Expand Down
4 changes: 2 additions & 2 deletions gtsam/base/ProductLieGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ namespace gtsam {
/// Assumes Lie group structure for G and H
template<typename G, typename H>
class ProductLieGroup: public std::pair<G, H> {
BOOST_CONCEPT_ASSERT((IsLieGroup<G>));
BOOST_CONCEPT_ASSERT((IsLieGroup<H>));
GTSAM_CONCEPT_ASSERT1(IsLieGroup<G>);
GTSAM_CONCEPT_ASSERT2(IsLieGroup<H>);
typedef std::pair<G, H> Base;

protected:
Expand Down
12 changes: 5 additions & 7 deletions gtsam/base/Testable.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@

#pragma once

#ifdef GTSAM_USE_BOOST_FEATURES
#include <boost/concept_check.hpp>
#endif
#include <gtsam/base/concepts.h>

#include <functional>
#include <iostream>
Expand Down Expand Up @@ -63,7 +61,7 @@ namespace gtsam {
bool r1,r2;
public:

BOOST_CONCEPT_USAGE(IsTestable) {
GTSAM_CONCEPT_USAGE(IsTestable) {
// check print function, with optional string
traits<T>::Print(t, std::string());
traits<T>::Print(t);
Expand Down Expand Up @@ -136,7 +134,7 @@ namespace gtsam {
template<typename T>
struct HasTestablePrereqs {

BOOST_CONCEPT_USAGE(HasTestablePrereqs) {
GTSAM_CONCEPT_USAGE(HasTestablePrereqs) {
t->print(str);
b = t->equals(*s,tol);
}
Expand All @@ -154,7 +152,7 @@ namespace gtsam {
struct Testable {

// Check that T has the necessary methods
BOOST_CONCEPT_ASSERT((HasTestablePrereqs<T>));
GTSAM_CONCEPT_ASSERT(HasTestablePrereqs<T>);

static void Print(const T& m, const std::string& str = "") {
m.print(str);
Expand All @@ -173,7 +171,7 @@ namespace gtsam {
*
* NOTE: intentionally not in the gtsam namespace to allow for classes not in
* the gtsam namespace to be more easily enforced as testable
* @deprecated please use BOOST_CONCEPT_ASSERT and
* @deprecated please use GTSAM_CONCEPT_ASSERT and
*/
#define GTSAM_CONCEPT_TESTABLE_INST(T) template class gtsam::IsTestable<T>;
#define GTSAM_CONCEPT_TESTABLE_TYPE(T) using _gtsam_Testable_##T = gtsam::IsTestable<T>;
8 changes: 4 additions & 4 deletions gtsam/base/VectorSpace.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ struct HasVectorSpacePrereqs {
Class p, q;
Vector v;

BOOST_CONCEPT_USAGE(HasVectorSpacePrereqs) {
GTSAM_CONCEPT_USAGE(HasVectorSpacePrereqs) {
p = Class::Identity(); // identity
q = p + p; // addition
q = p - p; // subtraction
Expand All @@ -185,7 +185,7 @@ template<class Class>
struct VectorSpaceTraits: VectorSpaceImpl<Class, Class::dimension> {

// Check that Class has the necessary machinery
BOOST_CONCEPT_ASSERT((HasVectorSpacePrereqs<Class>));
GTSAM_CONCEPT_ASSERT(HasVectorSpacePrereqs<Class>);

typedef vector_space_tag structure_category;

Expand Down Expand Up @@ -472,8 +472,8 @@ class IsVectorSpace: public IsLieGroup<T> {

typedef typename traits<T>::structure_category structure_category_tag;

BOOST_CONCEPT_USAGE(IsVectorSpace) {
BOOST_STATIC_ASSERT_MSG(
GTSAM_CONCEPT_USAGE(IsVectorSpace) {
static_assert(
(std::is_base_of<vector_space_tag, structure_category_tag>::value),
"This type's trait does not assert it as a vector space (or derived)");
r = p + q;
Expand Down
2 changes: 1 addition & 1 deletion gtsam/base/chartTesting.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void testDefaultChart(TestResult& result_,

// First, check the basic chart concept. This checks that the interface is satisfied.
// The rest of the function is even more detailed, checking the correctness of the chart.
BOOST_CONCEPT_ASSERT((ChartConcept<Chart>));
GTSAM_CONCEPT_ASSERT(ChartConcept<Chart>);

T other = value;

Expand Down
38 changes: 16 additions & 22 deletions gtsam/base/concepts.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,22 @@

#pragma once

// This is a helper to ease the transition to the new traits defined in this file.
// Uncomment this if you want all methods that are tagged as not implemented
// to cause compilation errors.
#ifdef COMPILE_ERROR_NOT_IMPLEMENTED

#ifdef GTSAM_USE_BOOST_FEATURES
#include <boost/static_assert.hpp>
#endif

#define CONCEPT_NOT_IMPLEMENTED BOOST_STATIC_ASSERT_MSG(boost::false_type, \
"This method is required by the new concepts framework but has not been implemented yet.");

#else

#include <exception>
#define CONCEPT_NOT_IMPLEMENTED \
throw std::runtime_error("This method is required by the new concepts framework but has not been implemented yet.");

#include <boost/concept_check.hpp>
#define GTSAM_CONCEPT_USAGE(concept) BOOST_CONCEPT_USAGE((concept))
#define GTSAM_CONCEPT_ASSERT(concept) BOOST_CONCEPT_ASSERT((concept))
#define GTSAM_CONCEPT_ASSERT1(concept) BOOST_CONCEPT_ASSERT((concept))
#define GTSAM_CONCEPT_ASSERT2(concept) BOOST_CONCEPT_ASSERT((concept))
#define GTSAM_CONCEPT_ASSERT3(concept) BOOST_CONCEPT_ASSERT((concept))
#define GTSAM_CONCEPT_REQUIRES(concept, return_type) BOOST_CONCEPT_REQUIRES((concept), (return_type))
#else
// These do something sensible:
#define GTSAM_CONCEPT_USAGE(concept) void check##concept()
#define GTSAM_CONCEPT_ASSERT(concept) concept checkConcept [[maybe_unused]];
#define GTSAM_CONCEPT_ASSERT1(concept) concept checkConcept1 [[maybe_unused]];
#define GTSAM_CONCEPT_ASSERT2(concept) concept checkConcept2 [[maybe_unused]];
#define GTSAM_CONCEPT_ASSERT3(concept) concept checkConcept3 [[maybe_unused]];
// This one just ignores concept for now:
#define GTSAM_CONCEPT_REQUIRES(concept, return_type) return_type
#endif

namespace gtsam {

template <typename T> struct traits;

}
6 changes: 3 additions & 3 deletions gtsam/base/tests/testGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ using namespace gtsam;
typedef Symmetric<2> S2;
TEST(Group, S2) {
S2 e, s1 = S2::Transposition(0, 1);
BOOST_CONCEPT_ASSERT((IsGroup<S2>));
GTSAM_CONCEPT_ASSERT(IsGroup<S2>);
EXPECT(check_group_invariants(e, s1));
}

//******************************************************************************
typedef Symmetric<3> S3;
TEST(Group, S3) {
S3 e, s1 = S3::Transposition(0, 1), s2 = S3::Transposition(1, 2);
BOOST_CONCEPT_ASSERT((IsGroup<S3>));
GTSAM_CONCEPT_ASSERT(IsGroup<S3>);
EXPECT(check_group_invariants(e, s1));
EXPECT(assert_equal(s1, s1 * e));
EXPECT(assert_equal(s1, e * s1));
Expand Down Expand Up @@ -127,7 +127,7 @@ struct traits<Dih6> : internal::MultiplicativeGroupTraits<Dih6> {
TEST(Group, Dih6) {
Dih6 e, g(S2::Transposition(0, 1),
S3::Transposition(0, 1) * S3::Transposition(1, 2));
BOOST_CONCEPT_ASSERT((IsGroup<Dih6>));
GTSAM_CONCEPT_ASSERT(IsGroup<Dih6>);
EXPECT(check_group_invariants(e, g));
EXPECT(assert_equal(e, compose_pow(g, 0)));
EXPECT(assert_equal(g, compose_pow(g, 1)));
Expand Down
31 changes: 22 additions & 9 deletions gtsam/base/tests/testMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1146,17 +1146,30 @@ TEST(Matrix, DLT )
}

//******************************************************************************
TEST(Matrix , IsVectorSpace) {
BOOST_CONCEPT_ASSERT((IsVectorSpace<Matrix24>));
typedef Eigen::Matrix<double,2,3,Eigen::RowMajor> RowMajor;
BOOST_CONCEPT_ASSERT((IsVectorSpace<RowMajor>));
BOOST_CONCEPT_ASSERT((IsVectorSpace<Matrix>));
BOOST_CONCEPT_ASSERT((IsVectorSpace<Vector>));
typedef Eigen::Matrix<double,1,-1> RowVector;
BOOST_CONCEPT_ASSERT((IsVectorSpace<RowVector>));
BOOST_CONCEPT_ASSERT((IsVectorSpace<Vector5>));
TEST(Matrix, Matrix24IsVectorSpace) {
GTSAM_CONCEPT_ASSERT(IsVectorSpace<Matrix24>);
}

TEST(Matrix, RowMajorIsVectorSpace) {
typedef Eigen::Matrix<double, 2, 3, Eigen::RowMajor> RowMajor;
GTSAM_CONCEPT_ASSERT(IsVectorSpace<RowMajor>);
}

TEST(Matrix, MatrixIsVectorSpace) {
GTSAM_CONCEPT_ASSERT(IsVectorSpace<Matrix>);
}

TEST(Matrix, VectorIsVectorSpace) {
GTSAM_CONCEPT_ASSERT(IsVectorSpace<Vector>);
}

TEST(Matrix, RowVectorIsVectorSpace) {
typedef Eigen::Matrix<double, 1, -1> RowVector;
GTSAM_CONCEPT_ASSERT1(IsVectorSpace<RowVector>);
GTSAM_CONCEPT_ASSERT2(IsVectorSpace<Vector5>);
}

//******************************************************************************
TEST(Matrix, AbsoluteError) {
double a = 2000, b = 1997, tol = 1e-1;
bool isEqual;
Expand Down
11 changes: 7 additions & 4 deletions gtsam/base/tests/testVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,14 @@ TEST(Vector, linear_dependent3 )
}

//******************************************************************************
TEST(Vector, IsVectorSpace) {
BOOST_CONCEPT_ASSERT((IsVectorSpace<Vector5>));
BOOST_CONCEPT_ASSERT((IsVectorSpace<Vector>));
TEST(Vector, VectorIsVectorSpace) {
GTSAM_CONCEPT_ASSERT1(IsVectorSpace<Vector5>);
GTSAM_CONCEPT_ASSERT2(IsVectorSpace<Vector>);
}

TEST(Vector, RowVectorIsVectorSpace) {
typedef Eigen::Matrix<double,1,-1> RowVector;
BOOST_CONCEPT_ASSERT((IsVectorSpace<RowVector>));
GTSAM_CONCEPT_ASSERT(IsVectorSpace<RowVector>);
}

/* ************************************************************************* */
Expand Down
4 changes: 2 additions & 2 deletions gtsam/geometry/tests/testBearingRange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ BearingRange3D br3D(Pose3().bearing(Point3(1, 0, 0)), 1);

//******************************************************************************
TEST(BearingRange2D, Concept) {
BOOST_CONCEPT_ASSERT((IsManifold<BearingRange2D>));
GTSAM_CONCEPT_ASSERT(IsManifold<BearingRange2D>);
}

/* ************************************************************************* */
Expand All @@ -46,7 +46,7 @@ TEST(BearingRange, 2D) {

//******************************************************************************
TEST(BearingRange3D, Concept) {
BOOST_CONCEPT_ASSERT((IsManifold<BearingRange3D>));
GTSAM_CONCEPT_ASSERT(IsManifold<BearingRange3D>);
}

/* ************************************************************************* */
Expand Down
Loading

0 comments on commit eb37866

Please sign in to comment.