Skip to content

julien-michot/tinyopt-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tinyopt-example Builds

tinyopt-example

Minimal Tinyopt project

CMakeLists.txt

set(CMAKE_CXX_STANDARD 20) # Minimum is c++17

find_package(Tinyopt)
find_package(Eigen3) # Only needed if Tinyopt is not found locally

add_executable(example src/example.cpp)
target_link_libraries(example PUBLIC tinyopt)
target_link_libraries(example PUBLIC Eigen3::Eigen) # needed, sometimes...

Alternative using git submodule

The provided CMakeLists.txt is fetching Tinyopt if it's not found locally but you can also install it using git submodules, e.g.

git submodule add https://github.com/julien-michot/tinyopt.git third_party/tinyopt
git submodule init
git submodule update --init --recursive

and add it to the project:

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/tinyopt)

Example.cpp

Here is an example of usage of 'tinyopt' where we compute the square root of 2.

#include <tinyopt/tinyopt.h>
using namespace tinyopt::nlls; // Default Non-Linear Least Square Optimizer

int main(int, char **argv) {
  double x = 1;
  Optimize(x, [](const auto &x) { return x * x - 2.0; });
  std::cout << "What's √2 already?\n" << x << "\n";
  return 0;
}

Building

git clone https://github.com/julien-michot/tinyopt-example
cd tinyopt-example && mkdir build && cd build
cmake ..
make -j

Running

./example

About

Minimal Tinyopt project

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published