Skip to content

Commit

Permalink
Disable unused sparse lmpar that causes trouble with newer GCCs; add …
Browse files Browse the repository at this point in the history
…CMakePresets (#43)
  • Loading branch information
pettni committed Aug 13, 2023
1 parent b660615 commit 4ade2d6
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 134 deletions.
87 changes: 8 additions & 79 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ jobs:

strategy:
fail-fast: false
matrix:
build_type: [Debug, Release]

steps:
- uses: actions/checkout@v2
Expand All @@ -23,21 +21,15 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
lcov \
libboost-dev \
libgtest-dev
- name: Install Eigen 3.4
run: |
git clone --branch 3.4.0 https://gitlab.com/libeigen/eigen.git ${{ github.workspace }}/deps/eigen
cmake \
-S ${{ github.workspace }}/deps/eigen \
-B ${{ github.workspace }}/deps/eigen/build
cmake --build ${{ github.workspace }}/deps/eigen/build
sudo cmake --install ${{ github.workspace }}/deps/eigen/build
libeigen3-dev \
libgtest-dev \
ninja-build
- name: Install autodiff
run: |
git clone --branch v0.6.8 https://github.com/autodiff/autodiff.git ${{ github.workspace }}/deps/autodiff
git clone --branch v1.0.3 https://github.com/autodiff/autodiff.git ${{ github.workspace }}/deps/autodiff
cmake \
-S ${{ github.workspace }}/deps/autodiff \
-B ${{ github.workspace }}/deps/autodiff/build \
Expand All @@ -47,72 +39,9 @@ jobs:
cmake --build ${{ github.workspace }}/deps/autodiff/build
sudo cmake --install ${{ github.workspace }}/deps/autodiff/build
- name: Configure CMake
run: |
cmake -B ${{ github.workspace }}/build \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DBUILD_TESTS=ON \
-DBUILD_EXAMPLES=ON
- name: Build
working-directory: ${{ github.workspace }}/build
run: make -j2

- name: Test
working-directory: ${{ github.workspace }}/build
run: make test

codecov:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v2

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
lcov \
libboost-dev \
libgtest-dev
- name: Install Eigen 3.4
run: |
git clone --branch 3.4.0 https://gitlab.com/libeigen/eigen.git ${{ github.workspace }}/deps/eigen
cmake \
-S ${{ github.workspace }}/deps/eigen \
-B ${{ github.workspace }}/deps/eigen/build
cmake --build ${{ github.workspace }}/deps/eigen/build
sudo cmake --install ${{ github.workspace }}/deps/eigen/build
- name: Install autodiff
run: |
git clone --branch v0.6.8 https://github.com/autodiff/autodiff.git ${{ github.workspace }}/deps/autodiff
cmake \
-S ${{ github.workspace }}/deps/autodiff \
-B ${{ github.workspace }}/deps/autodiff/build \
-DAUTODIFF_BUILD_EXAMPLES=OFF \
-DAUTODIFF_BUILD_TESTS=OFF \
-DAUTODIFF_BUILD_PYTHON=OFF
cmake --build ${{ github.workspace }}/deps/autodiff/build
sudo cmake --install ${{ github.workspace }}/deps/autodiff/build
- name: Configure CMake
run: |
cmake -B ${{ github.workspace }}/build \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_FLAGS="-O0 -g --coverage -fno-inline" \
-DCMAKE_EXE_LINKER_FLAGS="--coverage" \
-DBUILD_TESTS=ON \
-DBUILD_EXAMPLES=OFF
- name: Build
working-directory: ${{ github.workspace }}/build
run: make -j2

- name: Test
working-directory: ${{ github.workspace }}/build
run: make test
- name: Run cmake workflow
working-directory: ${{ github.workspace }}
run: cmake --workflow --preset ci

- name: Analyze coverage
working-directory: ${{ github.workspace }}
Expand Down
92 changes: 92 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 25,
"patch": 0
},
"configurePresets": [
{
"name": "default",
"displayName": "Ninja Multi-Config",
"description": "Default build using Ninja generator",
"generator": "Ninja Multi-Config",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_CONFIGURATION_TYPES": "Release;Debug",
"BUILD_TESTS": "ON",
"BUILD_EXAMPLES": "ON",
"ENABLE_TEST_COVERAGE": "ON",
"ENABLE_TEST_SANITIZERS": "OFF"
},
"environment": {},
"vendor": {}
}
],
"buildPresets": [
{
"name": "default",
"configurePreset": "default"
},
{
"name": "debug",
"inherits": "default",
"configuration": "Debug"
}
],
"testPresets": [
{
"name": "default",
"configurePreset": "default",
"output": {
"outputOnFailure": true
},
"execution": {
"noTestsAction": "error",
"stopOnFailure": true
}
},
{
"name": "debug",
"inherits": "default",
"configuration": "Debug"
}
],
"packagePresets": [
{
"name": "default",
"configurePreset": "default",
"generators": [
"TGZ"
]
}
],
"workflowPresets": [
{
"name": "ci",
"steps": [
{
"type": "configure",
"name": "default"
},
{
"type": "build",
"name": "debug"
},
{
"type": "test",
"name": "debug"
},
{
"type": "build",
"name": "default"
},
{
"type": "test",
"name": "default"
}
]
}
]
}

