Skip to content

Commit

Permalink
[format] add standard format support
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancoisCarouge committed Jul 28, 2022
1 parent 3295328 commit bb9d8e4
Show file tree
Hide file tree
Showing 15 changed files with 403 additions and 64 deletions.
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Checks: '*,
-altera-struct-pack-align,
-fuchsia-overloaded-operator,
-fuchsia-trailing-return,
-llvmlibc-callee-namespace,
-llvmlibc-implementation-in-namespace,
-llvmlibc-restrict-system-libc-headers,
-portability-simd-intrinsics,
Expand Down
25 changes: 18 additions & 7 deletions .github/workflows/deploy_test_coverage_coveralls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,27 @@ jobs:
- name: Install
run: |
sudo apt install gcc-11 g++-11 lcov
( cd /tmp ; mkdir eigen ;
( cd /tmp ;
git clone --depth 1 https://gitlab.com/libeigen/eigen.git ;
( cd eigen ;
mkdir build ) ;
( cd eigen/build ;
cmake .. ;
cmake --build . ;
sudo make install ) )
mkdir build ;
( cd build ;
cmake .. ;
cmake --build . ;
sudo make install ; ) ) )
( cd /tmp ;
git clone --depth 1 https://github.com/fmtlib/fmt.git ;
( cd fmt ;
mkdir build ;
( cd build ;
cmake .. ;
sudo make install ; ) ) )
- name: Build
run: gcc-11 sample/*.cpp source/*.cpp test/*.cpp -Iinclude -I/usr/local/include/eigen3 -O0 -g -std=c++23 -fmodules-ts --coverage -fno-inline -lstdc++ -lm
run: |
gcc-11 \
sample/*.cpp source/*.cpp test/*.cpp \
-Iinclude -I/usr/local/include/eigen3 -Isupport/include/fcarouge \
-O0 -g -std=c++23 -fmodules-ts --coverage -fno-inline -lstdc++ -lm -lfmt
- name: "Coverage: Base"
run: |
lcov --rc lcov_branch_coverage=1 --gcov-tool gcov-11 --capture --initial --directory . --output-file base.info
Expand Down
24 changes: 17 additions & 7 deletions .github/workflows/verify_code_static_analysis_tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,27 @@ jobs:
- name: Install
run: |
sudo apt install clang-tidy-14
( cd /tmp ; mkdir eigen ;
( cd /tmp ;
git clone --depth 1 https://gitlab.com/libeigen/eigen.git ;
( cd eigen ;
mkdir build ) ;
( cd eigen/build ;
cmake .. ;
cmake --build . ;
sudo make install ) )
mkdir build ;
( cd build ;
cmake .. ;
cmake --build . ;
sudo make install ; ) ) )
( cd /tmp ;
git clone --depth 1 https://github.com/fmtlib/fmt.git ;
( cd fmt ;
mkdir build ;
( cd build ;
CXX=clang++-14 cmake -DFMT_HEADER_ONLY=TRUE .. ;
sudo make install ; ) ) )
- name: Tidy
run: |
FILES=`find . -iname *.hpp`
clang-tidy-14 ${FILES} \
--warnings-as-errors=* \
-- -x c++ -Wall -Wextra -pedantic -std=c++2b -Iinclude -I/usr/local/include/eigen3
-- -x c++ \
-Iinclude -I/usr/local/include/eigen3 -Isupport/include/fcarouge \
-DFMT_HEADER_ONLY \
-Wall -Wextra -pedantic -std=c++2b -stdlib=libc++ -lfmt
25 changes: 18 additions & 7 deletions .github/workflows/verify_test_memory_valgrind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,26 @@ jobs:
- name: Install
run: |
sudo apt install gcc-11 g++-11 valgrind
( cd /tmp ; mkdir eigen ;
( cd /tmp ;
git clone --depth 1 https://gitlab.com/libeigen/eigen.git ;
( cd eigen ;
mkdir build ) ;
( cd eigen/build ;
cmake .. ;
cmake --build . ;
sudo make install ) )
mkdir build ;
( cd build ;
cmake .. ;
cmake --build . ;
sudo make install ; ) ) )
( cd /tmp ;
git clone --depth 1 https://github.com/fmtlib/fmt.git ;
( cd fmt ;
mkdir build ;
( cd build ;
cmake .. ;
sudo make install ; ) ) )
- name: Build
run: gcc-11 sample/*.cpp test/*.cpp source/*.cpp -Iinclude -I/usr/local/include/eigen3 -g -O0 -std=c++23 -lstdc++ -lm
run: |
gcc-11 \
sample/*.cpp test/*.cpp source/*.cpp \
-Iinclude -I/usr/local/include/eigen3 -Isupport/include/fcarouge \
-g -O0 -std=c++23 -lstdc++ -lm -lfmt
- name: Test
run: valgrind --verbose ./a.out
25 changes: 18 additions & 7 deletions .github/workflows/verify_test_sanitizer_address.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,26 @@ jobs:
- name: Install
run: |
sudo apt install gcc-11 g++-11
( cd /tmp ; mkdir eigen ;
( cd /tmp ;
git clone --depth 1 https://gitlab.com/libeigen/eigen.git ;
( cd eigen ;
mkdir build ) ;
( cd eigen/build ;
cmake .. ;
cmake --build . ;
sudo make install ) )
mkdir build ;
( cd build ;
cmake .. ;
cmake --build . ;
sudo make install ; ) ) )
( cd /tmp ;
git clone --depth 1 https://github.com/fmtlib/fmt.git ;
( cd fmt ;
mkdir build ;
( cd build ;
cmake .. ;
sudo make install ; ) ) )
- name: Build
run: gcc-11 sample/*.cpp test/*.cpp source/*.cpp -Iinclude -I/usr/local/include/eigen3 -std=c++23 -g -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer -lstdc++ -lm
run: |
gcc-11 \
sample/*.cpp test/*.cpp source/*.cpp \
-Iinclude -I/usr/local/include/eigen3 -Isupport/include/fcarouge \
-std=c++23 -g -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer -lstdc++ -lm -lfmt
- name: Test
run: ASAN_OPTIONS=verbosity=2:strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1 ./a.out
25 changes: 18 additions & 7 deletions .github/workflows/verify_test_sanitizer_leak.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,26 @@ jobs:
- name: Install
run: |
sudo apt install gcc-11 g++-11
( cd /tmp ; mkdir eigen ;
( cd /tmp ;
git clone --depth 1 https://gitlab.com/libeigen/eigen.git ;
( cd eigen ;
mkdir build ) ;
( cd eigen/build ;
cmake .. ;
cmake --build . ;
sudo make install ) )
mkdir build ;
( cd build ;
cmake .. ;
cmake --build . ;
sudo make install ; ) ) )
( cd /tmp ;
git clone --depth 1 https://github.com/fmtlib/fmt.git ;
( cd fmt ;
mkdir build ;
( cd build ;
cmake .. ;
sudo make install ; ) ) )
- name: Build
run: gcc-11 sample/*.cpp test/*.cpp source/*.cpp -Iinclude -I/usr/local/include/eigen3 -std=c++23 -g -fsanitize=leak -lstdc++ -lm
run: |
gcc-11 \
sample/*.cpp test/*.cpp source/*.cpp \
-Iinclude -I/usr/local/include/eigen3 -Isupport/include/fcarouge \
-std=c++23 -g -fsanitize=leak -lstdc++ -lm -lfmt
- name: Test
run: LSAN_OPTIONS=verbosity=2 ./a.out
25 changes: 18 additions & 7 deletions .github/workflows/verify_test_sanitizer_thread.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,26 @@ jobs:
- name: Install
run: |
sudo apt install gcc-11 g++-11
( cd /tmp ; mkdir eigen ;
( cd /tmp ;
git clone --depth 1 https://gitlab.com/libeigen/eigen.git ;
( cd eigen ;
mkdir build ) ;
( cd eigen/build ;
cmake .. ;
cmake --build . ;
sudo make install ) )
mkdir build ;
( cd build ;
cmake .. ;
cmake --build . ;
sudo make install ; ) ) )
( cd /tmp ;
git clone --depth 1 https://github.com/fmtlib/fmt.git ;
( cd fmt ;
mkdir build ;
( cd build ;
cmake .. ;
sudo make install ; ) ) )
- name: Build
run: gcc-11 sample/*.cpp test/*.cpp source/*.cpp -Iinclude -I/usr/local/include/eigen3 -std=c++23 -g -fsanitize=thread -lstdc++ -lm
run: |
gcc-11 \
sample/*.cpp test/*.cpp source/*.cpp \
-Iinclude -I/usr/local/include/eigen3 -Isupport/include/fcarouge \
-std=c++23 -g -fsanitize=thread -lstdc++ -lm -lfmt
- name: Test
run: TSAN_OPTIONS=verbosity=2 ./a.out
25 changes: 18 additions & 7 deletions .github/workflows/verify_test_sanitizer_undefined_behavior.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,26 @@ jobs:
- name: Install
run: |
sudo apt install gcc-11 g++-11
( cd /tmp ; mkdir eigen ;
( cd /tmp ;
git clone --depth 1 https://gitlab.com/libeigen/eigen.git ;
( cd eigen ;
mkdir build ) ;
( cd eigen/build ;
cmake .. ;
cmake --build . ;
sudo make install ) )
mkdir build ;
( cd build ;
cmake .. ;
cmake --build . ;
sudo make install ; ) ) )
( cd /tmp ;
git clone --depth 1 https://github.com/fmtlib/fmt.git ;
( cd fmt ;
mkdir build ;
( cd build ;
cmake .. ;
sudo make install ; ) ) )
- name: Build
run: gcc-11 sample/*.cpp test/*.cpp source/*.cpp -Iinclude -I/usr/local/include/eigen3 -std=c++23 -g -fsanitize=undefined -lstdc++ -lm
run: |
gcc-11 \
sample/*.cpp test/*.cpp source/*.cpp \
-Iinclude -I/usr/local/include/eigen3 -Isupport/include/fcarouge \
-std=c++23 -g -fsanitize=undefined -lstdc++ -lm -lfmt
- name: Test
run: UBSAN_OPTIONS=verbosity=2 ./a.out
26 changes: 19 additions & 7 deletions .github/workflows/verify_test_ubuntu-22-04_clang-trunk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,27 @@ jobs:
- name: Install
run: |
sudo apt install clang-14 lld-14 libc++-14-dev libc++abi-14-dev
( cd /tmp ; mkdir eigen ;
( cd /tmp ;
git clone --depth 1 https://gitlab.com/libeigen/eigen.git ;
( cd eigen ;
mkdir build ) ;
( cd eigen/build ;
cmake .. ;
cmake --build . ;
sudo make install ) )
mkdir build ;
( cd build ;
cmake .. ;
cmake --build . ;
sudo make install ; ) ) )
( cd /tmp ;
git clone --depth 1 https://github.com/fmtlib/fmt.git ;
( cd fmt ;
mkdir build ;
( cd build ;
CXX=clang++-14 cmake -DFMT_HEADER_ONLY=TRUE .. ;
sudo make install ; ) ) )
- name: Build
run: clang++-14 sample/*.cpp source/*.cpp test/*.cpp -Iinclude -I/usr/local/include/eigen3 -Wall -Wextra -pedantic -std=c++2b -stdlib=libc++
run: |
clang++-14 \
sample/*.cpp source/*.cpp test/*.cpp \
-Iinclude -I/usr/local/include/eigen3 -Isupport/include/fcarouge \
-DFMT_HEADER_ONLY \
-Wall -Wextra -pedantic -std=c++2b -stdlib=libc++ -lfmt
- name: Run
run: ./a.out
26 changes: 19 additions & 7 deletions .github/workflows/verify_test_ubuntu-22-04_gcc-trunk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,27 @@ jobs:
run: |
wget http://kayari.org/gcc-latest/gcc-latest.deb
sudo dpkg -i gcc-latest.deb
( cd /tmp ; mkdir eigen ;
( cd /tmp ;
git clone --depth 1 https://gitlab.com/libeigen/eigen.git ;
( cd eigen ;
mkdir build ) ;
( cd eigen/build ;
cmake .. ;
cmake --build . ;
sudo make install ) )
mkdir build ;
( cd build ;
cmake .. ;
cmake --build . ;
sudo make install ; ) ) )
( cd /tmp ;
git clone --depth 1 https://github.com/fmtlib/fmt.git ;
( cd fmt ;
mkdir build ;
( cd build ;
cmake .. ;
sudo make install ; ) ) )
- name: Build
run: LD_LIBRARY_PATH=/opt/gcc-latest/lib64 LD_RUN_PATH=/opt/gcc-latest/lib64 /opt/gcc-latest/bin/gcc sample/*.cpp test/*.cpp source/*.cpp -Iinclude -I/usr/local/include/eigen3 -Wall -Wextra -pedantic -std=c++23 -lstdc++ -lm
run: |
LD_LIBRARY_PATH=/opt/gcc-latest/lib64 LD_RUN_PATH=/opt/gcc-latest/lib64 \
/opt/gcc-latest/bin/gcc \
sample/*.cpp test/*.cpp source/*.cpp \
-Iinclude -I/usr/local/include/eigen3 -Isupport/include/fcarouge \
-Wall -Wextra -pedantic -std=c++23 -lstdc++ -lm -lfmt
- name: Run
run: ./a.out
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The library supports simple and extended filters. The update equation uses the J
- [Member Functions](#member-functions)
- [Characteristics](#characteristics)
- [Modifiers](#modifiers)
- [Format](#format)
- [Resources](#resources)
- [License](#license)

Expand Down Expand Up @@ -260,6 +261,17 @@ class kalman
| `update` | Updates the estimates with the outcome of a measurement. |
| `predict` | Produces estimates of the state variables and uncertainties. |

# Format

A specialization of the standard formatter is provided for the filter. Use `std::format` to store a formatted representation of all of the characteristics of the filter in a new string. Standard format parameters are supported.

```cpp
fcarouge::kalman k;

std::string message{ std::format("{}", k) };
// {f:1,h:1,k:1,p:1,q:0,r:0,s:1,x:0,y:0,z:0}
```
# Resources
Awesome resources to learn about Kalman filters:
Expand Down
44 changes: 44 additions & 0 deletions include/fcarouge/internal/format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,48 @@ For more information, please refer to <https://unlicense.org> */
#ifndef FCAROUGE_INTERNAL_FORMAT_HPP
#define FCAROUGE_INTERNAL_FORMAT_HPP

