File tree Expand file tree Collapse file tree 3 files changed +94
-0
lines changed
Expand file tree Collapse file tree 3 files changed +94
-0
lines changed Original file line number Diff line number Diff line change 1+ cmake_minimum_required (VERSION 3.5)
2+
3+ project (tinyopt-example VERSION 0.0.1
4+ DESCRIPTION "A Tinyopt Example Project"
5+ LANGUAGES CXX)
6+
7+ # Compiler flags
8+ set (CMAKE_CXX_STANDARD 20)
9+
10+ # Import Eigen (Mandatory)
11+ find_package (Eigen3 REQUIRED NO_MODULE)
12+
13+ # Find Tinyopt, fetch it if not found
14+ find_package (Tinyopt)
15+
16+ if (NOT Tinyopt_FOUND)
17+ message ("Tinyopt not found locally, fetching it" )
18+ include (FetchContent)
19+ FetchContent_Declare(
20+ tinyopt
21+ GIT_REPOSITORY https://github.com/julien-michot/tinyopt.git
22+ GIT_TAG main
23+ GIT_SHALLOW TRUE
24+ GIT_PROGRESS TRUE
25+ )
26+ set (BUILD_TINYOPT_TESTS OFF )
27+ FetchContent_MakeAvailable(tinyopt)
28+ endif ()
29+
30+ # Header-only library
31+ add_executable (example src/example.cpp)
32+ target_link_libraries (example PUBLIC Eigen3::Eigen tinyopt)
Original file line number Diff line number Diff line change 1+
2+ ![ Tinyopt-example Builds] ( https://github.com/julien-michot/tinyopt-example/actions/workflows/build.yml/badge.svg )
3+
14# tinyopt-example
25Minimal Tinyopt project
6+
7+ ## CMakeLists.txt
8+
9+ ``` cmake
10+ set(CMAKE_CXX_STANDARD 20)
11+
12+ find_package(Eigen3 REQUIRED NO_MODULE)
13+ find_package(Tinyopt)
14+
15+ add_executable(example src/example.cpp)
16+ target_link_libraries(example PUBLIC Eigen3::Eigen tinyopt)
17+ ```
18+
19+
20+ ## Example.cpp
21+
22+ Here is an example of usage of 'tinyopt' where we compute the square root of 2.
23+
24+ ``` cpp
25+ #include < tinyopt/tinyopt.h>
26+
27+ int main (int, char ** argv) {
28+ double x = 1;
29+ tinyopt::Optimize(x, [ ] (const auto &x) { return x * x - 2.0; });
30+ std::cout << "What's √2 already?\n" << x << "\n";
31+ return 0;
32+ }
33+ ```
34+
35+ ### Building
36+
37+ ```shell
38+ git clone https://github.com/julien-michot/tinyopt-example
39+ cd tinyopt-example && mkdir build && cd build
40+ cmake ..
41+ make -j
42+ ```
43+
44+ ### Running
45+
46+ ``` shell
47+ ./example
48+ ```
Original file line number Diff line number Diff line change 1+ // / This is free and unencumbered software released into the public domain.
2+ // / Example of usage of 'tinyopt' and compute the square root of 2.
3+
4+ #include < tinyopt/tinyopt.h>
5+
6+ int main (int , char **argv) {
7+
8+ double x = 1 ;
9+ auto loss = [](const auto &x) { return x * x - 2.0 ; };
10+
11+ tinyopt::Options options;
12+ const auto &out = tinyopt::Optimize (x, loss, options);
13+
14+ std::cout << " What's √2 already?\n " << x << " \n " ;
15+ return 0 ;
16+ }
You can’t perform that action at this time.
0 commit comments