8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
* Compatible with: autodiff, boost::numeric::odeint, Ceres, ROS
* Written in an extensible functional programming style

*This project is currently being developed---breaking changes and bugs should be expected.
If you are looking for something stable and established, check out
[manif][manif-link] and [Sophus][sophus-link].*

In robotics it is often convenient to work in non-Euclidean manifolds.
[Lie groups](https://en.wikipedia.org/wiki/Lie_group) are a class of manifolds that are
easy to work with due to their symmetries, and that are also good models for many robotic
Expand All @@ -38,8 +34,6 @@ The following common Lie groups are implemented:
* A smooth::Bundle type to treat Lie group products ![](https://latex.codecogs.com/png.latex?G&space;=&space;G_1&space;\times&space;\ldots&space;\times&space;G_n) as a single Lie group. The Bundle type also supports regular Eigen vectors as ![](https://latex.codecogs.com/png.latex?\mathbb{R}^n\cong\mathbb{T}(n)) components
* Lie group interfaces for Eigen vectors and builtin scalars

The guiding principles for `smooth` are **brevity, reliability and compatability**.


# Getting started

Expand All @@ -53,7 +47,7 @@ mkdir build && cd build

# Specify a C++20-compatible compiler if your default does not support C++20.
# Build tests and/or examples as desired.
cmake .. -DCMAKE_CXX_COMPILER=/usr/bin/g++-10 -DBUILD_EXAMPLES=OFF -DBUILD_TESTS=OFF
cmake .. -DBUILD_EXAMPLES=OFF -DBUILD_TESTS=OFF
make -j8
sudo make install
```
Expand Down
11 changes: 10 additions & 1 deletion include/smooth/compat/ceres.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@

#define SMOOTH_DIFF_CERES

#include "smooth/detail/wrt_impl.hpp"
#include "smooth/lie_group_base.hpp"
#include "smooth/manifolds.hpp"
#include "smooth/map.hpp"
#include "smooth/wrt.hpp"

namespace smooth {

// mark Jet as a valid scalar
template<typename T, int I>
struct detail::scalar_trait<ceres::Jet<T, I>>
{
static constexpr bool value = true;
};

// \cond
template<Manifold G>
struct CeresParamFunctor
Expand Down Expand Up @@ -84,6 +92,7 @@ auto dr_ceres(auto && f, auto && x)
Eigen::Matrix<Scalar, Nx, 1> a = Eigen::Matrix<Scalar, Nx, 1>::Zero(nx);
Eigen::Matrix<Scalar, Ny, 1> b(ny);
Eigen::Matrix<Scalar, Ny, Nx, (Nx == 1) ? Eigen::ColMajor : Eigen::RowMajor> jac(ny, nx);
jac.setZero();

const auto f_deriv = [&]<typename T>(const T * in, T * out) {
Eigen::Map<const Eigen::Matrix<T, Nx, 1>> mi(in, nx);
Expand Down
3 changes: 2 additions & 1 deletion include/smooth/detail/lmpar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ solve_ls(auto & R, const Eigen::Vector<double, N> & Qt_r, const auto & P, const
for (; rank != n && R.coeff(rank, rank) >= Eigen::NumTraits<double>::dummy_precision(); ++rank) {}

Eigen::Vector<double, N> sol(n);
sol.tail(n - rank).setZero();
sol.setZero();
sol.head(rank) = R.topLeftCorner(rank, rank).template triangularView<Eigen::Upper>().solve(a.head(rank));

// solution is now equal to -P z
Expand Down Expand Up @@ -190,6 +190,7 @@ lmpar(const auto & J, const Eigen::Vector<double, N> & d, const Eigen::Vector<do
using MatrixT = std::decay_t<decltype(J)>;

static constexpr bool is_sparse = std::is_base_of_v<Eigen::SparseMatrixBase<MatrixT>, MatrixT>;
static_assert(!is_sparse, "Use lmpar_sparse");

static constexpr int NM_min = std::min(N, M);
static constexpr int NM_rest = NM_min == -1 ? -1 : N - NM_min;
Expand Down
1 change: 1 addition & 0 deletions include/smooth/detail/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <array>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <numeric>
#include <ranges>
Expand Down
37 changes: 27 additions & 10 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
option(ENABLE_TEST_COVERAGE "Enable code coverage for debug build" OFF)
message(STATUS "ENABLE_TEST_COVERAGE set to: ${ENABLE_TEST_COVERAGE}")

option(ENABLE_TEST_SANITIZERS "Enable santitzers for debug build" OFF)
message(STATUS "ENABLE_TEST_SANITIZERS set to: ${ENABLE_TEST_SANITIZERS}")

include(GoogleTest)
find_package(GTest REQUIRED)

Expand All @@ -10,25 +16,36 @@ add_library(TestConfig INTERFACE)
target_compile_options(
TestConfig
INTERFACE -Wall
-Wcast-align
-Wconversion
-Wdouble-promotion
-Werror
-Wextra
-Wshadow
-Wimplicit-fallthrough
-Wnon-virtual-dtor
-Wnull-dereference
-Wold-style-cast
-Wcast-align
-Wunused
-Woverloaded-virtual
-Wpedantic
-Wconversion
-Wshadow
-Wsign-conversion
-Wnull-dereference
-Wdouble-promotion
-Wimplicit-fallthrough
-Werror
-Wunused
-fdiagnostics-color=always
)
target_link_libraries(
TestConfig INTERFACE smooth GTest::Main -fsanitize=undefined,address
)

if (ENABLE_TEST_COVERAGE)
target_compile_options(TestConfig INTERFACE $<$<CONFIG:Debug>:--coverage>)
target_link_libraries(TestConfig INTERFACE $<$<CONFIG:Debug>:--coverage>)
endif()

if (ENABLE_TEST_SANITIZERS)
target_compile_options(TestConfig INTERFACE $<$<CONFIG:Debug>:-fsanitize=undefined,address>)
target_link_options(TestConfig INTERFACE $<$<CONFIG:Debug>:-fsanitize=undefined,address>)
endif()

# CORE TESTS

add_executable(test_utils test_utils.cpp)
Expand Down Expand Up @@ -145,7 +162,7 @@ gtest_discover_tests(test_sparse)

find_package(Boost QUIET)
find_package(Ceres 2.1 QUIET)
find_package(autodiff 0.6 QUIET)
find_package(autodiff QUIET)
find_package(geometry_msgs QUIET)

if(autodiff_FOUND)
Expand Down Expand Up @@ -192,7 +209,7 @@ if(geometry_msgs_FOUND)
test_ros PRIVATE TestConfig
geometry_msgs::geometry_msgs__rosidl_typesupport_cpp
)
gtest_discover_tests(test_ros)
gtest_discover_tests(test_ros)
else()
message(WARNING "geometry_msgs not found, disabling ros test")
endif()

0 comments on commit 4ade2d6

Please sign in to comment.