#include "fcarouge/kalman.hpp"

#include <format>
#include <type_traits>

namespace fcarouge
{
template <typename State, typename Output, typename Input, typename Transpose,
typename Symmetrize, typename Divide, typename Identity,
typename UpdateTypes, typename PredictionTypes>
class kalman;
} // namespace fcarouge

template <typename State, typename Output, typename Input, typename Transpose,
typename Symmetrize, typename Divide, typename Identity,
typename UpdateTypes, typename PredictionTypes, typename Char>
struct std::formatter<
fcarouge::kalman<State, Output, Input, Transpose, Symmetrize, Divide,
Identity, UpdateTypes, PredictionTypes>,
Char> {
//! @todo Support parsing arguments.
constexpr auto parse(std::basic_format_parse_context<Char> &parse_context)
{
return parse_context.begin();
}

// @todo How to support different nested types?
template <typename OutputIt>
auto format(const fcarouge::kalman<State, Output, Input, Transpose,
Symmetrize, Divide, Identity, UpdateTypes,
PredictionTypes> &filter,
std::basic_format_context<OutputIt, Char> &format_context)
-> OutputIt
{
return format_to(
format_context.out(),
"{{f:{},g:{},h:{},k:{},p:{},q:{},r:{},s:{},u:{},x:{},y:{},z:{}}}",
filter.f(), filter.g(), filter.h(), filter.k(), filter.p(), filter.q(),
filter.r(), filter.s(), filter.u(), filter.x(), filter.y(), filter.z());
}

//! @}
};

#endif // FCAROUGE_INTERNAL_FORMAT_HPP
Loading

0 comments on commit bb9d8e4

Please sign in to comment.