From 3a0d62f4f4aad448522368821ea1d9ff433b1348 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 5 Mar 2013 09:38:43 +0000 Subject: Update Ceres to 1.5RC3 It brings optimization of DENSE_QR and DENSE_SCHUR solvers. --- extern/libmv/third_party/ceres/ChangeLog | 441 ++++++++++++--------- .../include/ceres/dynamic_autodiff_cost_function.h | 2 +- .../ceres/include/ceres/internal/eigen.h | 33 +- .../third_party/ceres/include/ceres/problem.h | 16 +- .../libmv/third_party/ceres/include/ceres/solver.h | 2 + .../ceres/block_random_access_dense_matrix.cc | 15 +- .../ceres/block_random_access_dense_matrix.h | 2 +- .../third_party/ceres/internal/ceres/cxsparse.cc | 1 + .../internal/ceres/dense_normal_cholesky_solver.cc | 2 +- .../ceres/internal/ceres/dense_sparse_matrix.cc | 36 +- .../ceres/internal/ceres/dense_sparse_matrix.h | 8 +- .../third_party/ceres/internal/ceres/evaluator.cc | 71 ---- .../third_party/ceres/internal/ceres/evaluator.h | 32 +- .../ceres/generate_eliminator_specialization.py | 99 +++-- .../ceres/generated/schur_eliminator_2_2_2.cc | 2 +- .../ceres/generated/schur_eliminator_2_2_3.cc | 2 +- .../ceres/generated/schur_eliminator_2_2_4.cc | 2 +- .../ceres/generated/schur_eliminator_2_2_d.cc | 4 +- .../ceres/generated/schur_eliminator_2_3_3.cc | 2 +- .../ceres/generated/schur_eliminator_2_3_4.cc | 2 +- .../ceres/generated/schur_eliminator_2_3_9.cc | 2 +- .../ceres/generated/schur_eliminator_2_3_d.cc | 4 +- .../ceres/generated/schur_eliminator_2_4_3.cc | 2 +- .../ceres/generated/schur_eliminator_2_4_4.cc | 2 +- .../ceres/generated/schur_eliminator_2_4_d.cc | 4 +- .../ceres/generated/schur_eliminator_4_4_2.cc | 2 +- .../ceres/generated/schur_eliminator_4_4_3.cc | 2 +- .../ceres/generated/schur_eliminator_4_4_4.cc | 2 +- .../ceres/generated/schur_eliminator_4_4_d.cc | 4 +- .../ceres/generated/schur_eliminator_d_d_d.cc | 4 +- .../ceres/internal/ceres/line_search_direction.cc | 2 +- .../ceres/internal/ceres/linear_solver.h | 16 +- .../libmv/third_party/ceres/internal/ceres/mutex.h | 3 +- .../ceres/internal/ceres/preconditioner.h | 8 +- .../ceres/internal/ceres/problem_impl.cc | 11 +- .../ceres/internal/ceres/program_evaluator.h | 4 +- .../ceres/internal/ceres/residual_block.cc | 5 +- .../ceres/internal/ceres/residual_block.h | 7 +- .../ceres/internal/ceres/schur_eliminator.cc | 55 +-- .../ceres/internal/ceres/schur_eliminator.h | 6 +- .../third_party/ceres/internal/ceres/solver.cc | 28 +- .../ceres/internal/ceres/solver_impl.cc | 25 +- .../third_party/ceres/internal/ceres/visibility.cc | 3 +- .../ceres/visibility_based_preconditioner.h | 3 +- 44 files changed, 520 insertions(+), 458 deletions(-) (limited to 'extern/libmv') diff --git a/extern/libmv/third_party/ceres/ChangeLog b/extern/libmv/third_party/ceres/ChangeLog index ebfb771be02..67a1cac9d76 100644 --- a/extern/libmv/third_party/ceres/ChangeLog +++ b/extern/libmv/third_party/ceres/ChangeLog @@ -1,3 +1,251 @@ +commit e7148795c3f2ce1f6625a7c81545707a6cbde3eb +Author: Sameer Agarwal +Date: Mon Mar 4 10:17:30 2013 -0800 + + Fix a memory leak in CXSparse::SolveCholesky. + + Thanks to Alexander Mordvintsev for reporting this. + + Change-Id: I5c6be4d3d28f062e83a1ad41cb8089c19362a005 + +commit 480f9b8551c02c429bc027197f3d868c5cc522c9 +Author: Sameer Agarwal +Date: Sun Mar 3 20:15:22 2013 -0800 + + Add gerrit instructions to the docs. + + Change-Id: Ic98f20273f3ccbaeb8b4ca00c4ce0042a0d262f8 + +commit 7c60b5c2c6170f0f81a29dbaa2ca7d8031db843b +Author: Sameer Agarwal +Date: Sun Mar 3 18:28:02 2013 -0800 + + version history update + + Change-Id: Ia92caeb0f6659667ce1e56eefd0e3c87b3f6e538 + +commit a363a7b69c7b97e17ad671ba1aee30f201eafdd1 +Author: Sameer Agarwal +Date: Sun Mar 3 18:06:00 2013 -0800 + + Multithread DENSE_SCHUR + + Replace the global lock in BlockRandomAccessDenseMatrix + with a per cell lock. + + Change-Id: Iddbe38616157b6e0d3770eede3335a056c3ba18c + +commit 31730ef55df802d1e251edab3bac3c0cdcb30647 +Author: Sameer Agarwal +Date: Thu Feb 28 11:20:28 2013 -0800 + + DenseSparseMatrix is now column-major. + + 1. Introduce new typdefs in eigen.h to allow for column + major matrices. + + 2. Clean up old unused typedefs, and the aligned typedefs + since they do not actually add any real performance. + + 3. Made eigen.h conform to the google style guide by removing + the using directives. They were polluting the ceres namespace. + + 4. Made the template specialization generator work again. + + Change-Id: Ic2268c784534b737ebd6e1a043e2a327adaeca37 + +commit f8e43f7f2724c5413015e1f113ce860ee8b30428 +Author: Sameer Agarwal +Date: Wed Feb 27 08:55:20 2013 -0800 + + version history update + + Change-Id: Ibd412a9e5beac3b3ac3e15b26fb11aa061956095 + +commit fef82b3a7af1e44f18f5343601fb19a4dd6f89ad +Author: Alex Stewart +Date: Wed Feb 27 10:44:12 2013 +0000 + + Bugfix - commenting-out unused member which results in build error on OS X with latest Xcode. + + - Build error due to -Werror,-Wunused-private-field clang args. + - Raised with gtest group (as it also occurs with latest gtest:master but for a different + variable) with patch, but they don't want to fix for compatibility with legacy compilers/OS + see here: https://groups.google.com/forum/?fromgroups=#!topic/googletestframework/S1KLl2jkzws + + Change-Id: I99984bcd9d07f6eb0e3fac58e27ddf0ac9e54265 + +commit 0bc3540b66cf9de4d4a317c6a760849aa66d414e +Author: Sameer Agarwal +Date: Wed Feb 27 08:46:48 2013 -0800 + + Version history update + + Change-Id: I6f79dd87e45bedf4bcf821e7b44f8b9553c39a7b + +commit b59ac43b9d1122da3d00882efa7c5d6833c06ea7 +Author: Alex Stewart +Date: Wed Feb 27 09:10:19 2013 +0000 + + Issue 83 fix: use correct pthread linker flags with clang. + + 1. -lpthreads was previously added to the CMAKE_CXX_FLAGS which are + not passed to the linker thus linking would fail. + 2. Clang would emit a warning about -lpthreads being added to a + build instruction with -c (compile only). + + This patch fixes both of these issues by adding -lpthreads to the + linker flags (and removes them from the CXX flags). + + Change-Id: I5e54de3ab7eced177aa31f311926893598af5b56 + +commit 6fb1024ed5b197da261f71d1bb02716661da2fff +Author: Sameer Agarwal +Date: Tue Feb 26 22:20:18 2013 -0800 + + Fix a small bug in evaluator.h + + Change-Id: I2c4b8637e0ac8645721109f8b6bb2396ce8bb37b + +commit 039ff07dd1a02e6c9cff335551f05bfe8269224b +Author: Sameer Agarwal +Date: Tue Feb 26 09:15:39 2013 -0800 + + Evaluate ResidualBlocks without LossFunction if needed. + + 1. Add the ability to evaluate the problem without loss function. + 2. Remove static Evaluator::Evaluate + 3. Refactor the common code from problem_test.cc and + evaluator_test.cc into evaluator_test_utils.cc + + Change-Id: I1aa841580afe91d288fbb65288b0ffdd1e43e827 + +commit c3fd3b960e489348d5b2c8b8f0167760e52ecbd9 +Author: Taylor Braun-Jones +Date: Tue Feb 26 00:30:35 2013 -0500 + + Only use cmake28 macro for RHEL6 + + This makes it possible to use the same spec to build on Fedora. It drops any + chance of building on RHEL5, but I doubt that was possible anyway. + + Change-Id: Ia956eb6416504e520962ec2f617e03b40ca18203 + +commit b73148b9f38fe41032e696436566b78043a368db +Author: Taylor Braun-Jones +Date: Mon Feb 25 02:34:00 2013 -0500 + + Remove -Wno-return-type-c-linkage option when using gcc + + Only use this option when compiling with CLang which supports it. + + Change-Id: I8555c16e82d61302f6a43672d0d63e5d4800c6b6 + +commit ba9442160dabf612a1dc51baf098937459b4b5ca +Author: Keir Mierle +Date: Mon Feb 25 12:46:44 2013 -0800 + + Add the number of effective parameters to the final report. + + Here is an example report, obtained by running: + + bin/Debug/bundle_adjuster \ + --input=../ceres-solver/data/problem-16-22106-pre.txt \ + --linear_solver=iterative_schur \ + --num_iterations=1 \ + --alsologtostderr \ + --use_local_parameterization \ + --use_quaternions + + Note that effective parameters is less than parameters by 16, which is the + number of cameras. In this case the local parameterization has a 3 dimensional + tangent space for the 4-dimensional quaternions. + + Ceres Solver Report + ------------------- + Original Reduced + Parameter blocks 22138 22138 + Parameters 66478 66478 + Effective parameters 66462 66462 + Residual blocks 83718 83718 + Residual 167436 167436 + + Minimizer TRUST_REGION + Trust Region Strategy LEVENBERG_MARQUARDT + + Given Used + Linear solver ITERATIVE_SCHUR ITERATIVE_SCHUR + Preconditioner JACOBI JACOBI + Threads: 1 1 + Linear solver threads 1 1 + Linear solver ordering AUTOMATIC 22106, 32 + + Cost: + Initial 4.185660e+06 + Final 7.221647e+04 + Change 4.113443e+06 + + Number of iterations: + Successful 1 + Unsuccessful 0 + Total 1 + + Time (in seconds): + Preprocessor 0.697 + + Residual Evaluations 0.063 + Jacobian Evaluations 27.608 + Linear Solver 13.360 + Minimizer 43.973 + + Postprocessor 0.004 + Total 44.756 + + Termination: NO_CONVERGENCE + + Change-Id: I6b6b8ac24f71bd187e67d95651290917642be74f + +commit 36dc14ddf2fd53238c2ce21f172aa1989b31c0fd +Author: Sameer Agarwal +Date: Mon Feb 25 10:33:10 2013 -0800 + + Fix a clang warning + + Change-Id: I5ef32c6329f1f75efb30b16519b8de146a8339fa + +commit 931c309b2734329ec6e5f0b88ce4a0b488ac47e5 +Author: Sameer Agarwal +Date: Mon Feb 25 09:46:21 2013 -0800 + + Cleanup based on comments by William Rucklidge + + Change-Id: If269ba8e388965a8ea32260fd6f17a133a19ab9b + +commit df36218c953e05d665df2cc96a6d7625e2307d97 +Author: Taylor Braun-Jones +Date: Fri Feb 15 18:28:11 2013 -0500 + + Add support for the CMake "LIB_SUFFIX" convention + + Allows `make install` to work correctly on e.g. 64-bit systems where the + native libraries are installed to /usr/lib64 + + Change-Id: I71b4fae7b459c003cb5fac981278c668f2e29779 + +commit 70701745b85fef7eeba2c978ae849fd48927699c +Author: Taylor Braun-Jones +Date: Fri Feb 15 19:09:48 2013 -0500 + + Add RPM .spec file + + Tested on RHEL6.1 (with epel repository for dependencies). + + make_release checks that that the version string in the .spec file is in + sync with the rest of the project and reminds the user to bump the + release string if necessary and to build/upload the RPM package. + + Change-Id: I5f454f2a7301d1e0e120cb3c0e13a68d03bca917 + commit d2a5195b512164fec286c6a52b40d7766977caa3 Author: Sameer Agarwal Date: Sun Feb 24 15:09:17 2013 -0800 @@ -377,196 +625,3 @@ Date: Sat Feb 2 00:49:31 2013 -0800 and coverage than the latex documentation now. Change-Id: I7ede3aa83b9b9ef25104caf331e5727b4f5beae5 - -commit 71c8058478311ff9b3087360827e048dec5dd69a -Author: Sameer Agarwal -Date: Thu Jan 31 17:33:01 2013 -0800 - - Remove ExecutionSummary from Evaluator and LinearSolver - - Change-Id: If4dbaf516a8b14e0a79e1a2116ce66a99ed4a592 - -commit fa1c31eee33051d6483bc90fa7b66c3664b23bf3 -Author: Sameer Agarwal -Date: Tue Jan 29 17:24:54 2013 -0800 - - Correct the documentation for crs_matrix.h - - Thanks to Joydeep Biswas for reporting this. - - Change-Id: Iae5fc2274644aab40f2f922a671f65da15ae71fc - -commit bdd87c03ed1cbac62990bf79aa6faed0a132bba9 -Author: Sameer Agarwal -Date: Tue Jan 29 16:24:31 2013 -0800 - - Add an ExecutionSummary object that the Evaluator and LinearSolver can use to - report execution statistics of all kinds. - - Currently a single map which maps arbitrary strings to doubles is supported, - which allows for precise timing information to be communicated. - - Change-Id: Ibd930aca5c9e6cae89bcfeffe9b13e2887644881 - -commit a2fd9ca8beb5aa11fcc5d2b32e23f161edc93d28 -Author: Sameer Agarwal -Date: Tue Jan 29 16:02:41 2013 -0800 - - Fix Android.mk - - Change-Id: I1093c2731283890d1f3792bf8e6741f448f1465d - -commit 977be7cac37316524038fa0168cc5994a5654acd -Author: Sameer Agarwal -Date: Sat Jan 26 16:01:54 2013 -0800 - - Add support for reporting linear solver and inner iteration - orderings. - - Change-Id: I0588a4285e0925ce689e47bd48ddcc61ce596a1f - -commit 146b9acb4d5570da311fedb5222ad65fe12f233c -Author: Sameer Agarwal -Date: Mon Jan 21 16:16:58 2013 -0800 - - Update include/ceres.h to export headers. - Update the ABI version. - - Change-Id: I5c1c4f110cddc816bbb5a737634f55b4cbea98e1 - -commit e837aeaf9e63936d745519fa53c726a2ca9d5822 -Author: Sameer Agarwal -Date: Mon Jan 21 13:05:01 2013 -0800 - - Documentation update. - - Change-Id: Ica8681f4bb58c60349d0dae453c652f2522eebf6 - -commit 2f0d7249ccedac8183e6e5a9cb45ca7c51bb6b41 -Author: Sameer Agarwal -Date: Fri Jan 18 13:11:32 2013 -0800 - - NumericDiffFunctor. - - A wrapper class that takes a variadic functor evaluating a - function, numerically differentiates it and makes it available as a - templated functor so that it can be easily used as part of Ceres' - automatic differentiation framework. - - The tests for NumericDiffCostFunction and NumericDiffFunctor have - a lot of stuff that is common, so refactor them to reduce code. - - Change-Id: I83b01e58b05e575fb2530d15cbd611928298646a - -commit 2fc0ed6143ad499d6dc82d621ff5ec69170beb52 -Author: Sameer Agarwal -Date: Tue Jan 15 11:34:10 2013 -0800 - - Change NumericDiffCostFunction to accept variadic functors. - - The interface for NumericDiffCostFunction and AutoDiffCostFunction - are not comparable. They both accept variadic functors. - - The change is backward compatible, as it still supports numeric - differentiation of CostFunction objects. - - Some refactoring of documentation and code in auto_diff_cost_function - and its relatives was also done to make things consistent. - - Change-Id: Ib5f230a1d4a85738eb187803b9c1cd7166bb3b92 - -commit 9c5acce674e3ec1ba08509123ff519f106cc4348 -Author: Sameer Agarwal -Date: Sun Jan 13 22:14:12 2013 -0800 - - Add CostFunctionToFunctor. - - CostFunctionToFunctor wraps a CostFunction, and makes it available - as a templated functor that can be called from other templated - functors. This is useful for when one wants to mix automatic, - numeric and analytic differentiated functions. - - Also a bug fix in autodiff.h - - Change-Id: If8ba281a89fda976ef2ce10a5844a74c4ac7b84a - -commit c89ea4b9de588e2e2e82c54cd1c30cddb11454c5 -Author: Sameer Agarwal -Date: Wed Jan 9 16:09:35 2013 -0800 - - Minor corrections based on Jim Roseborough's comments - - Change-Id: I4a8c7a454ddf038a3ed2567c101f9aee582044bf - -commit 00c8a061929b912bda3cfd4615fb8688c246c969 -Author: Keir Mierle -Date: Sat Dec 1 13:22:59 2012 -0800 - - Fix bug in DenseSparseMatrix::ToDenseMatrix(). - - Change-Id: I74a1a03149d74fbc4268ec3ce9d20e09746a7227 - -commit bcac4de5b75cae210c5557c81239222176d2709a -Author: Sameer Agarwal -Date: Fri Nov 30 23:11:26 2012 -0800 - - Speedup corrector.cc - - Add a specialization for the common case where the residual block - outputs exactly one residual. - - The matrix routines used by Corrector can be then specialized to - a scalar and be made considerably faster. - - For denoising upto 400% speedup is observed. - - Change-Id: I8e3f24b8ba41caa8e62ad97c5f5e96ab6ea47150 - -commit 9883fc396b2913fbc597afa795c39d365229c299 -Author: Sameer Agarwal -Date: Fri Nov 30 12:32:43 2012 -0800 - - Refactoring of the LineSearchMinimizer. - - 1. New LineSearchDirection interface, factory and instances. - 2. Cleanup of LineSearchMinimizer to use the State and Direction objects. - 3. LBFGS -> LowRankInverseHessian. - 4. Refactoring of the RunCallbacks function and share it across - LineSearchMinimizer and TrustRegionMinimizer. - - Change-Id: I19354afc6f5d6567b28918710c2012dc30ef8f32 - -commit 2293cb5bc96a5b317ed4ca52aa3494cadecbc07c -Author: Sameer Agarwal -Date: Thu Nov 29 16:00:18 2012 -0800 - - Add missing documentation to solver.h - - Change-Id: I86e7c4f1f6cc1e15d5eb2cf23e73c32d94d458c1 - -commit aed99615c017839df09c98f518dcc0a59a9819ec -Author: Sameer Agarwal -Date: Thu Nov 29 10:33:19 2012 -0800 - - Expose lbfgs rank in solver.h - - Change-Id: Ibc184b1a2f94a4057fa6569d539ca3a55d6d6098 - -commit 1afd498f50ef520868c18a0f26b55409d8471ceb -Author: Sameer Agarwal -Date: Thu Nov 29 10:28:11 2012 -0800 - - String to and from enum conversion routines. - - Update types.h/cc with stringication and unstringication - routines for the newly introduced enums. - - Change-Id: I0fe2842b5b1c75ba351f4ab87ec9fa60af2f9ed2 - -commit 3e8d192f2871bcf6d5f248c119c8a6eef19186d3 -Author: Sameer Agarwal -Date: Wed Nov 28 17:20:22 2012 -0800 - - Add a rough implementation of LBFGS. - - Change-Id: I2bc816adfe0c02773a23035ea31de3cddc1322a4 diff --git a/extern/libmv/third_party/ceres/include/ceres/dynamic_autodiff_cost_function.h b/extern/libmv/third_party/ceres/include/ceres/dynamic_autodiff_cost_function.h index 861164a8253..e4549c54b43 100644 --- a/extern/libmv/third_party/ceres/include/ceres/dynamic_autodiff_cost_function.h +++ b/extern/libmv/third_party/ceres/include/ceres/dynamic_autodiff_cost_function.h @@ -78,7 +78,7 @@ template class DynamicAutoDiffCostFunction : public CostFunction { public: explicit DynamicAutoDiffCostFunction(CostFunctor* functor) - : functor_(functor) {} + : functor_(functor) {} virtual ~DynamicAutoDiffCostFunction() {} diff --git a/extern/libmv/third_party/ceres/include/ceres/internal/eigen.h b/extern/libmv/third_party/ceres/include/ceres/internal/eigen.h index be76f9eff98..85df54b8f99 100644 --- a/extern/libmv/third_party/ceres/include/ceres/internal/eigen.h +++ b/extern/libmv/third_party/ceres/include/ceres/internal/eigen.h @@ -35,27 +35,40 @@ namespace ceres { -using Eigen::Dynamic; -using Eigen::RowMajor; - -typedef Eigen::Matrix Vector; -typedef Eigen::Matrix Matrix; +typedef Eigen::Matrix Vector; +typedef Eigen::Matrix Matrix; typedef Eigen::Map VectorRef; typedef Eigen::Map MatrixRef; -typedef Eigen::Map AlignedMatrixRef; typedef Eigen::Map ConstVectorRef; -typedef Eigen::Map ConstAlignedMatrixRef; typedef Eigen::Map ConstMatrixRef; +// Column major matrices for DenseSparseMatrix/DenseQRSolver +typedef Eigen::Matrix ColMajorMatrix; + +typedef Eigen::Map > ColMajorMatrixRef; + +typedef Eigen::Map > ConstColMajorMatrixRef; + + + // C++ does not support templated typdefs, thus the need for this // struct so that we can support statically sized Matrix and Maps. template struct EigenTypes { - typedef Eigen::Matrix + typedef Eigen::Matrix Matrix; typedef Eigen::Map< - Eigen::Matrix > + Eigen::Matrix > MatrixRef; typedef Eigen::Matrix @@ -67,7 +80,7 @@ struct EigenTypes { typedef Eigen::Map< - const Eigen::Matrix > + const Eigen::Matrix > ConstMatrixRef; typedef Eigen::Map < diff --git a/extern/libmv/third_party/ceres/include/ceres/problem.h b/extern/libmv/third_party/ceres/include/ceres/problem.h index bccb329dc55..b1ccbab5dbd 100644 --- a/extern/libmv/third_party/ceres/include/ceres/problem.h +++ b/extern/libmv/third_party/ceres/include/ceres/problem.h @@ -331,7 +331,8 @@ class Problem { // Options struct to control Problem::Evaluate. struct EvaluateOptions { EvaluateOptions() - : num_threads(1) { + : apply_loss_function(true), + num_threads(1) { } // The set of parameter blocks for which evaluation should be @@ -345,7 +346,7 @@ class Problem { // problem. // // NOTE: This vector should contain the same pointers as the ones - // used to add parameter blocks to the Problem. These parmeter + // used to add parameter blocks to the Problem. These parameter // block should NOT point to new memory locations. Bad things will // happen otherwise. vector parameter_blocks; @@ -360,6 +361,15 @@ class Problem { // they were added to the problem. But, this may change if the // user removes any residual blocks from the problem. vector residual_blocks; + + // Even though the residual blocks in the problem may contain loss + // functions, setting apply_loss_function to false will turn off + // the application of the loss function to the output of the cost + // function. This is of use for example if the user wishes to + // analyse the solution quality by studying the distribution of + // residuals before and after the solve. + bool apply_loss_function; + int num_threads; }; @@ -390,7 +400,7 @@ class Problem { // the gradient vector (and the number of columns in the jacobian) // is the sum of the sizes of all the parameter blocks. If a // parameter block has a local parameterization, then it contributes - // "LocalSize" entries to the gradient vecto (and the number of + // "LocalSize" entries to the gradient vector (and the number of // columns in the jacobian). bool Evaluate(const EvaluateOptions& options, double* cost, diff --git a/extern/libmv/third_party/ceres/include/ceres/solver.h b/extern/libmv/third_party/ceres/include/ceres/solver.h index 122870c86c8..8c2ff32d80b 100644 --- a/extern/libmv/third_party/ceres/include/ceres/solver.h +++ b/extern/libmv/third_party/ceres/include/ceres/solver.h @@ -611,11 +611,13 @@ class Solver { // Preprocessor summary. int num_parameter_blocks; int num_parameters; + int num_effective_parameters; int num_residual_blocks; int num_residuals; int num_parameter_blocks_reduced; int num_parameters_reduced; + int num_effective_parameters_reduced; int num_residual_blocks_reduced; int num_residuals_reduced; diff --git a/extern/libmv/third_party/ceres/internal/ceres/block_random_access_dense_matrix.cc b/extern/libmv/third_party/ceres/internal/ceres/block_random_access_dense_matrix.cc index aedfc745f22..e5822792fa1 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/block_random_access_dense_matrix.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/block_random_access_dense_matrix.cc @@ -40,16 +40,21 @@ namespace internal { BlockRandomAccessDenseMatrix::BlockRandomAccessDenseMatrix( const vector& blocks) { - block_layout_.resize(blocks.size(), 0); + const int num_blocks = blocks.size(); + block_layout_.resize(num_blocks, 0); num_rows_ = 0; - for (int i = 0; i < blocks.size(); ++i) { + for (int i = 0; i < num_blocks; ++i) { block_layout_[i] = num_rows_; num_rows_ += blocks[i]; } values_.reset(new double[num_rows_ * num_rows_]); - CHECK_NOTNULL(values_.get()); - cell_info_.values = values_.get(); + + cell_infos_.reset(new CellInfo[num_blocks * num_blocks]); + for (int i = 0; i < num_blocks * num_blocks; ++i) { + cell_infos_[i].values = values_.get(); + } + SetZero(); } @@ -68,7 +73,7 @@ CellInfo* BlockRandomAccessDenseMatrix::GetCell(const int row_block_id, *col = block_layout_[col_block_id]; *row_stride = num_rows_; *col_stride = num_rows_; - return &cell_info_; + return &cell_infos_[row_block_id * block_layout_.size() + col_block_id]; } // Assume that the user does not hold any locks on any cell blocks diff --git a/extern/libmv/third_party/ceres/internal/ceres/block_random_access_dense_matrix.h b/extern/libmv/third_party/ceres/internal/ceres/block_random_access_dense_matrix.h index 9f27a4c30f3..d160fd96013 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/block_random_access_dense_matrix.h +++ b/extern/libmv/third_party/ceres/internal/ceres/block_random_access_dense_matrix.h @@ -84,10 +84,10 @@ class BlockRandomAccessDenseMatrix : public BlockRandomAccessMatrix { double* mutable_values() { return values_.get(); } private: - CellInfo cell_info_; int num_rows_; vector block_layout_; scoped_array values_; + scoped_array cell_infos_; CERES_DISALLOW_COPY_AND_ASSIGN(BlockRandomAccessDenseMatrix); }; diff --git a/extern/libmv/third_party/ceres/internal/ceres/cxsparse.cc b/extern/libmv/third_party/ceres/internal/ceres/cxsparse.cc index 19fa17cc37d..3fbc2717f64 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/cxsparse.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/cxsparse.cc @@ -57,6 +57,7 @@ bool CXSparse::SolveCholesky(cs_di* A, cs_free(scratch_); } scratch_ = reinterpret_cast(cs_malloc(A->n, sizeof(CS_ENTRY))); + scratch_size_ = A->n; } // Solve using Cholesky factorization diff --git a/extern/libmv/third_party/ceres/internal/ceres/dense_normal_cholesky_solver.cc b/extern/libmv/third_party/ceres/internal/ceres/dense_normal_cholesky_solver.cc index a340e1664f0..96f55115a67 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/dense_normal_cholesky_solver.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/dense_normal_cholesky_solver.cc @@ -57,7 +57,7 @@ LinearSolver::Summary DenseNormalCholeskySolver::SolveImpl( const int num_rows = A->num_rows(); const int num_cols = A->num_cols(); - ConstAlignedMatrixRef Aref = A->matrix(); + ConstColMajorMatrixRef Aref = A->matrix(); Matrix lhs(num_cols, num_cols); lhs.setZero(); diff --git a/extern/libmv/third_party/ceres/internal/ceres/dense_sparse_matrix.cc b/extern/libmv/third_party/ceres/internal/ceres/dense_sparse_matrix.cc index 978ac6abe15..9d58031ccfc 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/dense_sparse_matrix.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/dense_sparse_matrix.cc @@ -42,7 +42,6 @@ namespace internal { DenseSparseMatrix::DenseSparseMatrix(int num_rows, int num_cols) : has_diagonal_appended_(false), has_diagonal_reserved_(false) { - // Allocate enough space for the diagonal. m_.resize(num_rows, num_cols); m_.setZero(); } @@ -52,8 +51,8 @@ DenseSparseMatrix::DenseSparseMatrix(int num_rows, bool reserve_diagonal) : has_diagonal_appended_(false), has_diagonal_reserved_(reserve_diagonal) { - // Allocate enough space for the diagonal. if (reserve_diagonal) { + // Allocate enough space for the diagonal. m_.resize(num_rows + num_cols, num_cols); } else { m_.resize(num_rows, num_cols); @@ -75,7 +74,7 @@ DenseSparseMatrix::DenseSparseMatrix(const TripletSparseMatrix& m) } } -DenseSparseMatrix::DenseSparseMatrix(const Matrix& m) +DenseSparseMatrix::DenseSparseMatrix(const ColMajorMatrix& m) : m_(m), has_diagonal_appended_(false), has_diagonal_reserved_(false) { @@ -141,7 +140,7 @@ void DenseSparseMatrix::ToProto(SparseMatrixProto* outer_proto) const { void DenseSparseMatrix::AppendDiagonal(double *d) { CHECK(!has_diagonal_appended_); if (!has_diagonal_reserved_) { - Matrix tmp = m_; + ColMajorMatrix tmp = m_; m_.resize(m_.rows() + m_.cols(), m_.cols()); m_.setZero(); m_.block(0, 0, tmp.rows(), tmp.cols()) = tmp; @@ -177,22 +176,27 @@ int DenseSparseMatrix::num_nonzeros() const { return m_.rows() * m_.cols(); } -ConstAlignedMatrixRef DenseSparseMatrix::matrix() const { - if (has_diagonal_reserved_ && !has_diagonal_appended_) { - return ConstAlignedMatrixRef( - m_.data(), m_.rows() - m_.cols(), m_.cols()); - } - return ConstAlignedMatrixRef(m_.data(), m_.rows(), m_.cols()); +ConstColMajorMatrixRef DenseSparseMatrix::matrix() const { + return ConstColMajorMatrixRef( + m_.data(), + ((has_diagonal_reserved_ && !has_diagonal_appended_) + ? m_.rows() - m_.cols() + : m_.rows()), + m_.cols(), + Eigen::Stride(m_.rows(), 1)); } -AlignedMatrixRef DenseSparseMatrix::mutable_matrix() { - if (has_diagonal_reserved_ && !has_diagonal_appended_) { - return AlignedMatrixRef( - m_.data(), m_.rows() - m_.cols(), m_.cols()); - } - return AlignedMatrixRef(m_.data(), m_.rows(), m_.cols()); +ColMajorMatrixRef DenseSparseMatrix::mutable_matrix() { + return ColMajorMatrixRef( + m_.data(), + ((has_diagonal_reserved_ && !has_diagonal_appended_) + ? m_.rows() - m_.cols() + : m_.rows()), + m_.cols(), + Eigen::Stride(m_.rows(), 1)); } + void DenseSparseMatrix::ToTextFile(FILE* file) const { CHECK_NOTNULL(file); const int active_rows = diff --git a/extern/libmv/third_party/ceres/internal/ceres/dense_sparse_matrix.h b/extern/libmv/third_party/ceres/internal/ceres/dense_sparse_matrix.h index 1e4d499b631..6c7b60ade13 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/dense_sparse_matrix.h +++ b/extern/libmv/third_party/ceres/internal/ceres/dense_sparse_matrix.h @@ -51,7 +51,7 @@ class DenseSparseMatrix : public SparseMatrix { // Build a matrix with the same content as the TripletSparseMatrix // m. This assumes that m does not have any repeated entries. explicit DenseSparseMatrix(const TripletSparseMatrix& m); - explicit DenseSparseMatrix(const Matrix& m); + explicit DenseSparseMatrix(const ColMajorMatrix& m); #ifndef CERES_NO_PROTOCOL_BUFFERS explicit DenseSparseMatrix(const SparseMatrixProto& proto); #endif @@ -78,8 +78,8 @@ class DenseSparseMatrix : public SparseMatrix { virtual const double* values() const { return m_.data(); } virtual double* mutable_values() { return m_.data(); } - ConstAlignedMatrixRef matrix() const; - AlignedMatrixRef mutable_matrix(); + ConstColMajorMatrixRef matrix() const; + ColMajorMatrixRef mutable_matrix(); // Only one diagonal can be appended at a time. The diagonal is appended to // as a new set of rows, e.g. @@ -106,7 +106,7 @@ class DenseSparseMatrix : public SparseMatrix { void RemoveDiagonal(); private: - Matrix m_; + ColMajorMatrix m_; bool has_diagonal_appended_; bool has_diagonal_reserved_; }; diff --git a/extern/libmv/third_party/ceres/internal/ceres/evaluator.cc b/extern/libmv/third_party/ceres/internal/ceres/evaluator.cc index a3ce6f04bd4..31a417689e8 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/evaluator.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/evaluator.cc @@ -72,76 +72,5 @@ Evaluator* Evaluator::Create(const Evaluator::Options& options, } } -bool Evaluator::Evaluate(Program* program, - int num_threads, - double* cost, - vector* residuals, - vector* gradient, - CRSMatrix* output_jacobian) { - CHECK_GE(num_threads, 1) - << "This is a Ceres bug; please contact the developers!"; - CHECK_NOTNULL(cost); - - // Setup the Parameter indices and offsets before an evaluator can - // be constructed and used. - program->SetParameterOffsetsAndIndex(); - - Evaluator::Options evaluator_options; - evaluator_options.linear_solver_type = SPARSE_NORMAL_CHOLESKY; - evaluator_options.num_threads = num_threads; - - string error; - scoped_ptr evaluator( - Evaluator::Create(evaluator_options, program, &error)); - if (evaluator.get() == NULL) { - LOG(ERROR) << "Unable to create an Evaluator object. " - << "Error: " << error - << "This is a Ceres bug; please contact the developers!"; - return false; - } - - if (residuals !=NULL) { - residuals->resize(evaluator->NumResiduals()); - } - - if (gradient != NULL) { - gradient->resize(evaluator->NumEffectiveParameters()); - } - - scoped_ptr jacobian; - if (output_jacobian != NULL) { - jacobian.reset( - down_cast(evaluator->CreateJacobian())); - } - - // Point the state pointers to the user state pointers. This is - // needed so that we can extract a parameter vector which is then - // passed to Evaluator::Evaluate. - program->SetParameterBlockStatePtrsToUserStatePtrs(); - - // Copy the value of the parameter blocks into a vector, since the - // Evaluate::Evaluate method needs its input as such. The previous - // call to SetParameterBlockStatePtrsToUserStatePtrs ensures that - // these values are the ones corresponding to the actual state of - // the parameter blocks, rather than the temporary state pointer - // used for evaluation. - Vector parameters(program->NumParameters()); - program->ParameterBlocksToStateVector(parameters.data()); - - if (!evaluator->Evaluate(parameters.data(), - cost, - residuals != NULL ? &(*residuals)[0] : NULL, - gradient != NULL ? &(*gradient)[0] : NULL, - jacobian.get())) { - return false; - } - - if (output_jacobian != NULL) { - jacobian->ToCRSMatrix(output_jacobian); - } - - return true; -} - } // namespace internal } // namespace ceres diff --git a/extern/libmv/third_party/ceres/internal/ceres/evaluator.h b/extern/libmv/third_party/ceres/internal/ceres/evaluator.h index 14a88188145..3d2546224b8 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/evaluator.h +++ b/extern/libmv/third_party/ceres/internal/ceres/evaluator.h @@ -72,7 +72,6 @@ class Evaluator { Program* program, string* error); - // This is used for computing the cost, residual and Jacobian for // returning to the user. For actually solving the optimization // problem, the optimization algorithm uses the ProgramEvaluator @@ -116,6 +115,18 @@ class Evaluator { // Schur complement based methods. virtual SparseMatrix* CreateJacobian() const = 0; + + // Options struct to control Evaluator::Evaluate; + struct EvaluateOptions { + EvaluateOptions() + : apply_loss_function(true) { + } + + // If false, the loss function correction is not applied to the + // residual blocks. + bool apply_loss_function; + }; + // Evaluate the cost function for the given state. Returns the cost, // residuals, and jacobian in the corresponding arguments. Both residuals and // jacobian are optional; to avoid computing them, pass NULL. @@ -125,12 +136,29 @@ class Evaluator { // // state is an array of size NumParameters(), cost is a pointer to a single // double, and residuals is an array of doubles of size NumResiduals(). - virtual bool Evaluate(const double* state, + virtual bool Evaluate(const EvaluateOptions& evaluate_options, + const double* state, double* cost, double* residuals, double* gradient, SparseMatrix* jacobian) = 0; + // Variant of Evaluator::Evaluate where the user wishes to use the + // default EvaluateOptions struct. This is mostly here as a + // convenience method. + bool Evaluate(const double* state, + double* cost, + double* residuals, + double* gradient, + SparseMatrix* jacobian) { + return Evaluate(EvaluateOptions(), + state, + cost, + residuals, + gradient, + jacobian); + } + // Make a change delta (of size NumEffectiveParameters()) to state (of size // NumParameters()) and store the result in state_plus_delta. // diff --git a/extern/libmv/third_party/ceres/internal/ceres/generate_eliminator_specialization.py b/extern/libmv/third_party/ceres/internal/ceres/generate_eliminator_specialization.py index af9873f94c0..60953513f4f 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generate_eliminator_specialization.py +++ b/extern/libmv/third_party/ceres/internal/ceres/generate_eliminator_specialization.py @@ -1,33 +1,31 @@ -// Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2010, 2011, 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of Google Inc. nor the names of its contributors may be -// used to endorse or promote products derived from this software without -// specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// +# Ceres Solver - A fast non-linear least squares minimizer +# Copyright 2010, 2011, 2012, 2013 Google Inc. All rights reserved. +# http://code.google.com/p/ceres-solver/ +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of Google Inc. nor the names of its contributors may be +# used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. # -# Copyright 2011 Google Inc. All Rights Reserved. # Author: sameeragarwal@google.com (Sameer Agarwal) # # Script for explicitly generating template specialization of the @@ -54,21 +52,48 @@ SPECIALIZATIONS = [(2, 2, 2), (2, 2, 3), (2, 2, 4), - (2, 2, "Dynamic"), + (2, 2, "Eigen::Dynamic"), (2, 3, 3), (2, 3, 4), (2, 3, 9), - (2, 3, "Dynamic"), + (2, 3, "Eigen::Dynamic"), (2, 4, 3), (2, 4, 4), - (2, 4, "Dynamic"), + (2, 4, "Eigen::Dynamic"), (4, 4, 2), (4, 4, 3), (4, 4, 4), - (4, 4, "Dynamic"), - ("Dynamic", "Dynamic", "Dynamic")] + (4, 4, "Eigen::Dynamic"), + ("Eigen::Dynamic", "Eigen::Dynamic", "Eigen::Dynamic")] -SPECIALIZATION_FILE = """// Copyright 2011 Google Inc. All Rights Reserved. +SPECIALIZATION_FILE = """// Ceres Solver - A fast non-linear least squares minimizer +// Copyright 2010, 2011, 2012, 2013 Google Inc. All rights reserved. +// http://code.google.com/p/ceres-solver/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Google Inc. nor the names of its contributors may be +// used to endorse or promote products derived from this software without +// specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// // Author: sameeragarwal@google.com (Sameer Agarwal) // // Template specialization of SchurEliminator. @@ -134,7 +159,7 @@ FACTORY_FOOTER = """ << options.row_block_size << "," << options.e_block_size << "," << options.f_block_size << ">"; - return new SchurEliminator(options); + return new SchurEliminator(options); } } // namespace internal @@ -143,7 +168,7 @@ FACTORY_FOOTER = """ def SuffixForSize(size): - if size == "Dynamic": + if size == "Eigen::Dynamic": return "d" return str(size) diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_2_2.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_2_2.cc index 5529386e485..b4a2cfd123c 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_2_2.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_2_2.cc @@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2010, 2011, 2012 Google Inc. All rights reserved. +// Copyright 2010, 2011, 2012, 2013 Google Inc. All rights reserved. // http://code.google.com/p/ceres-solver/ // // Redistribution and use in source and binary forms, with or without diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_2_3.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_2_3.cc index fd7af95192e..2373c6b86e1 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_2_3.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_2_3.cc @@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2010, 2011, 2012 Google Inc. All rights reserved. +// Copyright 2010, 2011, 2012, 2013 Google Inc. All rights reserved. // http://code.google.com/p/ceres-solver/ // // Redistribution and use in source and binary forms, with or without diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_2_4.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_2_4.cc index 109483e9fc0..6253fe47410 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_2_4.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_2_4.cc @@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2010, 2011, 2012 Google Inc. All rights reserved. +// Copyright 2010, 2011, 2012, 2013 Google Inc. All rights reserved. // http://code.google.com/p/ceres-solver/ // // Redistribution and use in source and binary forms, with or without diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_2_d.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_2_d.cc index b93e82fe2fa..d773a4f9d7e 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_2_d.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_2_d.cc @@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2010, 2011, 2012 Google Inc. All rights reserved. +// Copyright 2010, 2011, 2012, 2013 Google Inc. All rights reserved. // http://code.google.com/p/ceres-solver/ // // Redistribution and use in source and binary forms, with or without @@ -46,7 +46,7 @@ namespace ceres { namespace internal { -template class SchurEliminator<2, 2, Dynamic>; +template class SchurEliminator<2, 2, Eigen::Dynamic>; } // namespace internal } // namespace ceres diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_3_3.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_3_3.cc index 86352c07304..afb89b88891 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_3_3.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_3_3.cc @@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2010, 2011, 2012 Google Inc. All rights reserved. +// Copyright 2010, 2011, 2012, 2013 Google Inc. All rights reserved. // http://code.google.com/p/ceres-solver/ // // Redistribution and use in source and binary forms, with or without diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_3_4.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_3_4.cc index 200df7f5931..c883ee690dc 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_3_4.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_3_4.cc @@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2010, 2011, 2012 Google Inc. All rights reserved. +// Copyright 2010, 2011, 2012, 2013 Google Inc. All rights reserved. // http://code.google.com/p/ceres-solver/ // // Redistribution and use in source and binary forms, with or without diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_3_9.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_3_9.cc index 1fda3434bef..bdffdc5a98d 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_3_9.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_3_9.cc @@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2010, 2011, 2012 Google Inc. All rights reserved. +// Copyright 2010, 2011, 2012, 2013 Google Inc. All rights reserved. // http://code.google.com/p/ceres-solver/ // // Redistribution and use in source and binary forms, with or without diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_3_d.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_3_d.cc index 385cd2d70c9..5d4139c23c3 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_3_d.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_3_d.cc @@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2010, 2011, 2012 Google Inc. All rights reserved. +// Copyright 2010, 2011, 2012, 2013 Google Inc. All rights reserved. // http://code.google.com/p/ceres-solver/ // // Redistribution and use in source and binary forms, with or without @@ -46,7 +46,7 @@ namespace ceres { namespace internal { -template class SchurEliminator<2, 3, Dynamic>; +template class SchurEliminator<2, 3, Eigen::Dynamic>; } // namespace internal } // namespace ceres diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_4_3.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_4_3.cc index 7b15d6366ac..06b99df6622 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_4_3.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_4_3.cc @@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2010, 2011, 2012 Google Inc. All rights reserved. +// Copyright 2010, 2011, 2012, 2013 Google Inc. All rights reserved. // http://code.google.com/p/ceres-solver/ // // Redistribution and use in source and binary forms, with or without diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_4_4.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_4_4.cc index 29a610d743e..4bc1f44c2cd 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_4_4.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_4_4.cc @@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2010, 2011, 2012 Google Inc. All rights reserved. +// Copyright 2010, 2011, 2012, 2013 Google Inc. All rights reserved. // http://code.google.com/p/ceres-solver/ // // Redistribution and use in source and binary forms, with or without diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_4_d.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_4_d.cc index a3bc4dc6f83..573e40ca73f 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_4_d.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_4_d.cc @@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2010, 2011, 2012 Google Inc. All rights reserved. +// Copyright 2010, 2011, 2012, 2013 Google Inc. All rights reserved. // http://code.google.com/p/ceres-solver/ // // Redistribution and use in source and binary forms, with or without @@ -46,7 +46,7 @@ namespace ceres { namespace internal { -template class SchurEliminator<2, 4, Dynamic>; +template class SchurEliminator<2, 4, Eigen::Dynamic>; } // namespace internal } // namespace ceres diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_4_4_2.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_4_4_2.cc index f71a4f62944..e1f17fedd1b 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_4_4_2.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_4_4_2.cc @@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2010, 2011, 2012 Google Inc. All rights reserved. +// Copyright 2010, 2011, 2012, 2013 Google Inc. All rights reserved. // http://code.google.com/p/ceres-solver/ // // Redistribution and use in source and binary forms, with or without diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_4_4_3.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_4_4_3.cc index 52259fb1a67..e7c750ade04 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_4_4_3.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_4_4_3.cc @@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2010, 2011, 2012 Google Inc. All rights reserved. +// Copyright 2010, 2011, 2012, 2013 Google Inc. All rights reserved. // http://code.google.com/p/ceres-solver/ // // Redistribution and use in source and binary forms, with or without diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_4_4_4.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_4_4_4.cc index 775424e6c8f..d60ad71eedd 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_4_4_4.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_4_4_4.cc @@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2010, 2011, 2012 Google Inc. All rights reserved. +// Copyright 2010, 2011, 2012, 2013 Google Inc. All rights reserved. // http://code.google.com/p/ceres-solver/ // // Redistribution and use in source and binary forms, with or without diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_4_4_d.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_4_4_d.cc index 97cde594059..12fa9789beb 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_4_4_d.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_4_4_d.cc @@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2010, 2011, 2012 Google Inc. All rights reserved. +// Copyright 2010, 2011, 2012, 2013 Google Inc. All rights reserved. // http://code.google.com/p/ceres-solver/ // // Redistribution and use in source and binary forms, with or without @@ -46,7 +46,7 @@ namespace ceres { namespace internal { -template class SchurEliminator<4, 4, Dynamic>; +template class SchurEliminator<4, 4, Eigen::Dynamic>; } // namespace internal } // namespace ceres diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_d_d_d.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_d_d_d.cc index 4cba32e26c8..fa34e39e42d 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_d_d_d.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_d_d_d.cc @@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2010, 2011, 2012 Google Inc. All rights reserved. +// Copyright 2010, 2011, 2012, 2013 Google Inc. All rights reserved. // http://code.google.com/p/ceres-solver/ // // Redistribution and use in source and binary forms, with or without @@ -46,7 +46,7 @@ namespace ceres { namespace internal { -template class SchurEliminator; +template class SchurEliminator; } // namespace internal } // namespace ceres diff --git a/extern/libmv/third_party/ceres/internal/ceres/line_search_direction.cc b/extern/libmv/third_party/ceres/internal/ceres/line_search_direction.cc index 2f27a78301a..1fc4de57e91 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/line_search_direction.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/line_search_direction.cc @@ -81,7 +81,7 @@ class NonlinearConjugateGradient : public LineSearchDirection { *search_direction = -current.gradient + beta * previous.search_direction; const double directional_derivative = - current. gradient.dot(*search_direction); + current.gradient.dot(*search_direction); if (directional_derivative > -function_tolerance_) { LOG(WARNING) << "Restarting non-linear conjugate gradients: " << directional_derivative; diff --git a/extern/libmv/third_party/ceres/internal/ceres/linear_solver.h b/extern/libmv/third_party/ceres/internal/ceres/linear_solver.h index a98051468e7..f4bd0fb6f9f 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/linear_solver.h +++ b/extern/libmv/third_party/ceres/internal/ceres/linear_solver.h @@ -79,9 +79,9 @@ class LinearSolver { max_num_iterations(1), num_threads(1), residual_reset_period(10), - row_block_size(Dynamic), - e_block_size(Dynamic), - f_block_size(Dynamic) { + row_block_size(Eigen::Dynamic), + e_block_size(Eigen::Dynamic), + f_block_size(Eigen::Dynamic) { } LinearSolverType type; @@ -106,11 +106,11 @@ class LinearSolver { // // For example if elimination_groups is a vector of size k, then // the linear solver is informed that it should eliminate the - // parameter blocks 0 - elimination_groups[0] - 1 first, and then - // elimination_groups[0] - elimination_groups[1] and so on. Within - // each elimination group, the linear solver is free to choose how - // the parameter blocks are ordered. Different linear solvers have - // differing requirements on elimination_groups. + // parameter blocks 0 ... elimination_groups[0] - 1 first, and + // then elimination_groups[0] ... elimination_groups[1] - 1 and so + // on. Within each elimination group, the linear solver is free to + // choose how the parameter blocks are ordered. Different linear + // solvers have differing requirements on elimination_groups. // // The most common use is for Schur type solvers, where there // should be at least two elimination groups and the first diff --git a/extern/libmv/third_party/ceres/internal/ceres/mutex.h b/extern/libmv/third_party/ceres/internal/ceres/mutex.h index 410748ff0ab..0c48ed352b5 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/mutex.h +++ b/extern/libmv/third_party/ceres/internal/ceres/mutex.h @@ -275,7 +275,8 @@ void Mutex::ReaderUnlock() { Unlock(); } // "MutexLock(x) COMPILE_ASSERT(false)". To work around this, "Ceres" is // prefixed to the class names; this permits defining the classes. -// CeresMutexLock(mu) acquires mu when constructed and releases it when destroyed. +// CeresMutexLock(mu) acquires mu when constructed and releases it +// when destroyed. class CeresMutexLock { public: explicit CeresMutexLock(Mutex *mu) : mu_(mu) { mu_->Lock(); } diff --git a/extern/libmv/third_party/ceres/internal/ceres/preconditioner.h b/extern/libmv/third_party/ceres/internal/ceres/preconditioner.h index 5bb077e0e33..bfc8464db17 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/preconditioner.h +++ b/extern/libmv/third_party/ceres/internal/ceres/preconditioner.h @@ -49,9 +49,9 @@ class Preconditioner : public LinearOperator { sparse_linear_algebra_library(SUITE_SPARSE), use_block_amd(true), num_threads(1), - row_block_size(Dynamic), - e_block_size(Dynamic), - f_block_size(Dynamic) { + row_block_size(Eigen::Dynamic), + e_block_size(Eigen::Dynamic), + f_block_size(Eigen::Dynamic) { } PreconditionerType type; @@ -70,7 +70,7 @@ class Preconditioner : public LinearOperator { // For example if elimination_groups is a vector of size k, then // the linear solver is informed that it should eliminate the // parameter blocks 0 ... elimination_groups[0] - 1 first, and - // then elimination_groups[0] ... elimination_groups[1] and so + // then elimination_groups[0] ... elimination_groups[1] - 1 and so // on. Within each elimination group, the linear solver is free to // choose how the parameter blocks are ordered. Different linear // solvers have differing requirements on elimination_groups. diff --git a/extern/libmv/third_party/ceres/internal/ceres/problem_impl.cc b/extern/libmv/third_party/ceres/internal/ceres/problem_impl.cc index bc378aaafff..21d11442177 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/problem_impl.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/problem_impl.cc @@ -651,14 +651,19 @@ bool ProblemImpl::Evaluate(const Problem::EvaluateOptions& evaluate_options, program.ParameterBlocksToStateVector(parameters.data()); double tmp_cost = 0; - bool status = evaluator->Evaluate(parameters.data(), + + Evaluator::EvaluateOptions evaluator_evaluate_options; + evaluator_evaluate_options.apply_loss_function = + evaluate_options.apply_loss_function; + bool status = evaluator->Evaluate(evaluator_evaluate_options, + parameters.data(), &tmp_cost, residuals != NULL ? &(*residuals)[0] : NULL, gradient != NULL ? &(*gradient)[0] : NULL, tmp_jacobian.get()); - // Make the parameter blocks that were temporarirly marked - // constant, variable again. + // Make the parameter blocks that were temporarily marked constant, + // variable again. for (int i = 0; i < variable_parameter_blocks.size(); ++i) { variable_parameter_blocks[i]->SetVarying(); } diff --git a/extern/libmv/third_party/ceres/internal/ceres/program_evaluator.h b/extern/libmv/third_party/ceres/internal/ceres/program_evaluator.h index a19cdf8a86a..de56ac25ff6 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/program_evaluator.h +++ b/extern/libmv/third_party/ceres/internal/ceres/program_evaluator.h @@ -120,7 +120,8 @@ class ProgramEvaluator : public Evaluator { return jacobian_writer_.CreateJacobian(); } - bool Evaluate(const double* state, + bool Evaluate(const Evaluator::EvaluateOptions& evaluate_options, + const double* state, double* cost, double* residuals, double* gradient, @@ -196,6 +197,7 @@ class ProgramEvaluator : public Evaluator { // Evaluate the cost, residuals, and jacobians. double block_cost; if (!residual_block->Evaluate( + evaluate_options.apply_loss_function, &block_cost, block_residuals, block_jacobians, diff --git a/extern/libmv/third_party/ceres/internal/ceres/residual_block.cc b/extern/libmv/third_party/ceres/internal/ceres/residual_block.cc index 7f789605e5f..b91b0ed7843 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/residual_block.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/residual_block.cc @@ -62,7 +62,8 @@ ResidualBlock::ResidualBlock(const CostFunction* cost_function, parameter_blocks_.get()); } -bool ResidualBlock::Evaluate(double* cost, +bool ResidualBlock::Evaluate(const bool apply_loss_function, + double* cost, double* residuals, double** jacobians, double* scratch) const { @@ -154,7 +155,7 @@ bool ResidualBlock::Evaluate(double* cost, } } - if (loss_function_ == NULL) { + if (loss_function_ == NULL || !apply_loss_function) { *cost = 0.5 * squared_norm; return true; } diff --git a/extern/libmv/third_party/ceres/internal/ceres/residual_block.h b/extern/libmv/third_party/ceres/internal/ceres/residual_block.h index 3921d1d4678..9c3671bb0a4 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/residual_block.h +++ b/extern/libmv/third_party/ceres/internal/ceres/residual_block.h @@ -93,11 +93,16 @@ class ResidualBlock { // parameterizations applied already; for example, the jacobian for a // 4-dimensional quaternion parameter using the "QuaternionParameterization" // is num_residuals by 3 instead of num_residuals by 4. - bool Evaluate(double* cost, + // + // apply_loss_function as the name implies allows the user to switch + // the application of the loss function on and off. + bool Evaluate(bool apply_loss_function, + double* cost, double* residuals, double** jacobians, double* scratch) const; + const CostFunction* cost_function() const { return cost_function_; } const LossFunction* loss_function() const { return loss_function_; } diff --git a/extern/libmv/third_party/ceres/internal/ceres/schur_eliminator.cc b/extern/libmv/third_party/ceres/internal/ceres/schur_eliminator.cc index 44f5be3b4e9..8dbf30f0379 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/schur_eliminator.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/schur_eliminator.cc @@ -1,31 +1,4 @@ -// Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2010, 2011, 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of Google Inc. nor the names of its contributors may be -// used to endorse or promote products derived from this software without -// specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// +// Copyright 2011 Google Inc. All Rights Reserved. // Author: sameeragarwal@google.com (Sameer Agarwal) // // ======================================== @@ -65,8 +38,8 @@ SchurEliminatorBase::Create(const LinearSolver::Options& options) { } if ((options.row_block_size == 2) && (options.e_block_size == 2) && - (options.f_block_size == Dynamic)) { - return new SchurEliminator<2, 2, Dynamic>(options); + (options.f_block_size == Eigen::Dynamic)) { + return new SchurEliminator<2, 2, Eigen::Dynamic>(options); } if ((options.row_block_size == 2) && (options.e_block_size == 3) && @@ -85,8 +58,8 @@ SchurEliminatorBase::Create(const LinearSolver::Options& options) { } if ((options.row_block_size == 2) && (options.e_block_size == 3) && - (options.f_block_size == Dynamic)) { - return new SchurEliminator<2, 3, Dynamic>(options); + (options.f_block_size == Eigen::Dynamic)) { + return new SchurEliminator<2, 3, Eigen::Dynamic>(options); } if ((options.row_block_size == 2) && (options.e_block_size == 4) && @@ -100,8 +73,8 @@ SchurEliminatorBase::Create(const LinearSolver::Options& options) { } if ((options.row_block_size == 2) && (options.e_block_size == 4) && - (options.f_block_size == Dynamic)) { - return new SchurEliminator<2, 4, Dynamic>(options); + (options.f_block_size == Eigen::Dynamic)) { + return new SchurEliminator<2, 4, Eigen::Dynamic>(options); } if ((options.row_block_size == 4) && (options.e_block_size == 4) && @@ -120,13 +93,13 @@ SchurEliminatorBase::Create(const LinearSolver::Options& options) { } if ((options.row_block_size == 4) && (options.e_block_size == 4) && - (options.f_block_size == Dynamic)) { - return new SchurEliminator<4, 4, Dynamic>(options); + (options.f_block_size == Eigen::Dynamic)) { + return new SchurEliminator<4, 4, Eigen::Dynamic>(options); } - if ((options.row_block_size == Dynamic) && - (options.e_block_size == Dynamic) && - (options.f_block_size == Dynamic)) { - return new SchurEliminator(options); + if ((options.row_block_size == Eigen::Dynamic) && + (options.e_block_size == Eigen::Dynamic) && + (options.f_block_size == Eigen::Dynamic)) { + return new SchurEliminator(options); } #endif @@ -134,7 +107,7 @@ SchurEliminatorBase::Create(const LinearSolver::Options& options) { << options.row_block_size << "," << options.e_block_size << "," << options.f_block_size << ">"; - return new SchurEliminator(options); + return new SchurEliminator(options); } } // namespace internal diff --git a/extern/libmv/third_party/ceres/internal/ceres/schur_eliminator.h b/extern/libmv/third_party/ceres/internal/ceres/schur_eliminator.h index c24fe435f54..877621bb48c 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/schur_eliminator.h +++ b/extern/libmv/third_party/ceres/internal/ceres/schur_eliminator.h @@ -213,9 +213,9 @@ class SchurEliminatorBase { // // This implementation is mulithreaded using OpenMP. The level of // parallelism is controlled by LinearSolver::Options::num_threads. -template +template class SchurEliminator : public SchurEliminatorBase { public: explicit SchurEliminator(const LinearSolver::Options& options) diff --git a/extern/libmv/third_party/ceres/internal/ceres/solver.cc b/extern/libmv/third_party/ceres/internal/ceres/solver.cc index 6436d2df2a7..ea9ff1f488b 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/solver.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/solver.cc @@ -100,10 +100,12 @@ Solver::Summary::Summary() jacobian_evaluation_time_in_seconds(-1.0), num_parameter_blocks(-1), num_parameters(-1), + num_effective_parameters(-1), num_residual_blocks(-1), num_residuals(-1), num_parameter_blocks_reduced(-1), num_parameters_reduced(-1), + num_effective_parameters_reduced(-1), num_residual_blocks_reduced(-1), num_residuals_reduced(-1), num_threads_given(-1), @@ -156,10 +158,12 @@ string Solver::Summary::FullReport() const { if (termination_type == DID_NOT_RUN) { StringAppendF(&report, " Original\n"); - StringAppendF(&report, "Parameter blocks % 10d\n", - num_parameter_blocks); - StringAppendF(&report, "Parameters % 10d\n", - num_parameters); + StringAppendF(&report, "Parameter blocks % 10d\n", num_parameter_blocks); + StringAppendF(&report, "Parameters % 10d\n", num_parameters); + if (num_effective_parameters != num_parameters) { + StringAppendF(&report, "Effective parameters% 10d\n", num_parameters); + } + StringAppendF(&report, "Residual blocks % 10d\n", num_residual_blocks); StringAppendF(&report, "Residuals % 10d\n\n", @@ -170,6 +174,10 @@ string Solver::Summary::FullReport() const { num_parameter_blocks, num_parameter_blocks_reduced); StringAppendF(&report, "Parameters % 25d% 25d\n", num_parameters, num_parameters_reduced); + if (num_effective_parameters_reduced != num_parameters_reduced) { + StringAppendF(&report, "Effective parameters% 25d% 25d\n", + num_effective_parameters, num_effective_parameters_reduced); + } StringAppendF(&report, "Residual blocks % 25d% 25d\n", num_residual_blocks, num_residual_blocks_reduced); StringAppendF(&report, "Residual % 25d% 25d\n", @@ -204,7 +212,7 @@ string Solver::Summary::FullReport() const { StringAppendF(&report, "\n"); StringAppendF(&report, "\n"); - StringAppendF(&report, "%45s %21s\n", "Given", "Used"); + StringAppendF(&report, "%45s %21s\n", "Given", "Used"); StringAppendF(&report, "Linear solver %25s%25s\n", LinearSolverTypeToString(linear_solver_type_given), LinearSolverTypeToString(linear_solver_type_used)); @@ -299,15 +307,15 @@ string Solver::Summary::FullReport() const { // LINE_SEARCH StringAppendF(&report, "\nMinimizer %19s\n", "LINE_SEARCH"); if (line_search_direction_type == LBFGS) { - StringAppendF(&report, "Line search direction %19s(%d)\n", + StringAppendF(&report, "Line search direction %19s(%d)\n", LineSearchDirectionTypeToString(line_search_direction_type), max_lbfgs_rank); } else { - StringAppendF(&report, "Line search direction %19s\n", + StringAppendF(&report, "Line search direction %19s\n", LineSearchDirectionTypeToString( line_search_direction_type)); } - StringAppendF(&report, "Line search type %19s\n", + StringAppendF(&report, "Line search type %19s\n", LineSearchTypeToString(line_search_type)); StringAppendF(&report, "\n"); @@ -336,8 +344,8 @@ string Solver::Summary::FullReport() const { initial_cost - final_cost); } - StringAppendF(&report, "\nNumber of iterations: % 20ld\n", - iterations.size() - 1); + StringAppendF(&report, "\nNumber of iterations: % 20d\n", + static_cast(iterations.size() - 1)); StringAppendF(&report, "\nTime (in seconds):\n"); StringAppendF(&report, "Preprocessor %25.3f\n", diff --git a/extern/libmv/third_party/ceres/internal/ceres/solver_impl.cc b/extern/libmv/third_party/ceres/internal/ceres/solver_impl.cc index 5bcfdc6312f..e18d3b96333 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/solver_impl.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/solver_impl.cc @@ -335,6 +335,8 @@ void SolverImpl::TrustRegionSolve(const Solver::Options& original_options, summary->minimizer_type = TRUST_REGION; summary->num_parameter_blocks = problem_impl->NumParameterBlocks(); summary->num_parameters = problem_impl->NumParameters(); + summary->num_effective_parameters = + original_program->NumEffectiveParameters(); summary->num_residual_blocks = problem_impl->NumResidualBlocks(); summary->num_residuals = problem_impl->NumResiduals(); @@ -447,6 +449,8 @@ void SolverImpl::TrustRegionSolve(const Solver::Options& original_options, summary->num_parameter_blocks_reduced = reduced_program->NumParameterBlocks(); summary->num_parameters_reduced = reduced_program->NumParameters(); + summary->num_effective_parameters_reduced = + reduced_program->NumEffectiveParameters(); summary->num_residual_blocks_reduced = reduced_program->NumResidualBlocks(); summary->num_residuals_reduced = reduced_program->NumResiduals(); @@ -910,8 +914,11 @@ bool SolverImpl::RemoveFixedBlocksFromProgram(Program* program, // The residual is constant and will be removed, so its cost is // added to the variable fixed_cost. double cost = 0.0; - if (!residual_block->Evaluate( - &cost, NULL, NULL, residual_block_evaluate_scratch.get())) { + if (!residual_block->Evaluate(true, + &cost, + NULL, + NULL, + residual_block_evaluate_scratch.get())) { *error = StringPrintf("Evaluation of the residual %d failed during " "removal of fixed residual blocks.", i); return false; @@ -1146,20 +1153,6 @@ LinearSolver* SolverImpl::CreateLinearSolver(Solver::Options* options, options->sparse_linear_algebra_library; linear_solver_options.num_threads = options->num_linear_solver_threads; - // The matrix used for storing the dense Schur complement has a - // single lock guarding the whole matrix. Running the - // SchurComplementSolver with multiple threads leads to maximum - // contention and slowdown. If the problem is large enough to - // benefit from a multithreaded schur eliminator, you should be - // using a SPARSE_SCHUR solver anyways. - if ((linear_solver_options.num_threads > 1) && - (linear_solver_options.type == DENSE_SCHUR)) { - LOG(WARNING) << "Warning: Solver::Options::num_linear_solver_threads = " - << options->num_linear_solver_threads - << " with DENSE_SCHUR will result in poor performance; " - << "switching to single-threaded."; - linear_solver_options.num_threads = 1; - } options->num_linear_solver_threads = linear_solver_options.num_threads; linear_solver_options.use_block_amd = options->use_block_amd; diff --git a/extern/libmv/third_party/ceres/internal/ceres/visibility.cc b/extern/libmv/third_party/ceres/internal/ceres/visibility.cc index 8e80fd121bb..371bdfacd52 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/visibility.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/visibility.cc @@ -139,7 +139,8 @@ Graph* CreateSchurComplementGraph(const vector >& visibility) { const int count = it->second; // Static cast necessary for Windows. const double weight = static_cast(count) / - (sqrt(static_cast(visibility[camera1].size() * visibility[camera2].size()))); + (sqrt(static_cast( + visibility[camera1].size() * visibility[camera2].size()))); graph->AddEdge(camera1, camera2, weight); } diff --git a/extern/libmv/third_party/ceres/internal/ceres/visibility_based_preconditioner.h b/extern/libmv/third_party/ceres/internal/ceres/visibility_based_preconditioner.h index 8a09c78d36a..dae498730aa 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/visibility_based_preconditioner.h +++ b/extern/libmv/third_party/ceres/internal/ceres/visibility_based_preconditioner.h @@ -38,7 +38,8 @@ // documented here can be found in // // Visibility Based Preconditioning for Bundle Adjustment -// A. Kushal & S. Agarwal, submitted to CVPR 2012 +// A. Kushal & S. Agarwal, CVPR 2012. +// // http://www.cs.washington.edu/homes/sagarwal/vbp.pdf // // The two preconditioners share enough code that its most efficient -- cgit v1.2.3