123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- #include "ceres/preprocessor.h"
- #include <memory>
- #include "ceres/callbacks.h"
- #include "ceres/gradient_checking_cost_function.h"
- #include "ceres/line_search_preprocessor.h"
- #include "ceres/problem_impl.h"
- #include "ceres/solver.h"
- #include "ceres/thread_pool.h"
- #include "ceres/trust_region_preprocessor.h"
- namespace ceres::internal {
- std::unique_ptr<Preprocessor> Preprocessor::Create(
- MinimizerType minimizer_type) {
- if (minimizer_type == TRUST_REGION) {
- return std::make_unique<TrustRegionPreprocessor>();
- }
- if (minimizer_type == LINE_SEARCH) {
- return std::make_unique<LineSearchPreprocessor>();
- }
- LOG(FATAL) << "Unknown minimizer_type: " << minimizer_type;
- return nullptr;
- }
- Preprocessor::~Preprocessor() = default;
- void ChangeNumThreadsIfNeeded(Solver::Options* options) {
- if (options->num_threads == 1) {
- return;
- }
- const int num_threads_available = ThreadPool::MaxNumThreadsAvailable();
- if (options->num_threads > num_threads_available) {
- LOG(WARNING) << "Specified options.num_threads: " << options->num_threads
- << " exceeds maximum available from the threading model Ceres "
- << "was compiled with: " << num_threads_available
- << ". Bounding to maximum number available.";
- options->num_threads = num_threads_available;
- }
- }
- void SetupCommonMinimizerOptions(PreprocessedProblem* pp) {
- const Solver::Options& options = pp->options;
- Program* program = pp->reduced_program.get();
-
-
- pp->reduced_parameters.resize(program->NumParameters());
- double* reduced_parameters = pp->reduced_parameters.data();
- program->ParameterBlocksToStateVector(reduced_parameters);
- auto context = pp->problem->context();
- Minimizer::Options& minimizer_options = pp->minimizer_options;
- minimizer_options = Minimizer::Options(options);
- minimizer_options.evaluator = pp->evaluator;
- minimizer_options.context = context;
- if (options.logging_type != SILENT) {
- pp->logging_callback = std::make_unique<LoggingCallback>(
- options.minimizer_type, options.minimizer_progress_to_stdout);
- minimizer_options.callbacks.insert(minimizer_options.callbacks.begin(),
- pp->logging_callback.get());
- }
- if (options.update_state_every_iteration) {
- pp->state_updating_callback =
- std::make_unique<StateUpdatingCallback>(program, reduced_parameters);
-
-
- minimizer_options.callbacks.insert(minimizer_options.callbacks.begin(),
- pp->state_updating_callback.get());
- }
- }
- }
|