diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2015-10-28 16:55:04 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2015-10-28 17:20:50 +0300 |
commit | ced1c34f74d115f81052667d4d17e4efd6b282c4 (patch) | |
tree | 8f236e4a3183bdfe3d7d7ab19e6a5b5703c9ae84 /extern/libmv | |
parent | f10db730bc4d8139e86ce078dd0fdd9fd07a8f35 (diff) |
Ceres: Update to the latest version
It brings all the performance improvements, bug fixes and stability improvements
which were done in the last year of Ceres development.
Diffstat (limited to 'extern/libmv')
268 files changed, 3920 insertions, 2552 deletions
diff --git a/extern/libmv/third_party/ceres/CMakeLists.txt b/extern/libmv/third_party/ceres/CMakeLists.txt index 694982ec606..f9a7d0631c0 100644 --- a/extern/libmv/third_party/ceres/CMakeLists.txt +++ b/extern/libmv/third_party/ceres/CMakeLists.txt @@ -80,7 +80,6 @@ set(SRC internal/ceres/gradient_problem.cc internal/ceres/gradient_problem_solver.cc internal/ceres/implicit_schur_complement.cc - internal/ceres/incomplete_lq_factorization.cc internal/ceres/iterative_schur_complement_solver.cc internal/ceres/lapack.cc internal/ceres/levenberg_marquardt_strategy.cc @@ -209,7 +208,6 @@ set(SRC internal/ceres/graph_algorithms.h internal/ceres/graph.h internal/ceres/implicit_schur_complement.h - internal/ceres/incomplete_lq_factorization.h internal/ceres/integral_types.h internal/ceres/iterative_schur_complement_solver.h internal/ceres/lapack.h @@ -270,6 +268,7 @@ if(WITH_LIBMV_SCHUR_SPECIALIZATIONS) internal/ceres/generated/partitioned_matrix_view_2_2_d.cc internal/ceres/generated/partitioned_matrix_view_2_3_3.cc internal/ceres/generated/partitioned_matrix_view_2_3_4.cc + internal/ceres/generated/partitioned_matrix_view_2_3_6.cc internal/ceres/generated/partitioned_matrix_view_2_3_9.cc internal/ceres/generated/partitioned_matrix_view_2_3_d.cc internal/ceres/generated/partitioned_matrix_view_2_4_3.cc @@ -288,6 +287,7 @@ if(WITH_LIBMV_SCHUR_SPECIALIZATIONS) internal/ceres/generated/schur_eliminator_2_2_d.cc internal/ceres/generated/schur_eliminator_2_3_3.cc internal/ceres/generated/schur_eliminator_2_3_4.cc + internal/ceres/generated/schur_eliminator_2_3_6.cc internal/ceres/generated/schur_eliminator_2_3_9.cc internal/ceres/generated/schur_eliminator_2_3_d.cc internal/ceres/generated/schur_eliminator_2_4_3.cc diff --git a/extern/libmv/third_party/ceres/ChangeLog b/extern/libmv/third_party/ceres/ChangeLog index b4f78ee0731..0e6c195174c 100644 --- a/extern/libmv/third_party/ceres/ChangeLog +++ b/extern/libmv/third_party/ceres/ChangeLog @@ -1,673 +1,659 @@ -commit 0435246de5f45e69b2c97d244ed61bedd340215a -Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Wed Oct 8 18:12:53 2014 -0700 +commit aef9c9563b08d5f39eee1576af133a84749d1b48 +Author: Alessandro Gentilini <agentilini@gmail.com> +Date: Tue Oct 6 20:43:45 2015 +0200 - Add seene to users.rst + Add test for Bessel functions. - Change-Id: If40726775a3d4b234b6e10517fe9943d122a3384 + Change-Id: Ief5881e8027643d7ef627e60a88fdbad17f3d884 -commit fdf32b315f39553639f0becf078ad4eec763a10e -Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Wed Oct 8 16:04:32 2014 -0700 +commit 49c86018e00f196c4aa9bd25daccb9919917efee +Author: Alessandro Gentilini <agentilini@gmail.com> +Date: Wed Sep 23 21:59:44 2015 +0200 - Fix some errant tabs. + Add Bessel functions in order to use them in residual code. - Change-Id: Iaf1906eaade49467ba282656cf0a10879d258b1f + See "How can I use the Bessel function in the residual function?" at + https://groups.google.com/d/msg/ceres-solver/Vh1gpqac8v0/NIK1EiWJCAAJ + + Change-Id: I3e80d9f9d1cadaf7177076e493ff46ace5233b76 -commit 6768b3586a027bb850c0a50e2a27380f5d80142a -Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Wed Oct 8 12:48:16 2014 -0700 +commit dfb201220c034fde00a242d0533bef3f73b2907d +Author: Simon Rutishauser <simon.rutishauser@pix4d.com> +Date: Tue Oct 13 07:33:58 2015 +0200 - Minor cleanups in preparation for a release. + Make miniglog threadsafe on non-windows system by using + localtime_r() instead of localtime() for time formatting - 1. Fix the release script to ignore the version.h checking. - 2. Fix some ceres documentation formatting errors. - - Change-Id: I3fd6b85e771b242f463d6a36c3efd8d691f9242f + Change-Id: Ib8006c685cd8ed4f374893bef56c4061ca2c9747 -commit 7b6bd1cd31aa0b8cb7fb97600c1b9999846e3152 -Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Thu Oct 2 16:16:26 2014 -0700 +commit 41455566ac633e55f222bce7c4d2cb4cc33d5c72 +Author: Alex Stewart <alexs.mac@gmail.com> +Date: Mon Sep 28 22:43:42 2015 +0100 - Documentation update. + Remove link-time optimisation (LTO). - 1. Complete restructuring of the documentation to account for - GradientProblemSolver. - 2. Update the version history to account for changes since 1.9.0. - 3. Add links and document the various examples that ship with ceres. - 4. Documentation for GradientProblem GradientProblemSolver. + - On GCC 4.9+ although GCC supports LTO, it requires use of the + non-default gcc-ar & gcc-ranlib. Whilst we can ensure Ceres is + compiled with these, doing so with GCC 4.9 causes multiple definition + linker errors of static ints inside Eigen when compiling the tests + and examples when they are not also built with LTO. + - On OS X (Xcode 6 & 7) after the latest update to gtest, if LTO + is used when compiling the tests (& examples), two tests fail + due to typeinfo::operator== (things are fine if only Ceres itself is + compiled with LTO). + - This patch disables LTO for all compilers. It should be revisited when + the performance is more stable across our supported compilers. - Change-Id: If3a18f2850cbc98be1bc34435e9ea468785b8b27 + Change-Id: I17b52957faefbdeff0aa40846dc9b342db1b02e3 -commit b7d321f505e936b6c09aeb43ae3f7b1252388a95 -Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Fri Oct 3 15:47:59 2014 -0700 +commit 89c40005bfceadb4163bd16b7464b3c2ce740daf +Author: Alex Stewart <alexs.mac@gmail.com> +Date: Sun Sep 27 13:37:26 2015 +0100 - Relax the warning/error handing in GCC. + Only use LTO when compiling Ceres itself, not tests or examples. - Thanks to Matthew Woehlke for suggesting this. + - If Ceres is built as a shared library, and LTO is enabled for Ceres + and the tests, then type_info::operator==() incorrectly returns false + in gtests' CheckedDowncastToActualType() in the following tests: + -- levenberg_marquardt_strategy_test. + -- gradient_checking_cost_function_test. + on at least Xcode 6 & 7 as reported here: + https://github.com/google/googletest/issues/595. + - This does not appear to be a gtest issue, but is perhaps an LLVM bug + or an RTTI shared library issue. Either way, disabling the use of + LTO when compiling the test application resolves the issue. + - Allow LTO to be enabled for GCC, if it is supported. + - Add CMake function to allow easy appending to target properties s/t + Ceres library-specific compile flags can be iteratively constructed. - Change-Id: Iae754465c086b0841a7816df1a36781371d0dc9a + Change-Id: I923e6aae4f7cefa098cf32b2f8fc19389e7918c9 -commit 94c6e7d27b5d48d81ab54ed9cdcbc55c3c099311 +commit 0794f41cca440f7f65d9a44e671f66f6e498ef7c Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Wed Oct 1 15:55:13 2014 -0700 +Date: Sat Sep 26 14:10:15 2015 -0700 - Improve multithreading when using inner iterations. - - Inner iterations by default would use problems where the evaluator - was configured to use exactly one thread for doing the evaluation. - This is fine when there are multiple inner iteration problems - being executed concurrently, but every now and then there are - problem decompositions where there is just one parameter block - in the current independent set and it touches every single - residual block. In such cases it is essential that the evaluator - be configured to use multiple threads. + Documentation updates. - We now pay attention to the size of the independent set and - dynamically configure the number of threads being used by the - outer loop and the evaluator loop. + 1. Fix a typo in the Trust Region algorithm. + 2. Add ARL in the list of users. + 3. Update the version history. - Thanks to William Rucklidge for reporting this issue and providing - a test problem to debug. - - Change-Id: Iaff9a4ab6d2658cf7b61ea213575d23aab604e3b + Change-Id: Ic286e8ef1a71af07f3890b7592dd3aed9c5f87ce -commit 9e11cd16d09403b9270e621e839d5948b6a74b8d -Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Mon Sep 29 14:27:58 2014 -0700 +commit 90e32a8dc437dfb0e6747ce15a1f3193c13b7d5b +Author: Alex Stewart <alexs.mac@gmail.com> +Date: Mon Sep 21 21:08:25 2015 +0100 - Faster BlockRandomAccessSparseMatrix::SymmetricRightMultiply. - - Trade a small amount of memory to improve the cache coherency of - the SymmetricRightMultiply operation. + Use old minimum iOS version flags on Xcode < 7.0. - The resulting code leads to a 10-20% speedup in the linear solver - end to end. + - The newer style, which are more specific and match the SDK names + are not available on Xcode < 7.0. - Change-Id: I8ab2fe152099e849b211b5b19e4ef9f03d8e7f1c + Change-Id: I2f07a0365183d2781157cdb05fd49b30ae001ac5 -commit 46b8461fd010c1e7ffce6bb2bdf8a84b659d5e09 -Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Mon Sep 29 15:10:58 2014 -0700 +commit 26cd5326a1fb99ae02c667eab9942e1308046984 +Author: Alex Stewart <alexs.mac@gmail.com> +Date: Mon Sep 21 10:16:01 2015 +0100 - Various minor fixes from William Rucklidge. + Add gtest-specific flags when building/using as a shared library. + + - Currently these flags are only used to define the relevant DLL export + prefix for Windows. - Change-Id: Ibe731d5db374ad8ee148d62a9fdd8d726b607a3f + Change-Id: I0c05207b512cb4a985390aefc779b91febdabb38 -commit b44cfdef25f6bf0917a23b3fd65cce38aa6a3362 -Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Mon Sep 29 07:53:54 2014 -0700 +commit c4c79472112a49bc1340da0074af2d15b1c89749 +Author: Alex Stewart <alexs.mac@gmail.com> +Date: Sun Sep 20 18:26:59 2015 +0100 - Let ITERATIVE_SCHUR use an explicit Schur Complement matrix. - - Up till now ITERATIVE_SCHUR evaluates matrix-vector products - between the Schur complement and a vector implicitly by exploiting - the algebraic expression for the Schur complement. - - This cost of this evaluation scales with the number of non-zeros - in the Jacobian. - - For small to medium sized problems there is a sweet spot where - computing the Schur complement is cheap enough that it is much - more efficient to explicitly compute it and use it for evaluating - the matrix-vector products. - - This changes implements support for an explicit Schur complement - in ITERATIVE_SCHUR in combination with the SCHUR_JACOBI preconditioner. - - API wise a new bool Solver::Options::use_explicit_schur_complement - has been added. - - The implementation extends the SparseSchurComplementSolver to use - Conjugate Gradients. - - Example speedup: - - use_explicit_schur_complement = false - - Time (in seconds): - Preprocessor 0.585 - - Residual evaluation 0.319 - Jacobian evaluation 1.590 - Linear solver 25.685 - Minimizer 27.990 - - Postprocessor 0.010 - Total 28.585 + Clean up iOS.cmake to use xcrun/xcodebuild & libtool. - use_explicit_schur_complement = true + - Substantial cleanup of iOS.cmake to use xcrun & xcodebuild to + determine the SDK & tool paths. + - Use libtool -static to link libraries instead of ar + ranlib, which + is not compatible with Xcode 7+, this change should be backwards + compatible to at least Xcode 6. + - Force locations of unordered_map & shared_ptr on iOS to work around + check_cxx_source_compiles() running in a forked CMake instance without + access to the variables (IOS_PLATFORM) defined by the user. + - Minor CMake style updates. - Time (in seconds): - Preprocessor 0.638 - - Residual evaluation 0.318 - Jacobian evaluation 1.507 - Linear solver 5.930 - Minimizer 8.144 - - Postprocessor 0.010 - Total 8.791 - - Which indicates an end-to-end speedup of more than 3x, with the linear - solver being sped up by > 4x. - - The idea to explore this optimization was inspired by the recent paper: - - Mining structure fragments for smart bundle adjustment - L. Carlone, P. Alcantarilla, H. Chiu, K. Zsolt, F. Dellaert - British Machine Vision Conference, 2014 - - which uses a more complicated algorithm to compute parts of the - Schur complement to speed up the matrix-vector product. - - Change-Id: I95324af0ab351faa1600f5204039a1d2a64ae61d + Change-Id: I5f83a60607db34d461ebe85f9dce861f53d98277 -commit 4ad91490827f2ebebcc70d17e63ef653bf06fd0d +commit 155765bbb358f1d19f072a4b54825faf1c059910 Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Wed Sep 24 23:54:18 2014 -0700 +Date: Wed Sep 16 06:56:08 2015 -0700 - Simplify the Block Jacobi and Schur Jacobi preconditioners. - - 1. Extend the implementation of BlockRandomAccessDiagonalMatrix - by adding Invert and RightMultiply methods. + Import the latest version of gtest and gmock. - 2. Simplify the implementation of the Schur Jacobi preconditioner - using these new methods. - - 3. Replace the custom storage used inside Block Jacobi preconditioner - with BlockRandomAccessDiagonalMatrix and simplify its implementation - too. - - Change-Id: I9d4888b35f0f228c08244abbdda5298b3ce9c466 + Change-Id: I4b686c44bba823cab1dae40efa99e31340d2b52a -commit 8f7be1036b853addc33224d97b92412b5a1281b6 -Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Mon Sep 29 08:13:35 2014 -0700 +commit 0c4647b8f1496c97c6b9376d9c49ddc204aa08dd +Author: Alex Stewart <alexs.mac@gmail.com> +Date: Wed Sep 16 20:01:11 2015 +0100 - Fix a formatting error TrustRegionMinimizer logging. + Remove FAQ about increasing inlining threshold for Clang. - Change-Id: Iad1873c51eece46c3fdee1356d154367cfd7925e + - Changing the inlining threshold for Clang as described has a minimal + effect on user performance. + - The problem that originally prompted the belief that it did was + due to an erroneous CXX flag configuration (in user code). + + Change-Id: I03017241c0f87b8dcefb8c984ec3b192afd97fc2 -commit c99872d48e322662ea19efb9010a62b7432687ae +commit f4b768b69afcf282568f9ab3a3f0eb8078607468 Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Wed Sep 24 21:30:02 2014 -0700 +Date: Mon Sep 14 13:53:24 2015 -0700 - Add BlockRandomAccessSparseMatrix::SymmetricRightMultiply. + Lint changes from William Rucklidge - Change-Id: Ib06a22a209b4c985ba218162dfb6bf46bd93169e + Change-Id: I0dac2549a8fa2bfd12f745a8d8a0db623b7ec1ac -commit d3ecd18625ba260e0d00912a305a448b566acc59 +commit 5f2f05c726443e35767d677daba6d25dbc2d7ff8 Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Tue Sep 23 10:12:42 2014 -0700 +Date: Fri Sep 11 22:19:38 2015 -0700 - Add an explicit include for local_parameterization.h + Refactor system_test + + 1. Move common test infrastructure into test_util. + 2. system_test now only contains powells function. + 3. Add bundle_adjustment_test. - Thanks to cooordz for reporting this. + Instead of a single function which computes everything, + there is now a test for each solver configuration which + uses the reference solution computed by the fixture. - Change-Id: I7d345404e362a94ff1eb433ad6b9dcc4960ba76d + Change-Id: I16a9a9a83a845a7aaf28762bcecf1a8ff5aee805 -commit 5dd76869cf45122c79579423f09e0de08cf04092 +commit 1936d47e213142b8bf29d3f548905116092b093d Author: Alex Stewart <alexs.mac@gmail.com> -Date: Fri Sep 19 16:08:25 2014 +0100 +Date: Tue Sep 8 23:27:42 2015 +0100 - Fix unused-function warning with Eigen < 3.2.2. + Revert increased inline threshold (iff Clang) to exported Ceres target. - - CreateBlockJacobian() is only ever used when Eigen >= 3.2.2 is - detected, but was previously defined whenever CERES_USE_EIGEN_SPARSE - was defined with no check on the Eigen version. - - This resulted in an unused-function compile warning that became an - error due to -Werror, preventing compilation when using Eigen < 3.2.2. + - Increasing the inline threshold results in very variable performance + improvements, and could potentially confuse users if they are trying + to set the inline threshold themselves. + - As such, we no longer export our inline threshold configuration for + Clang, but instead document how to change it in the FAQs. - Change-Id: I24628ff329f14b087ece66bf2626bdc0de4ba224 + Change-Id: I88e2e0001e4586ba2718535845ed1e4b1a5b72bc -commit 820cb7b14831aa03eca1e8186000cebfdf0a42f3 +commit a66d89dcda47cefda83758bfb9e7374bec4ce866 Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Wed Sep 17 09:46:08 2014 -0700 +Date: Sat Sep 5 16:50:20 2015 -0700 - Add solver_utils.cc to Android.mk + Get ready for 1.11.0RC1 + + Update version numbers. + Drop CERES_VERSION_ABI macro. - Change-Id: I358522971711280f4362a1fa39b1568160e21e63 + Change-Id: Ib3eadabb318afe206bb196a5221b195d26cbeaa0 -commit 092b94970a073f8b47179d96160226fc19095898 +commit 1ac3dd223c179fbadaed568ac532af4139c75d84 Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Fri Sep 5 11:56:29 2014 -0700 +Date: Sat Sep 5 15:30:01 2015 -0700 - Add GradientProblem and GradientProblemSolver. + Fix a bug in CompressedRowSparseMatrix::AppendRows - The line search minimizer in Ceres does not require that the - problems that is solving is a sum of squares. Over the past - year there have been multiple requests to expose this algorithm - on its own so that it can be used to solve unconstrained - non-linear minimization problems on its own. + The test for CompressedRowSparseMatrix::AppendRows tries to add + a matrix of size zero, which results in an invalid pointer deferencing + even though that pointer is never written to. - With this change, a new optimization problem called - GradientProblem is introduced which is basically a thin - wrapper around a user defined functor that evaluates cost - and gradients (FirstOrderFunction) and an optional LocalParameterization. - - Corresponding to it, a GradientProblemSolver and its associated - options and summary structs are introduced too. - - An example that uses the new API to find the minimum of Rosenbrock's - function is also added. - - Change-Id: I42bf687540da25de991e9bdb00e321239244e8b4 + Change-Id: I97dba37082bd5dad242ae1af0447a9178cd92027 -commit 6c45d6b891aac01489b478a021f99081c61792cb +commit 67622b080c8d37b5e932120a53d4ce76b80543e5 Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Thu Sep 11 07:48:30 2014 -0700 +Date: Sat Sep 5 13:18:38 2015 -0700 - Add more inspection methods to Problem. - - Problem::GetCostFunctionForResidualBlock - Problem::GetLossFunctionForResidualBlock + Fix a pointer access bug in Ridders' algorithm. - are added, so that users do not have to maintain this mapping - outside the Problem. + A pointer to an Eigen matrix was being used as an array. - Change-Id: I38356dfa094b2c7eec90651dafeaf3a33c5f5f56 + Change-Id: Ifaea14fa3416eda5953de49afb78dc5a6ea816eb -commit 6ad9b8e2ae66c9009441d0f9304486ec8dfa9a6a +commit 5742b7d0f14d2d170054623ccfee09ea214b8ed9 Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Tue Sep 9 14:29:28 2014 -0700 +Date: Wed Aug 26 09:24:33 2015 -0700 - Ignore row/column blocks structure when using dynamic sparsity + Improve performance of SPARSE_NORMAL_CHOLESKY + dynamic_sparsity - The row/column blocks can be huge when using dynamic sparsity. This - can result in very large memory usage when augmenting the jacobian - with the LM diagonal. + The outer product computation logic in SparseNormalCholeskySolver + does not work well with dynamic sparsity. The overhead of computing + the sparsity pattern of the normal equations is only amortized if + the sparsity is constant. If the sparsity can change from call to call + SparseNormalCholeskySolver will actually be more expensive. - Thanks to Mingsong Dou for reporting this. - - Change-Id: I6aa140ceefa98389ae17958f89ca76e0c76f95b8 + For Eigen and for CXSparse we now explicitly compute the normal + equations using their respective matrix-matrix product routines and solve. + Change-Id: Ifbd8ed78987cdf71640e66ed69500442526a23d4 -commit 7e43460d42e20be1ba13121655dbbfd0d1c751ae -Author: Martin Baeuml <baeuml@gmail.com> -Date: Mon Sep 8 16:49:06 2014 +0200 +commit d0b6cf657d6ef0dd739e958af9a5768f2eecfd35 +Author: Keir Mierle <mierle@gmail.com> +Date: Fri Sep 4 18:43:41 2015 -0700 - Fix a few typos in the documentation. + Fix incorrect detect structure test - Change-Id: I541db56b2b81ae758e233ce850d78c3cbb4b6fa3 + Change-Id: I7062f3639147c40b57947790d3b18331a39a366b -commit 1aef66eeae7042902655a11b0d6a1a32900abb7b -Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Sun Sep 7 21:18:44 2014 -0700 +commit 0e8264cc47661651a11e2dd8570c210082963545 +Author: Alex Stewart <alexs.mac@gmail.com> +Date: Sat Aug 22 16:23:05 2015 +0100 - Remove errant space. + Add increased inline threshold (iff Clang) to exported Ceres target. - Change-Id: Iedc06960417a9b938d57f623b4beb87a98e3d081 + - When compiled with Clang, Ceres and all of the examples are compiled + with an increased inlining-threshold, as the default value can result + in poor Eigen performance. + - Previously, client code using Ceres would typically not use an + increased inlining-threshold (unless the user has specifically added + it themselves). However, increasing the inlining threshold can result + in significant performance improvements in auto-diffed CostFunctions. + - This patch adds the inlining-threshold flags to the interface flags + for the Ceres CMake target s/t any client code using Ceres (via + CMake), and compiled with Clang, will now be compiled with the same + increased inlining threshold as used by Ceres itself. + + Change-Id: I31e8f1abfda140d22e85bb48aa57f028a68a415e -commit 89080ab153a33008782759187fa8e9af7d2f83f1 -Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Sat Sep 6 21:13:48 2014 -0700 +commit a1b3fce9e0a4141b973f6b4dd9b08c4c13052d52 +Author: Alex Stewart <alexs.mac@gmail.com> +Date: Mon Aug 31 14:14:56 2015 +0100 - Add LocalParameterization::MultiplyByJacobian. - - This is needed to efficiently support LocalParameterization objects - in GradientProblemSolver. + Add optional export of Ceres build directory to new features list. - Change-Id: Ic7b715b8be694b099dc95d6707a67474297533e6 + Change-Id: I6f1e42b41957ae9cc98fd9dcd1969ef64c4cd96f -commit d76da16f49d419ae3664ca1bdc2286c1ea78ebed -Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Sun Sep 7 18:42:49 2014 -0700 +commit e46777d8df068866ef80902401a03e29348d11ae +Author: Alex Stewart <alexs.mac@gmail.com> +Date: Mon Aug 31 12:41:54 2015 +0100 - Move some routines to solver_utils.h/cc - - This moves a couple of routines from solver.cc into solver_utils.h/cc - so that they can also be used by the upcoming GradientProblemSolver. + Credit reporters of buildsystem bugs in version history. - Change-Id: I627b32ad3dc639422aacde78a8e391459d947e99 + Change-Id: I16fe7973534cd556d97215e84268ae0b8ec4e11a -commit cbf03ac292a0c0e9e6b7fcc1b08b67e95965922f +commit 01548282cb620e5e3ac79a63a391cd0afd5433e4 Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Sat Sep 6 21:07:08 2014 -0700 +Date: Sun Aug 30 22:29:27 2015 -0700 - Make LineSearchMinimizer consistent with TrustRegionMinimizer. + Update the version history. - Change the logic for how IterationSummary objects are added to - Summary::iterations to match the one in TrustRegionMinimizer. - - Change-Id: I57851ad8294e58f83b9115cca9c24695d86ee92a + Change-Id: I29873bed31675e0108f1a44f53f7bc68976b7f98 -commit f04c32319751e1efd610acd3699bca0a6dd6c6d1 +commit 2701429f770fce69ed0c77523fa43d7bc20ac6dc Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Sat Sep 6 21:05:41 2014 -0700 +Date: Sun Aug 30 21:33:57 2015 -0700 - Fix some obsolete documentation in CostFunction::Evaluate + Use Eigen::Dynamic instead of ceres::DYNAMIC in numeric_diff.h - Change-Id: I1d7ee5c596fbf6a4d886dce5b989c8eb18af2dce + Change-Id: Iccb0284a8fb4c2160748dfae24bcd595f1d4cb5c -commit 9263547c02a1807532b159c217e7acd124d3db10 -Author: Johannes Schönberger <hannesschoenberger@gmail.com> -Date: Sat Sep 6 17:26:15 2014 -0400 +commit 4f049db7c2a3ee8cf9910c6eac96be6a28a5999c +Author: Tal Ben-Nun <tbennun@gmail.com> +Date: Wed May 13 15:43:51 2015 +0300 - Fix CG solver options for ITERATIVE_SCHUR, which did not copy min_num_iterations + Adaptive numeric differentiation using Ridders' method. - Change-Id: If31bc53b49ec20426fd438b79b8fa1f69d11e861 - -commit b41f048256d1a8184cbe874b5a96dffa7fa4630d -Author: Martin Baeuml <baeuml@gmail.com> -Date: Fri Sep 5 15:03:32 2014 +0200 - - Remove obsolete include of numeric_diff_functor.h. + This method numerically computes function derivatives in different + scales, extrapolating between intermediate results to conserve function + evaluations. Adaptive differentiation is essential to produce accurate + results for functions with noisy derivatives. - numeric_diff_functor.h was removed and does not exist anymore. + Full changelist: + -Created a new type of NumericDiffMethod (RIDDERS). + -Implemented EvaluateRiddersJacobianColumn in NumericDiff. + -Created unit tests with f(x) = x^2 + [random noise] and + f(x) = exp(x). - Change-Id: I07bf04bf81142551e867b95b83a0653e11cad54c + Change-Id: I2d6e924d7ff686650272f29a8c981351e6f72091 -commit b7fb6056a717cc3c372cfb7115c527ee8bc05ddb +commit 070bba4b43b4b7449628bf456a10452fd2b34d28 Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Wed Sep 3 11:19:02 2014 -0700 +Date: Tue Aug 25 13:37:33 2015 -0700 - Remove NumericDiffFunctor. + Lint fixes from William Rucklidge - Its API was broken, and its implementation was an unnecessary - layer of abstraction over CostFunctionToFunctor. - - Change-Id: I18fc261fc6a3620b51a9eeb4dde0af03d753af69 + Change-Id: I719e8852859c970091df842e59c44e02e2c65827 -commit 175fa8ff09049110a8509409f60cee5fd52cdbe6 -Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Tue Sep 2 06:49:08 2014 -0700 +commit 887a20ca7f02a1504e35f7cabbdfb2e0842a0b0b +Author: Alex Stewart <alexs.mac@gmail.com> +Date: Wed Aug 12 21:41:43 2015 +0100 - CostFunctionToFunctor allows dynamic number of residuals. + Build position independent code when compiling Ceres statically. - The code itself was perfectly capable of handling residuals, but there - was an overly strict runtime check that had to be removed. + - Previously, when Ceres was built as a static library we did not + compile position independent code. This means that the resulting + static library could not be linked against shared libraries, but + could be used by executables. + - To enable the use of a static Ceres library by other shared libraries + as reported in [1], the static library must be generated from + position independent code (except on Windows, where PIC does not + apply). - Thanks to Domink Reitzle for reporting this. + [1] https://github.com/Itseez/opencv_contrib/pull/290#issuecomment-130389471 - Change-Id: I6a6d000a7c5203dd5945a61b4caeda1b8aeb09c9 + Change-Id: I99388f1784ece688f91b162d009578c5c97ddaf6 -commit 70ace0d5a5601901288974fcf27919754260cf0e -Author: Johannes Schönberger <hannesschoenberger@gmail.com> -Date: Sat Aug 30 15:52:34 2014 -0400 - - Fix max. linear solver iterations in ConjugateGradientsSolver - - Change-Id: Ice0cef46441dbc1c121eeb42113667a46c96936f - -commit c5d8d0680250f5eb554577d30d28fc805b03fab9 +commit 860bba588b981a5718f6b73e7e840e5b8757fe65 Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Fri Aug 29 20:31:19 2014 -0700 +Date: Tue Aug 25 09:43:21 2015 -0700 - Fix a unused function error with Eigen version 3.2.1 or less. + Fix a bug in DetectStructure - Thanks to Johannes Schoenberger for reporting this. + The logic for determing static/dynamic f-block size in + DetectStructure was broken in a corner case, where the very first + row block which was used to initialize the f_block_size contained + more than one f blocks of varying sizes. The way the if block + was structured, no iteration was performed on the remaining + f-blocks and the loop failed to detect that the f-block size + was actually changing. - Change-Id: Ie17d28f2a68734a978a8c95007724bc4055de43a - -commit 0e1cc2a55488e4cf381833baaa3531c02ce9d69e -Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Fri Aug 29 09:16:56 2014 -0700 - - Fix the build on Eigen version 3.2.1 and older. + If in the remaining row blocks, there were no row blocks + with varying f-block sizes, the function will erroneously + return a static f-block size. + + Thanks to Johannes Schonberger for providing a reproduction for this + rather tricky corner case. - Change-Id: I18f5cb5d42113737d7b8f78a67acee28bd5b3e08 + Change-Id: Ib442a041d8b7efd29f9653be6a11a69d0eccd1ec -commit 5f96c62b56222f27e606f2246a8a16b6942af8d1 -Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Thu Aug 28 23:06:17 2014 -0700 +commit b0cbc0f0b0a22f01724b7b647a4a94db959cc4e4 +Author: Johannes Schönberger <hannesschoenberger@gmail.com> +Date: Thu Aug 20 14:21:30 2015 -0400 - Add Block AMD ordering for SPARSE_SCHUR + EIGEN_SPARSE. - - Ordering routines for the Schur complement when using EIGEN_SPARSE. - Also integration into SchurComplementSolver. - - Part of this CL is also a refactoring of the block jacobian matrix - construction. + Reduce memory footprint of SubsetParameterization - Change-Id: I11d665cc7d4867c64190e6fed1118f4d2e13d59b + Change-Id: If113cb4696d5aef3e50eed01fba7a3d4143b7ec8 -commit 7344626c04d19ca1dc4871c377c4422c744b1bca -Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Thu Aug 28 22:03:09 2014 -0700 +commit ad2a99777786101411a971e59576ca533a297013 +Author: Sergey Sharybin <sergey.vfx@gmail.com> +Date: Sat Aug 22 11:18:45 2015 +0200 - Let EIGEN_SPARSE + SPARSE_NORMAL_CHOLESKY use block AMD. + Fix for reoder program unit test when built without suitesparse - Modify SparseNormalCholeskySolver to use a pre-ordered Jacobian - matrix. + This commit fixes failure of reorder_program_test when Ceres is built without + any suitesparse. - Change-Id: Ib4d725d7a2d7bb94ea76dbb3a9b172784dbc8ea0 + Change-Id: Ia23ae8dfd20c482cb9cd1301f17edf9a34df3235 -commit 9f7032369ea4e432f0fb507cb6d2209741ee6946 +commit 4bf3868beca9c17615f72ec03730cddb3676acaa Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Thu Aug 28 21:46:43 2014 -0700 +Date: Sun Aug 9 15:24:45 2015 -0700 - Block AMD for SparseNormalCholesky + EIGEN_SPARSE. + Fix a bug in the Schur eliminator - This is just the reordering routine. The integration with - SparseNormalCholesky shall happen in a subsequent CL. + The schur eliminator treats rows with e blocks and row with + no e blocks separately. The template specialization logic only + applies to the rows with e blocks. - Change-Id: I39ddc32aa66b11c368faf75404850fa0ae0d2b3a - -commit b9331cd4077100d645be22a912d5743eeda72878 -Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Thu Aug 28 14:42:27 2014 -0700 - - Cleanup reorder_program.cc + So, in cases where the rows with e-blocks have a fixed size f-block + but the rows without e-blocks have f-blocks of varying sizes, + DetectStructure will return a static f-block size, but we need to be + careful that we do not blindly use that static f-block size everywhere. - Program::SetParameterOffsetsAndIndex() was being called willy nilly. - Now the invariant is that any function that actually reorders the - program, updates the offsets and indices. + This patch fixes a bug where such care was not being taken, where + it was assumed that the static f-block size could be assumed for all + f-block sizes. - Also the logic around handling EIGEN_SPARSE has been simplified in - anticipation of the block AMD code that is forthcoming. + A new test is added, which triggers an exception in debug mode. In + release mode this error does not present itself, due to a peculiarity + of the way Eigen works. - Last but not the least, num_eliminate_blocks, which is a rather - cryptic name to begin with has been replaced by the more meaningful - size_of_first_elimination_group. + Thanks to Werner Trobin for reporting this bug. - Change-Id: I77e684f699a93b53e76aa406d64f40f8704df813 + Change-Id: I8ae7aabf8eed8c3f9cf74b6c74d632ba44f82581 -commit 79491a3f4a3939a3cce4644da7a998b7782b963a +commit 1635ce726078f00264b89d7fb6e76fd1c2796e59 Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Thu Aug 28 13:57:50 2014 -0700 +Date: Wed Aug 19 00:26:02 2015 -0700 - Solver::FullReport now reports build config. + Fix a bug in the reordering code. - The header of Summary::FullReport now looks like + When the user provides an ordering which starts at a non-zero group id, + or has gaps in the groups, then CAMD, the algorithm used to reorder + the program can crash or return garbage results. - Solver Summary (v 1.10.0-suitesparse-cxsparse-lapack-no_openmp) + The solution is to map the ordering into grouping constraints, and then + to re-number the groups to be contiguous using a call to + MapValuesToContiguousRange. This was already done for CAMD based + ordering for Schur type solvers, but was not done for SPARSE_NORMAL_CHOLESKY. - Original Reduced - Parameter blocks 22122 22122 - Parameters 66462 66462 - Residual blocks 83718 83718 - Residual 167436 167436 + Thanks to Bernhard Zeisl for not only reporting the bug but also + providing a reproduction. - Change-Id: Id1b81bbf90ba412d19e2dd3687eeb9d372b72c1b + Change-Id: I5cfae222d701dfdb8e1bda7f0b4670a30417aa89 -commit 48068c753e91d77f6c96ef2d529a27ef8ee3947c -Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Thu Aug 28 13:03:40 2014 -0700 +commit 4c3f8987e7f0c51fd367cf6d43d7eb879e79589f +Author: Simon Rutishauser <simon.rutishauser@pix4d.com> +Date: Thu Aug 13 11:10:44 2015 +0200 - Lint cleanup from William Rucklidge. + Add missing CERES_EXPORT to ComposedLoss - Change-Id: Ie0e0aa58440be7a4f67dcd633dbb6f1bb0c051a8 + Change-Id: Id7db388d41bf53e6e5704039040c9d2c6bf4c29c -commit 6a51b135e6298e8ba44a58cc2b54a170ab61a82f +commit 1a740cc787b85b883a0703403a99fe49662acb79 Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Thu Aug 28 10:48:29 2014 -0700 +Date: Tue Aug 11 18:08:05 2015 -0700 - Fix solver_test.cc + Add the option to use numeric differentiation to nist and more_garbow_hillstrom - When Eigen is not installed, Solver::IsValid was not detecting - it correctly. - - Change-Id: Id285a84d829a9e20bc5de663adfca66ac31e08f3 + Change-Id: If0a5caef90b524dcf5e2567c5b681987f5459401 -commit 62a8d64453ee41dae56710a4eead3fadf2fe1a4e -Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Wed Aug 27 22:54:00 2014 -0700 +commit ea667ede5c038d6bf3d1c9ec3dbdc5072d1beec6 +Author: Alex Stewart <alexs.mac@gmail.com> +Date: Sun Aug 9 16:56:13 2015 +0100 - Expand check for lack of a sparse linear algebra library. - - The LinearSolver factory was creating a NULL linear solver - if only Eigen's sparse linear algebra backend was available. + Fix EIGENSPARSE option help s/t it displays in CMake ncurses GUI. - Thanks to Michael Samples and Domink Reitzle for reporting this. + - Shorten description for EIGENSPARSE to a single line, as otherwise + it is not correctly displayed in the ncurses CMake GUI. + - Made explicit in description that this results in an LGPL licensed + version of Ceres (this is also made clear in the CMake log output if + EIGENSPARSE is enabled). - Change-Id: I35e3a6c0fd0da2a31934adb5dfe4cad29577cc73 + Change-Id: I11678a9cbc7a817133c22128da01055a3cb8a26d -commit 12eb389b4ec4113a2260c1a192a1d3f8d1b6a2d3 -Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Wed Aug 27 22:18:33 2014 -0700 +commit a14ec27fb28ab2e8d7f1c9d88e41101dc6c0aab5 +Author: Richard Stebbing <richie.stebbing@gmail.com> +Date: Fri Aug 7 08:42:03 2015 -0700 - Fix Eigen Row/ColMajor bug in NumericDiffCostFunction. + Fix SparseNormalCholeskySolver with dynamic sparsity. - If the parameter block size is 1, asking Eigen to create - a row-major matrix triggers a compile time error. Previously - we were handling the case where the number of rows in the - jacobian block was known statically, but the problem is present - when the nummber of rows is dynamic. + The previous implementation incorrectly cached the outer product matrix + pattern even when `dynamic_sparsity = true`. - This CL fixes this problem. + Change-Id: I1e58315a9b44f2f457d07c56b203ab2668bfb8a2 + +commit 3dd7fced44ff00197fa9fcb1f2081d12be728062 +Author: Alex Stewart <alexs.mac@gmail.com> +Date: Sun Aug 9 16:38:50 2015 +0100 + + Remove legacy dependency detection macros. - Thanks to Dominik Reitzle for reporting this. + - Before the new CMake buildsystem in 1.8, Ceres used non-standard + HINTS variables for dependencies. For backwards compatibility CMake + macros were added to translate these legacy variables into the new + (standard) variables. + - As it has now been multiple releases since the legacy variables + were used and they no longer appear in any of the documentation + support for them has now expired. - Change-Id: I99c3eec3558e66ebf4efa51c4dee8ce292ffe0c1 + Change-Id: I2cc72927ed711142ba7943df334ee008181f86a2 -commit 6c25185bb1643d8d0f3d8e1a7b82a058156aa869 +commit 8b32e258ccce1eed2a50bb002add16cad13aff1e Author: Alex Stewart <alexs.mac@gmail.com> -Date: Thu Aug 28 16:07:51 2014 +0100 +Date: Sun Aug 9 15:42:39 2015 +0100 - Fix crash in Covariance if # threads > 1 requested without OpenMP. + Fix failed if() condition expansion if gflags is not found. - - Previously if options.num_threads > 1 was given to Covariance compiled - without OpenMP, a CHECK() would be triggered in program_evalutor. + - If a CMake-ified version of gflags is not detected, then + gflags_LIBRARIES is not set and the TARGET condition within a + multiconditional if() statement prevents configuration. - Change-Id: Iaade4f5ed5326b0c59a7014c750c41ee026e1124 + Change-Id: Ia92e97523d7a1478ab36539726b9540d7cfee5d0 -commit 6f89d850fb4ace0104abccf467c4fe37ad378b79 -Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Wed Aug 27 11:51:50 2014 -0700 +commit cc8d47aabb9d63ba4588ba7295058a6191c2df83 +Author: Alex Stewart <alexs.mac@gmail.com> +Date: Sun Aug 9 15:18:42 2015 +0100 - Further build breakage fixes. + Update all CMake to lowercase function name style. - 1. Allow the minimum number of linear solver iterations to be zero. - 2. Fix conjugate gradients solver's iteration loop to be sane again. + - Updated to new CMake style where function names are all lowercase, + this will be backwards compatible as CMake function names are + case insensitive. + - Updated using Emacs' M-x unscreamify-cmake-buffer. - Change-Id: I8594815fec940c2b30e28eb58ec5d8baacf13dae + Change-Id: If7219816f560270e59212813aeb021353a64a0e2 -commit dd596d0f0d6d08951efc2c11a639b546db2080c6 -Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Wed Aug 27 11:26:50 2014 -0700 +commit 1f106904c1f47460c35ac03258d6506bb2d60838 +Author: Alex Stewart <alexs.mac@gmail.com> +Date: Sun Aug 9 14:55:02 2015 +0100 - Fix the broken build. + Update minimum iOS version to 7.0 for shared_ptr/unordered_map. + + - In order to correctly detect shared_ptr (& unordered_map) + the iOS version must be >= 7.0 (Xcode 5.0+). This only affects the + SIMULATOR(64) platform builds, as the OS (device) build uses the + latest SDK which is now likely 8.0+. - Change-Id: I083cf1cca1bf4cca956193022d450364e73f833a + Change-Id: Iefec8f03408b8cdc7a495f442ebba081f800adb0 -commit d906afae22b05b9b9a9a2657924f4c0bf1a9b5ea -Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Mon Aug 25 22:32:38 2014 -0700 +commit 16ecd40523a408e7705c9fdb0e159cef2007b8ab +Author: Alex Stewart <alexs.mac@gmail.com> +Date: Sat Aug 8 17:32:31 2015 +0100 - A number of bug fixes. + Fix bug in gflags' <= 2.1.2 exported CMake configuration. - 1. Fix a build breakage in graph_test. - 2. Respect Solver::Options::min_num_linear_solver_iterations in - conjugate_gradients_solver.cc + - gflags <= 2.1.2 has a bug in its exported gflags-config.cmake: + https://github.com/gflags/gflags/issues/110 whereby it sets + gflags_LIBRARIES to a non-existent 'gflags' target. + - This causes linker errors if gflags is installed in a non-standard + location (as otherwise CMake resolves gflags to -lgflags which + links if gflags is installed somewhere on the current path). + - We now check for this case, and search for the correct gflags imported + target and update gflags_LIBRARIES to reference it if found, otherwise + proceed on to the original manual search to try to find gflags. - Thanks to Johannes Schönberger for reporting these. - - Change-Id: Ib32e3929bf5d92dd576ae5b53d4d88797095136e + Change-Id: Iceccc3ee53c7c2010e41cc45255f966e7b13d526 -commit dab955928c6d0942d6acc5b5f1c4c11260d0767d -Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Sun Aug 17 13:14:50 2014 -0700 +commit 56be8de007dfd65ed5a31c795eb4a08ad765f411 +Author: Alex Stewart <alexs.mac@gmail.com> +Date: Thu Jun 25 21:31:00 2015 +0100 - Add an unweighted graph. - - Rename Graph -> WeightedGraph. - Add a new Graph class, which is cheaper to construct and - work with if the weights are not needed. + Add docs for new CXX11 option & mask option for Windows. - This cuts down the cost of building the Hessian graph - significantly. + - The CXX11 option has no effect on Windows, as there, any new C++11 + features are enabled by default, as such to avoid confusion we only + present the option for non-Windows. - Change-Id: Id0cfc81dd2c0bb5ff8f63a1b55aa133c53c0c869 + Change-Id: I38925ae3bb8c16682d404468ba95c611a519b9b9 -commit a0c282adbd268c2ad82551fab31fe1cf8d0c4282 +commit cf863b6415ac4dbf3626e70adeac1ac0f3d87ee5 Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Sun Aug 24 22:19:03 2014 -0700 +Date: Thu Aug 6 14:52:18 2015 -0700 - Add EIGEN_STRONG_INLINE annotation to jet.h + Remove the spec file needed for generating RPMs. - This improves performance when using MSVC on Windows. On GCC - there will be no effect. + Now that ceres is part of RawHide, there is no need to carry + this spec file with the ceres distribution. - Change-Id: I555a81ff6823c2855d64773073f75af50c48d716 + Change-Id: Icc400b9874ba05ba05b353e2658f1de94c72299e -commit 20de0a7793c574e964350a623446136889f74632 -Author: Björn Piltz <bjornpiltz@gmail.com> -Date: Mon Aug 25 17:05:54 2014 +0200 +commit 560940fa277a469c1ab34f1aa303ff1af9c3cacf +Author: Sameer Agarwal <sameeragarwal@google.com> +Date: Sat Jul 11 22:21:31 2015 -0700 - Fixed Malformed regex + A refactor of the cubic interpolation code - I got the following error with MSVC: - Syntax error at index 9 in simple regular expression "NumGroups()": '(' is unsupported. + 1. Push the boundary handling logic into the underlying array + object. This has two very significant impacts: - Change-Id: Id1952831d81d3eb5d73bbed8c311914c4c8ab51f + a. The interpolation code becomes extremely simple to write + and to test. + + b. The user has more flexibility in implementing how out of bounds + values are handled. We provide one default implementation. + + Change-Id: Ic2f6cf9257ce7110c62e492688e5a6c8be1e7df2 -commit ccf8aea988269841d84d746e52164d5056c67a10 -Author: Björn Piltz <bjornpiltz@gmail.com> -Date: Mon Aug 25 16:16:01 2014 +0200 +commit dfdf19e111c2b0e6daeb6007728ec2f784106d49 +Author: Sameer Agarwal <sameeragarwal@google.com> +Date: Wed Aug 5 15:20:57 2015 -0700 - Fixed MSVC error C2124: divide or mod by zero - - Alternatively, if quiet_NaN is not available on all platforms a workaround would be: - volatile double zero = 0.0; - double x = 1.0/zero; - The 'volatile' is needed to shut up "warning C4723: potential divide by 0". + Lint cleanup from Jim Roseborough - Change-Id: If2bbdab8540595aa2e0079e1eb6b6fed6d4a6ef7 + Change-Id: Id6845c85644d40e635ed196ca74fc51a387aade4 -commit 8de27be218d42b282d7f15867733ad07058b0887 +commit 7444f23ae245476a7ac8421cc2f88d6947fd3e5f Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Tue Aug 19 08:22:40 2014 -0700 +Date: Mon Aug 3 12:22:44 2015 -0700 - Fix a bug in TrustRegionPreprocessor + Fix a typo in small_blas.h - TrustRegionPreprocessor was not setting Minimizer::Options::is_constrained. - This meant that the line search for bounds constraints was not being - invoked for bounds constrained problems. + The reason this rather serious looking typo has not + caused any problems uptil now is because NUM_ROW_B is + computed but never actually used. - And some minor lint cleanup. + Thanks to Werner Trobin for pointing this out. - Change-Id: I18852cfaf1b33fd90b7d8c196f2063c128126658 + Change-Id: Id2b4d9326ec21baec8a85423e3270aefbafb611e -commit 1745dd615b3897a3ef9896acfdba67eee1739bf4 -Author: Sameer Agarwal <sameeragarwal@google.com> -Date: Thu Jun 5 21:30:13 2014 -0700 +commit 5a48b92123b30a437f031eb24b0deaadc8f60d26 +Author: Alex Stewart <alexs.mac@gmail.com> +Date: Sat Jul 4 17:59:52 2015 +0100 - Refactor SolverImpl. - - Replace SolverImpl with + Export Ceres build directory into local CMake package registry. - a. A minimizer specific preprocessor class. - b. A generic Solve function inside solver.cc - c. Presummarize and Postsummarize functions to handle - updates to the summary object. + - Optionally use CMake's export() functionality to export the Ceres + build directory as a package into the local CMake package registry. + - This enables the detection & use of Ceres from CMake *without* + requiring that Ceres be installed. - The existing SolverImpl class was a mixture of the above three - things and was increasingly complicated code to follow. This change, - breaks it into its three separate constituents, with the aims of - better separation of concerns and thus better testability and - reliability. + Change-Id: Ib5a7588446f490e1b405878475b6b1dd13accd1f + +commit d9790e77894ea99d38137d359d6118315b2d1601 +Author: Sameer Agarwal <sameeragarwal@google.com> +Date: Sun Jul 12 19:39:47 2015 -0700 + + Add ProductParameterization - The call to Solver::Solve() now consists of + Often a parameter block is the Cartesian product of a number of + manifolds. For example, a rigid transformation SE(3) = SO(3) x R^3 + In such cases, where you have the local parameterization + of the individual manifolds available, + ProductParameterization can be used to construct a local + parameterization of the cartesian product. - 1. Presummarize - summarize the given state of the problem and solver - options. - 2. Preprocess - Setup everything that is needed to call the minimizer. - This includes, removing redundant parameter and residual blocks, - setting up the reordering for the linear solver, creating the - linear solver, evaluator, inner iteration minimizer etc. - 3. Minimize. - 4. Post summarize - summarize the result of the preprocessing and the - solve. + Change-Id: I4b5bcbd2407a38739c7725b129789db5c3d65a20 + +commit 7b4fb69dad49eaefb5d2d47ef0d76f48ad7fef73 +Author: Alex Stewart <alexs.mac@gmail.com> +Date: Sun Jun 28 21:43:46 2015 +0100 + + Cleanup FindGflags & use installed gflags CMake config if present. + + - Split out gflags namespace detection methods: + check_cxx_source_compiles() & regex, into separate functions. + - Use installed/exported gflags CMake configuration (present for + versions >= 2.1) if available, unless user expresses a preference not + to, or specifies search directories, in which case fall back to manual + search for components. + -- Prefer installed gflags CMake configurations over exported gflags + build directories on all OSs. + - Remove custom version of check_cxx_source_compiles() that attempted + to force the build type of the test project. This only worked for + NMake on Windows, not MSVC as msbuild ignored our attempts to force + the build type. Now we always use the regex method on Windows if + we cannot find an installed gflags CMake configuration which works + even on MSVC by bypassing msbuild. + - Add default search paths for gflags on Windows. + + Change-Id: I083b267d97a7a5838a1314f3d41a61ae48d5a2d7 + +commit b3063c047906d4a44503dc0187fdcbbfcdda5f38 +Author: Alex Stewart <alexs.mac@gmail.com> +Date: Wed Jul 15 20:56:56 2015 +0100 + + Add default glog install location on Windows to search paths. - Change-Id: I80f35cfc9f2cbf78f1df4aceace27075779d8a3a + Change-Id: I083d368be48986e6780c11460f5a07b2f3b6c900 diff --git a/extern/libmv/third_party/ceres/SConscript b/extern/libmv/third_party/ceres/SConscript index f53d54ba94b..7b46083f386 100644 --- a/extern/libmv/third_party/ceres/SConscript +++ b/extern/libmv/third_party/ceres/SConscript @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # NOTE: This file is automatically generated by bundle.sh script # If you're doing changes in this file, please update template diff --git a/extern/libmv/third_party/ceres/bundle.sh b/extern/libmv/third_party/ceres/bundle.sh index 0becc87dd4f..0418356c6f4 100755 --- a/extern/libmv/third_party/ceres/bundle.sh +++ b/extern/libmv/third_party/ceres/bundle.sh @@ -129,7 +129,7 @@ set(INC ) set(INC_SYS - ${EIGEN3_INCLUDE_DIRS} + \${EIGEN3_INCLUDE_DIRS} ) set(SRC diff --git a/extern/libmv/third_party/ceres/config/ceres/internal/config.h b/extern/libmv/third_party/ceres/config/ceres/internal/config.h index c9d2c16e865..1cf034ded5f 100644 --- a/extern/libmv/third_party/ceres/config/ceres/internal/config.h +++ b/extern/libmv/third_party/ceres/config/ceres/internal/config.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -30,13 +30,16 @@ // Default (empty) configuration options for Ceres. // -// IMPORTANT: Most users of Ceres will not use this file, when compiling Ceres -// with CMake, CMake will configure a new config.h with the currently -// selected Ceres compile options and copy it into the source -// directory before compilation. However, for some users of Ceres -// who compile without CMake, this file ensures that Ceres will -// compile, with the user either specifying manually the Ceres -// compile options, or passing them directly through the compiler. +// IMPORTANT: Most users of Ceres will not use this file, when +// compiling Ceres with CMake, CMake will configure a new +// config.h with the currently selected Ceres compile +// options in <BUILD_DIR>/config, which will be added to +// the include path for compilation, and installed with the +// public Ceres headers. However, for some users of Ceres +// who compile without CMake (Android), this file ensures +// that Ceres will compile, with the user either specifying +// manually the Ceres compile options, or passing them +// directly through the compiler. #ifndef CERES_PUBLIC_INTERNAL_CONFIG_H_ #define CERES_PUBLIC_INTERNAL_CONFIG_H_ diff --git a/extern/libmv/third_party/ceres/files.txt b/extern/libmv/third_party/ceres/files.txt index d1bd69672c8..976200b6229 100644 --- a/extern/libmv/third_party/ceres/files.txt +++ b/extern/libmv/third_party/ceres/files.txt @@ -157,8 +157,6 @@ internal/ceres/graph_algorithms.h internal/ceres/graph.h internal/ceres/implicit_schur_complement.cc internal/ceres/implicit_schur_complement.h -internal/ceres/incomplete_lq_factorization.cc -internal/ceres/incomplete_lq_factorization.h internal/ceres/integral_types.h internal/ceres/iterative_schur_complement_solver.cc internal/ceres/iterative_schur_complement_solver.h diff --git a/extern/libmv/third_party/ceres/include/ceres/autodiff_cost_function.h b/extern/libmv/third_party/ceres/include/ceres/autodiff_cost_function.h index 7c0fa79ad0b..e7893e4828e 100644 --- a/extern/libmv/third_party/ceres/include/ceres/autodiff_cost_function.h +++ b/extern/libmv/third_party/ceres/include/ceres/autodiff_cost_function.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/include/ceres/autodiff_local_parameterization.h b/extern/libmv/third_party/ceres/include/ceres/autodiff_local_parameterization.h index c100d4825d2..27397e20d3b 100644 --- a/extern/libmv/third_party/ceres/include/ceres/autodiff_local_parameterization.h +++ b/extern/libmv/third_party/ceres/include/ceres/autodiff_local_parameterization.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -33,9 +33,9 @@ #ifndef CERES_PUBLIC_AUTODIFF_LOCAL_PARAMETERIZATION_H_ #define CERES_PUBLIC_AUTODIFF_LOCAL_PARAMETERIZATION_H_ +#include "ceres/local_parameterization.h" #include "ceres/internal/autodiff.h" #include "ceres/internal/scoped_ptr.h" -#include "ceres/local_parameterization.h" namespace ceres { diff --git a/extern/libmv/third_party/ceres/include/ceres/c_api.h b/extern/libmv/third_party/ceres/include/ceres/c_api.h index 71f41fd226b..df7c9b6d671 100644 --- a/extern/libmv/third_party/ceres/include/ceres/c_api.h +++ b/extern/libmv/third_party/ceres/include/ceres/c_api.h @@ -1,6 +1,6 @@ /* Ceres Solver - A fast non-linear least squares minimizer - * Copyright 2013 Google Inc. All rights reserved. - * http://code.google.com/p/ceres-solver/ + * Copyright 2015 Google Inc. All rights reserved. + * http://ceres-solver.org/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/include/ceres/ceres.h b/extern/libmv/third_party/ceres/include/ceres/ceres.h index 7c8981e2994..64ffb99798a 100644 --- a/extern/libmv/third_party/ceres/include/ceres/ceres.h +++ b/extern/libmv/third_party/ceres/include/ceres/ceres.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/include/ceres/conditioned_cost_function.h b/extern/libmv/third_party/ceres/include/ceres/conditioned_cost_function.h index 3f0087c7815..29597d935cb 100644 --- a/extern/libmv/third_party/ceres/include/ceres/conditioned_cost_function.h +++ b/extern/libmv/third_party/ceres/include/ceres/conditioned_cost_function.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -78,7 +78,7 @@ class CERES_EXPORT ConditionedCostFunction : public CostFunction { // functions, or not, depending on the ownership parameter. Conditioners // may be NULL, in which case the corresponding residual is not modified. ConditionedCostFunction(CostFunction* wrapped_cost_function, - const vector<CostFunction*>& conditioners, + const std::vector<CostFunction*>& conditioners, Ownership ownership); virtual ~ConditionedCostFunction(); @@ -88,7 +88,7 @@ class CERES_EXPORT ConditionedCostFunction : public CostFunction { private: internal::scoped_ptr<CostFunction> wrapped_cost_function_; - vector<CostFunction*> conditioners_; + std::vector<CostFunction*> conditioners_; Ownership ownership_; }; diff --git a/extern/libmv/third_party/ceres/include/ceres/cost_function.h b/extern/libmv/third_party/ceres/include/ceres/cost_function.h index fe8fc07d2ce..f051a897c0d 100644 --- a/extern/libmv/third_party/ceres/include/ceres/cost_function.h +++ b/extern/libmv/third_party/ceres/include/ceres/cost_function.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -115,7 +115,7 @@ class CERES_EXPORT CostFunction { double* residuals, double** jacobians) const = 0; - const vector<int32>& parameter_block_sizes() const { + const std::vector<int32>& parameter_block_sizes() const { return parameter_block_sizes_; } @@ -124,7 +124,7 @@ class CERES_EXPORT CostFunction { } protected: - vector<int32>* mutable_parameter_block_sizes() { + std::vector<int32>* mutable_parameter_block_sizes() { return ¶meter_block_sizes_; } @@ -135,7 +135,7 @@ class CERES_EXPORT CostFunction { private: // Cost function signature metadata: number of inputs & their sizes, // number of outputs (residuals). - vector<int32> parameter_block_sizes_; + std::vector<int32> parameter_block_sizes_; int num_residuals_; CERES_DISALLOW_COPY_AND_ASSIGN(CostFunction); }; diff --git a/extern/libmv/third_party/ceres/include/ceres/cost_function_to_functor.h b/extern/libmv/third_party/ceres/include/ceres/cost_function_to_functor.h index b4a516e0ab1..6c67ac0f937 100644 --- a/extern/libmv/third_party/ceres/include/ceres/cost_function_to_functor.h +++ b/extern/libmv/third_party/ceres/include/ceres/cost_function_to_functor.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -29,7 +29,7 @@ // Author: sameeragarwal@google.com (Sameer Agarwal) // // CostFunctionToFunctor is an adapter class that allows users to use -// CostFunction objects in templated functors which are to be used for +// SizedCostFunction objects in templated functors which are to be used for // automatic differentiation. This allows the user to seamlessly mix // analytic, numeric and automatic differentiation. // @@ -37,7 +37,7 @@ // // class IntrinsicProjection : public SizedCostFunction<2, 5, 3> { // public: -// IntrinsicProjection(const double* observations); +// IntrinsicProjection(const double* observation); // virtual bool Evaluate(double const* const* parameters, // double* residuals, // double** jacobians) const; @@ -62,10 +62,8 @@ // Then we can now do the following, // // struct CameraProjection { -// CameraProjection(double* observation) { -// intrinsic_projection_.reset( -// new CostFunctionToFunctor<2, 5, 3>( -// new IntrinsicProjection(observation_))); +// CameraProjection(const double* observation) +// : intrinsic_projection_(new IntrinsicProjection(observation)) { // } // template <typename T> // bool operator()(const T* rotation, @@ -79,11 +77,11 @@ // // Note that we call intrinsic_projection_, just like it was // // any other templated functor. // -// return (*intrinsic_projection_)(intrinsics, transformed_point, residual); +// return intrinsic_projection_(intrinsics, transformed_point, residual); // } // // private: -// scoped_ptr<CostFunctionToFunctor<2,5,3> > intrinsic_projection_; +// CostFunctionToFunctor<2,5,3> intrinsic_projection_; // }; #ifndef CERES_PUBLIC_COST_FUNCTION_TO_FUNCTOR_H_ @@ -93,6 +91,7 @@ #include <vector> #include "ceres/cost_function.h" +#include "ceres/dynamic_cost_function_to_functor.h" #include "ceres/internal/fixed_array.h" #include "ceres/internal/port.h" #include "ceres/internal/scoped_ptr.h" @@ -104,28 +103,29 @@ template <int kNumResiduals, int N5 = 0, int N6 = 0, int N7 = 0, int N8 = 0, int N9 = 0> class CostFunctionToFunctor { public: + // Takes ownership of cost_function. explicit CostFunctionToFunctor(CostFunction* cost_function) - : cost_function_(cost_function) { + : cost_functor_(cost_function) { CHECK_NOTNULL(cost_function); CHECK(kNumResiduals > 0 || kNumResiduals == DYNAMIC); // This block breaks the 80 column rule to keep it somewhat readable. CHECK((!N1 && !N2 && !N3 && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || ((N1 > 0) && !N2 && !N3 && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && !N3 && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && !N5 && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && (N8 > 0) && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && (N8 > 0) && (N9 > 0))) + ((N1 > 0) && (N2 > 0) && !N3 && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && !N5 && !N6 && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && !N6 && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && (N8 > 0) && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && (N8 > 0) && (N9 > 0))) // NOLINT << "Zero block cannot precede a non-zero block. Block sizes are " << "(ignore trailing 0s): " << N0 << ", " << N1 << ", " << N2 << ", " << N3 << ", " << N4 << ", " << N5 << ", " << N6 << ", " << N7 << ", " << N8 << ", " << N9; - const vector<int32>& parameter_block_sizes = + const std::vector<int32>& parameter_block_sizes = cost_function->parameter_block_sizes(); const int num_parameter_blocks = (N0 > 0) + (N1 > 0) + (N2 > 0) + (N3 > 0) + (N4 > 0) + @@ -160,7 +160,7 @@ class CostFunctionToFunctor { CHECK_EQ(N8, 0); CHECK_EQ(N9, 0); - return cost_function_->Evaluate(&x0, residuals, NULL); + return cost_functor_(&x0, residuals); } bool operator()(const double* x0, @@ -179,7 +179,7 @@ class CostFunctionToFunctor { internal::FixedArray<const double*> parameter_blocks(2); parameter_blocks[0] = x0; parameter_blocks[1] = x1; - return cost_function_->Evaluate(parameter_blocks.get(), residuals, NULL); + return cost_functor_(parameter_blocks.get(), residuals); } bool operator()(const double* x0, @@ -200,7 +200,7 @@ class CostFunctionToFunctor { parameter_blocks[0] = x0; parameter_blocks[1] = x1; parameter_blocks[2] = x2; - return cost_function_->Evaluate(parameter_blocks.get(), residuals, NULL); + return cost_functor_(parameter_blocks.get(), residuals); } bool operator()(const double* x0, @@ -223,7 +223,7 @@ class CostFunctionToFunctor { parameter_blocks[1] = x1; parameter_blocks[2] = x2; parameter_blocks[3] = x3; - return cost_function_->Evaluate(parameter_blocks.get(), residuals, NULL); + return cost_functor_(parameter_blocks.get(), residuals); } bool operator()(const double* x0, @@ -248,7 +248,7 @@ class CostFunctionToFunctor { parameter_blocks[2] = x2; parameter_blocks[3] = x3; parameter_blocks[4] = x4; - return cost_function_->Evaluate(parameter_blocks.get(), residuals, NULL); + return cost_functor_(parameter_blocks.get(), residuals); } bool operator()(const double* x0, @@ -275,7 +275,7 @@ class CostFunctionToFunctor { parameter_blocks[3] = x3; parameter_blocks[4] = x4; parameter_blocks[5] = x5; - return cost_function_->Evaluate(parameter_blocks.get(), residuals, NULL); + return cost_functor_(parameter_blocks.get(), residuals); } bool operator()(const double* x0, @@ -304,7 +304,7 @@ class CostFunctionToFunctor { parameter_blocks[4] = x4; parameter_blocks[5] = x5; parameter_blocks[6] = x6; - return cost_function_->Evaluate(parameter_blocks.get(), residuals, NULL); + return cost_functor_(parameter_blocks.get(), residuals); } bool operator()(const double* x0, @@ -335,7 +335,7 @@ class CostFunctionToFunctor { parameter_blocks[5] = x5; parameter_blocks[6] = x6; parameter_blocks[7] = x7; - return cost_function_->Evaluate(parameter_blocks.get(), residuals, NULL); + return cost_functor_(parameter_blocks.get(), residuals); } bool operator()(const double* x0, @@ -368,7 +368,7 @@ class CostFunctionToFunctor { parameter_blocks[6] = x6; parameter_blocks[7] = x7; parameter_blocks[8] = x8; - return cost_function_->Evaluate(parameter_blocks.get(), residuals, NULL); + return cost_functor_(parameter_blocks.get(), residuals); } bool operator()(const double* x0, @@ -403,7 +403,7 @@ class CostFunctionToFunctor { parameter_blocks[7] = x7; parameter_blocks[8] = x8; parameter_blocks[9] = x9; - return cost_function_->Evaluate(parameter_blocks.get(), residuals, NULL); + return cost_functor_(parameter_blocks.get(), residuals); } template <typename JetT> @@ -418,7 +418,7 @@ class CostFunctionToFunctor { CHECK_EQ(N7, 0); CHECK_EQ(N8, 0); CHECK_EQ(N9, 0); - return EvaluateWithJets(&x0, residuals); + return cost_functor_(&x0, residuals); } template <typename JetT> @@ -438,7 +438,7 @@ class CostFunctionToFunctor { internal::FixedArray<const JetT*> jets(2); jets[0] = x0; jets[1] = x1; - return EvaluateWithJets(jets.get(), residuals); + return cost_functor_(jets.get(), residuals); } template <typename JetT> @@ -460,7 +460,7 @@ class CostFunctionToFunctor { jets[0] = x0; jets[1] = x1; jets[2] = x2; - return EvaluateWithJets(jets.get(), residuals); + return cost_functor_(jets.get(), residuals); } template <typename JetT> @@ -484,7 +484,7 @@ class CostFunctionToFunctor { jets[1] = x1; jets[2] = x2; jets[3] = x3; - return EvaluateWithJets(jets.get(), residuals); + return cost_functor_(jets.get(), residuals); } template <typename JetT> @@ -510,7 +510,7 @@ class CostFunctionToFunctor { jets[2] = x2; jets[3] = x3; jets[4] = x4; - return EvaluateWithJets(jets.get(), residuals); + return cost_functor_(jets.get(), residuals); } template <typename JetT> @@ -538,7 +538,7 @@ class CostFunctionToFunctor { jets[3] = x3; jets[4] = x4; jets[5] = x5; - return EvaluateWithJets(jets.get(), residuals); + return cost_functor_(jets.get(), residuals); } template <typename JetT> @@ -568,7 +568,7 @@ class CostFunctionToFunctor { jets[4] = x4; jets[5] = x5; jets[6] = x6; - return EvaluateWithJets(jets.get(), residuals); + return cost_functor_(jets.get(), residuals); } template <typename JetT> @@ -600,7 +600,7 @@ class CostFunctionToFunctor { jets[5] = x5; jets[6] = x6; jets[7] = x7; - return EvaluateWithJets(jets.get(), residuals); + return cost_functor_(jets.get(), residuals); } template <typename JetT> @@ -634,7 +634,7 @@ class CostFunctionToFunctor { jets[6] = x6; jets[7] = x7; jets[8] = x8; - return EvaluateWithJets(jets.get(), residuals); + return cost_functor_(jets.get(), residuals); } template <typename JetT> @@ -670,79 +670,11 @@ class CostFunctionToFunctor { jets[7] = x7; jets[8] = x8; jets[9] = x9; - return EvaluateWithJets(jets.get(), residuals); + return cost_functor_(jets.get(), residuals); } private: - template <typename JetT> - bool EvaluateWithJets(const JetT** inputs, JetT* output) const { - const int kNumParameters = N0 + N1 + N2 + N3 + N4 + N5 + N6 + N7 + N8 + N9; - const vector<int32>& parameter_block_sizes = - cost_function_->parameter_block_sizes(); - const int num_parameter_blocks = parameter_block_sizes.size(); - const int num_residuals = cost_function_->num_residuals(); - - internal::FixedArray<double> parameters(kNumParameters); - internal::FixedArray<double*> parameter_blocks(num_parameter_blocks); - internal::FixedArray<double> jacobians(num_residuals * kNumParameters); - internal::FixedArray<double*> jacobian_blocks(num_parameter_blocks); - internal::FixedArray<double> residuals(num_residuals); - - // Build a set of arrays to get the residuals and jacobians from - // the CostFunction wrapped by this functor. - double* parameter_ptr = parameters.get(); - double* jacobian_ptr = jacobians.get(); - for (int i = 0; i < num_parameter_blocks; ++i) { - parameter_blocks[i] = parameter_ptr; - jacobian_blocks[i] = jacobian_ptr; - for (int j = 0; j < parameter_block_sizes[i]; ++j) { - *parameter_ptr++ = inputs[i][j].a; - } - jacobian_ptr += num_residuals * parameter_block_sizes[i]; - } - - if (!cost_function_->Evaluate(parameter_blocks.get(), - residuals.get(), - jacobian_blocks.get())) { - return false; - } - - // Now that we have the incoming Jets, which are carrying the - // partial derivatives of each of the inputs w.r.t to some other - // underlying parameters. The derivative of the outputs of the - // cost function w.r.t to the same underlying parameters can now - // be computed by applying the chain rule. - // - // d output[i] d output[i] d input[j] - // -------------- = sum_j ----------- * ------------ - // d parameter[k] d input[j] d parameter[k] - // - // d input[j] - // -------------- = inputs[j], so - // d parameter[k] - // - // outputJet[i] = sum_k jacobian[i][k] * inputJet[k] - // - // The following loop, iterates over the residuals, computing one - // output jet at a time. - for (int i = 0; i < num_residuals; ++i) { - output[i].a = residuals[i]; - output[i].v.setZero(); - - for (int j = 0; j < num_parameter_blocks; ++j) { - const int32 block_size = parameter_block_sizes[j]; - for (int k = 0; k < parameter_block_sizes[j]; ++k) { - output[i].v += - jacobian_blocks[j][i * block_size + k] * inputs[j][k].v; - } - } - } - - return true; - } - - private: - internal::scoped_ptr<CostFunction> cost_function_; + DynamicCostFunctionToFunctor cost_functor_; }; } // namespace ceres diff --git a/extern/libmv/third_party/ceres/include/ceres/covariance.h b/extern/libmv/third_party/ceres/include/ceres/covariance.h index 35fde4de05d..dd20dc36ba1 100644 --- a/extern/libmv/third_party/ceres/include/ceres/covariance.h +++ b/extern/libmv/third_party/ceres/include/ceres/covariance.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -183,7 +183,7 @@ class CovarianceImpl; // Covariance::Options options; // Covariance covariance(options); // -// vector<pair<const double*, const double*> > covariance_blocks; +// std::vector<std::pair<const double*, const double*> > covariance_blocks; // covariance_blocks.push_back(make_pair(x, x)); // covariance_blocks.push_back(make_pair(y, y)); // covariance_blocks.push_back(make_pair(x, y)); @@ -353,10 +353,11 @@ class CERES_EXPORT Covariance { // Covariance::Options for more on the conditions under which this // function returns false. bool Compute( - const vector<pair<const double*, const double*> >& covariance_blocks, + const std::vector<std::pair<const double*, + const double*> >& covariance_blocks, Problem* problem); - // Return the block of the covariance matrix corresponding to + // Return the block of the cross-covariance matrix corresponding to // parameter_block1 and parameter_block2. // // Compute must be called before the first call to @@ -373,6 +374,26 @@ class CERES_EXPORT Covariance { const double* parameter_block2, double* covariance_block) const; + // Return the block of the cross-covariance matrix corresponding to + // parameter_block1 and parameter_block2. + // Returns cross-covariance in the tangent space if a local + // parameterization is associated with either parameter block; + // else returns cross-covariance in the ambient space. + // + // Compute must be called before the first call to + // GetCovarianceBlock and the pair <parameter_block1, + // parameter_block2> OR the pair <parameter_block2, + // parameter_block1> must have been present in the vector + // covariance_blocks when Compute was called. Otherwise + // GetCovarianceBlock will return false. + // + // covariance_block must point to a memory location that can store a + // parameter_block1_local_size x parameter_block2_local_size matrix. The + // returned covariance will be a row-major matrix. + bool GetCovarianceBlockInTangentSpace(const double* parameter_block1, + const double* parameter_block2, + double* covariance_block) const; + private: internal::scoped_ptr<internal::CovarianceImpl> impl_; }; diff --git a/extern/libmv/third_party/ceres/include/ceres/crs_matrix.h b/extern/libmv/third_party/ceres/include/ceres/crs_matrix.h index d2d62894194..23687c4670e 100644 --- a/extern/libmv/third_party/ceres/include/ceres/crs_matrix.h +++ b/extern/libmv/third_party/ceres/include/ceres/crs_matrix.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -74,9 +74,9 @@ struct CERES_EXPORT CRSMatrix { // cols = [ 1, 3, 1, 2, 3, 0, 1] // values = [10, 4, 2, -3, 2, 1, 2] - vector<int> cols; - vector<int> rows; - vector<double> values; + std::vector<int> cols; + std::vector<int> rows; + std::vector<double> values; }; } // namespace ceres 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 f9342cdbab9..e6d26111f18 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 @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -120,18 +120,18 @@ class DynamicAutoDiffCostFunction : public CostFunction { 0); // Allocate scratch space for the strided evaluation. - vector<Jet<double, Stride> > input_jets(num_parameters); - vector<Jet<double, Stride> > output_jets(num_residuals()); + std::vector<Jet<double, Stride> > input_jets(num_parameters); + std::vector<Jet<double, Stride> > output_jets(num_residuals()); // Make the parameter pack that is sent to the functor (reused). - vector<Jet<double, Stride>* > jet_parameters(num_parameter_blocks, + std::vector<Jet<double, Stride>* > jet_parameters(num_parameter_blocks, static_cast<Jet<double, Stride>* >(NULL)); int num_active_parameters = 0; // To handle constant parameters between non-constant parameter blocks, the // start position --- a raw parameter index --- of each contiguous block of // non-constant parameters is recorded in start_derivative_section. - vector<int> start_derivative_section; + std::vector<int> start_derivative_section; bool in_derivative_section = false; int parameter_cursor = 0; diff --git a/extern/libmv/third_party/ceres/include/ceres/dynamic_cost_function_to_functor.h b/extern/libmv/third_party/ceres/include/ceres/dynamic_cost_function_to_functor.h new file mode 100644 index 00000000000..9339a503ea0 --- /dev/null +++ b/extern/libmv/third_party/ceres/include/ceres/dynamic_cost_function_to_functor.h @@ -0,0 +1,190 @@ +// Ceres Solver - A fast non-linear least squares minimizer +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ +// +// 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) +// dgossow@google.com (David Gossow) +// +// DynamicCostFunctionToFunctor allows users to use CostFunction +// objects in templated functors which are to be used for automatic +// differentiation. It works similar to CostFunctionToFunctor, with the +// difference that it allows you to wrap a cost function with dynamic numbers +// of parameters and residuals. +// +// For example, let us assume that +// +// class IntrinsicProjection : public CostFunction { +// public: +// IntrinsicProjection(const double* observation); +// virtual bool Evaluate(double const* const* parameters, +// double* residuals, +// double** jacobians) const; +// }; +// +// is a cost function that implements the projection of a point in its +// local coordinate system onto its image plane and subtracts it from +// the observed point projection. It can compute its residual and +// either via analytic or numerical differentiation can compute its +// jacobians. The intrinsics are passed in as parameters[0] and the point as +// parameters[1]. +// +// Now we would like to compose the action of this CostFunction with +// the action of camera extrinsics, i.e., rotation and +// translation. Say we have a templated function +// +// template<typename T> +// void RotateAndTranslatePoint(double const* const* parameters, +// double* residuals); +// +// Then we can now do the following, +// +// struct CameraProjection { +// CameraProjection(const double* observation) +// : intrinsic_projection_.(new IntrinsicProjection(observation)) { +// } +// template <typename T> +// bool operator()(T const* const* parameters, +// T* residual) const { +// const T* rotation = parameters[0]; +// const T* translation = parameters[1]; +// const T* intrinsics = parameters[2]; +// const T* point = parameters[3]; +// T transformed_point[3]; +// RotateAndTranslatePoint(rotation, translation, point, transformed_point); +// +// // Note that we call intrinsic_projection_, just like it was +// // any other templated functor. +// const T* projection_parameters[2]; +// projection_parameters[0] = intrinsics; +// projection_parameters[1] = transformed_point; +// return intrinsic_projection_(projection_parameters, residual); +// } +// +// private: +// DynamicCostFunctionToFunctor intrinsic_projection_; +// }; + +#ifndef CERES_PUBLIC_DYNAMIC_COST_FUNCTION_TO_FUNCTOR_H_ +#define CERES_PUBLIC_DYNAMIC_COST_FUNCTION_TO_FUNCTOR_H_ + +#include <numeric> +#include <vector> + +#include "ceres/cost_function.h" +#include "ceres/internal/fixed_array.h" +#include "ceres/internal/port.h" +#include "ceres/internal/scoped_ptr.h" + +namespace ceres { + +class DynamicCostFunctionToFunctor { + public: + // Takes ownership of cost_function. + explicit DynamicCostFunctionToFunctor(CostFunction* cost_function) + : cost_function_(cost_function) { + CHECK_NOTNULL(cost_function); + } + + bool operator()(double const* const* parameters, double* residuals) const { + return cost_function_->Evaluate(parameters, residuals, NULL); + } + + template <typename JetT> + bool operator()(JetT const* const* inputs, JetT* output) const { + const std::vector<int32>& parameter_block_sizes = + cost_function_->parameter_block_sizes(); + const int num_parameter_blocks = parameter_block_sizes.size(); + const int num_residuals = cost_function_->num_residuals(); + const int num_parameters = std::accumulate(parameter_block_sizes.begin(), + parameter_block_sizes.end(), 0); + + internal::FixedArray<double> parameters(num_parameters); + internal::FixedArray<double*> parameter_blocks(num_parameter_blocks); + internal::FixedArray<double> jacobians(num_residuals * num_parameters); + internal::FixedArray<double*> jacobian_blocks(num_parameter_blocks); + internal::FixedArray<double> residuals(num_residuals); + + // Build a set of arrays to get the residuals and jacobians from + // the CostFunction wrapped by this functor. + double* parameter_ptr = parameters.get(); + double* jacobian_ptr = jacobians.get(); + for (int i = 0; i < num_parameter_blocks; ++i) { + parameter_blocks[i] = parameter_ptr; + jacobian_blocks[i] = jacobian_ptr; + for (int j = 0; j < parameter_block_sizes[i]; ++j) { + *parameter_ptr++ = inputs[i][j].a; + } + jacobian_ptr += num_residuals * parameter_block_sizes[i]; + } + + if (!cost_function_->Evaluate(parameter_blocks.get(), + residuals.get(), + jacobian_blocks.get())) { + return false; + } + + // Now that we have the incoming Jets, which are carrying the + // partial derivatives of each of the inputs w.r.t to some other + // underlying parameters. The derivative of the outputs of the + // cost function w.r.t to the same underlying parameters can now + // be computed by applying the chain rule. + // + // d output[i] d output[i] d input[j] + // -------------- = sum_j ----------- * ------------ + // d parameter[k] d input[j] d parameter[k] + // + // d input[j] + // -------------- = inputs[j], so + // d parameter[k] + // + // outputJet[i] = sum_k jacobian[i][k] * inputJet[k] + // + // The following loop, iterates over the residuals, computing one + // output jet at a time. + for (int i = 0; i < num_residuals; ++i) { + output[i].a = residuals[i]; + output[i].v.setZero(); + + for (int j = 0; j < num_parameter_blocks; ++j) { + const int32 block_size = parameter_block_sizes[j]; + for (int k = 0; k < parameter_block_sizes[j]; ++k) { + output[i].v += + jacobian_blocks[j][i * block_size + k] * inputs[j][k].v; + } + } + } + + return true; + } + + private: + internal::scoped_ptr<CostFunction> cost_function_; +}; + +} // namespace ceres + +#endif // CERES_PUBLIC_DYNAMIC_COST_FUNCTION_TO_FUNCTOR_H_ diff --git a/extern/libmv/third_party/ceres/include/ceres/dynamic_numeric_diff_cost_function.h b/extern/libmv/third_party/ceres/include/ceres/dynamic_numeric_diff_cost_function.h index 2b6e8260286..c852d57a3fc 100644 --- a/extern/libmv/third_party/ceres/include/ceres/dynamic_numeric_diff_cost_function.h +++ b/extern/libmv/third_party/ceres/include/ceres/dynamic_numeric_diff_cost_function.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -29,6 +29,7 @@ // Author: mierle@gmail.com (Keir Mierle) // sameeragarwal@google.com (Sameer Agarwal) // thadh@gmail.com (Thad Hughes) +// tbennun@gmail.com (Tal Ben-Nun) // // This numeric diff implementation differs from the one found in // numeric_diff_cost_function.h by supporting numericdiff on cost @@ -41,7 +42,6 @@ // numeric diff; the expected interface for the cost functors is: // // struct MyCostFunctor { -// template<typename T> // bool operator()(double const* const* parameters, double* residuals) const { // // Use parameters[i] to access the i'th parameter block. // } @@ -68,19 +68,37 @@ #include "ceres/internal/scoped_ptr.h" #include "ceres/internal/eigen.h" #include "ceres/internal/numeric_diff.h" +#include "ceres/numeric_diff_options.h" #include "glog/logging.h" namespace ceres { -template <typename CostFunctor, NumericDiffMethod method = CENTRAL> +template <typename CostFunctor, NumericDiffMethodType method = CENTRAL> class DynamicNumericDiffCostFunction : public CostFunction { public: - explicit DynamicNumericDiffCostFunction(const CostFunctor* functor, - Ownership ownership = TAKE_OWNERSHIP, - double relative_step_size = 1e-6) + explicit DynamicNumericDiffCostFunction( + const CostFunctor* functor, + Ownership ownership = TAKE_OWNERSHIP, + const NumericDiffOptions& options = NumericDiffOptions()) : functor_(functor), ownership_(ownership), - relative_step_size_(relative_step_size) { + options_(options) { + } + + // Deprecated. New users should avoid using this constructor. Instead, use the + // constructor with NumericDiffOptions. + DynamicNumericDiffCostFunction( + const CostFunctor* functor, + Ownership ownership, + double relative_step_size) + : functor_(functor), + ownership_(ownership), + options_() { + LOG(WARNING) << "This constructor is deprecated and will be removed in " + "a future version. Please use the NumericDiffOptions " + "constructor instead."; + + options_.relative_step_size = relative_step_size; } virtual ~DynamicNumericDiffCostFunction() { @@ -100,11 +118,12 @@ class DynamicNumericDiffCostFunction : public CostFunction { virtual bool Evaluate(double const* const* parameters, double* residuals, double** jacobians) const { + using internal::NumericDiff; CHECK_GT(num_residuals(), 0) << "You must call DynamicNumericDiffCostFunction::SetNumResiduals() " << "before DynamicNumericDiffCostFunction::Evaluate()."; - const vector<int32>& block_sizes = parameter_block_sizes(); + const std::vector<int32>& block_sizes = parameter_block_sizes(); CHECK(!block_sizes.empty()) << "You must call DynamicNumericDiffCostFunction::AddParameterBlock() " << "before DynamicNumericDiffCostFunction::Evaluate()."; @@ -116,8 +135,8 @@ class DynamicNumericDiffCostFunction : public CostFunction { // Create local space for a copy of the parameters which will get mutated. int parameters_size = accumulate(block_sizes.begin(), block_sizes.end(), 0); - vector<double> parameters_copy(parameters_size); - vector<double*> parameters_references_copy(block_sizes.size()); + std::vector<double> parameters_copy(parameters_size); + std::vector<double*> parameters_references_copy(block_sizes.size()); parameters_references_copy[0] = ¶meters_copy[0]; for (int block = 1; block < block_sizes.size(); ++block) { parameters_references_copy[block] = parameters_references_copy[block - 1] @@ -133,12 +152,18 @@ class DynamicNumericDiffCostFunction : public CostFunction { for (int block = 0; block < block_sizes.size(); ++block) { if (jacobians[block] != NULL && - !EvaluateJacobianForParameterBlock(block_sizes[block], - block, - relative_step_size_, + !NumericDiff<CostFunctor, method, DYNAMIC, + DYNAMIC, DYNAMIC, DYNAMIC, DYNAMIC, DYNAMIC, + DYNAMIC, DYNAMIC, DYNAMIC, DYNAMIC, DYNAMIC, + DYNAMIC, DYNAMIC>::EvaluateJacobianForParameterBlock( + functor_.get(), residuals, + options_, + this->num_residuals(), + block, + block_sizes[block], ¶meters_references_copy[0], - jacobians)) { + jacobians[block])) { return false; } } @@ -146,91 +171,6 @@ class DynamicNumericDiffCostFunction : public CostFunction { } private: - bool EvaluateJacobianForParameterBlock(const int parameter_block_size, - const int parameter_block, - const double relative_step_size, - double const* residuals_at_eval_point, - double** parameters, - double** jacobians) const { - using Eigen::Map; - using Eigen::Matrix; - using Eigen::Dynamic; - using Eigen::RowMajor; - - typedef Matrix<double, Dynamic, 1> ResidualVector; - typedef Matrix<double, Dynamic, 1> ParameterVector; - typedef Matrix<double, Dynamic, Dynamic, RowMajor> JacobianMatrix; - - int num_residuals = this->num_residuals(); - - Map<JacobianMatrix> parameter_jacobian(jacobians[parameter_block], - num_residuals, - parameter_block_size); - - // Mutate one element at a time and then restore. - Map<ParameterVector> x_plus_delta(parameters[parameter_block], - parameter_block_size); - ParameterVector x(x_plus_delta); - ParameterVector step_size = x.array().abs() * relative_step_size; - - // To handle cases where a paremeter is exactly zero, instead use - // the mean step_size for the other dimensions. - double fallback_step_size = step_size.sum() / step_size.rows(); - if (fallback_step_size == 0.0) { - // If all the parameters are zero, there's no good answer. Use the given - // relative step_size as absolute step_size and hope for the best. - fallback_step_size = relative_step_size; - } - - // For each parameter in the parameter block, use finite - // differences to compute the derivative for that parameter. - for (int j = 0; j < parameter_block_size; ++j) { - if (step_size(j) == 0.0) { - // The parameter is exactly zero, so compromise and use the - // mean step_size from the other parameters. This can break in - // many cases, but it's hard to pick a good number without - // problem specific knowledge. - step_size(j) = fallback_step_size; - } - x_plus_delta(j) = x(j) + step_size(j); - - ResidualVector residuals(num_residuals); - if (!EvaluateCostFunctor(parameters, &residuals[0])) { - // Something went wrong; bail. - return false; - } - - // Compute this column of the jacobian in 3 steps: - // 1. Store residuals for the forward part. - // 2. Subtract residuals for the backward (or 0) part. - // 3. Divide out the run. - parameter_jacobian.col(j).matrix() = residuals; - - double one_over_h = 1 / step_size(j); - if (method == CENTRAL) { - // Compute the function on the other side of x(j). - x_plus_delta(j) = x(j) - step_size(j); - - if (!EvaluateCostFunctor(parameters, &residuals[0])) { - // Something went wrong; bail. - return false; - } - - parameter_jacobian.col(j) -= residuals; - one_over_h /= 2; - } else { - // Forward difference only; reuse existing residuals evaluation. - parameter_jacobian.col(j) -= - Map<const ResidualVector>(residuals_at_eval_point, num_residuals); - } - x_plus_delta(j) = x(j); // Restore x_plus_delta. - - // Divide out the run to get slope. - parameter_jacobian.col(j) *= one_over_h; - } - return true; - } - bool EvaluateCostFunctor(double const* const* parameters, double* residuals) const { return EvaluateCostFunctorImpl(functor_.get(), @@ -257,7 +197,7 @@ class DynamicNumericDiffCostFunction : public CostFunction { internal::scoped_ptr<const CostFunctor> functor_; Ownership ownership_; - const double relative_step_size_; + NumericDiffOptions options_; }; } // namespace ceres diff --git a/extern/libmv/third_party/ceres/include/ceres/fpclassify.h b/extern/libmv/third_party/ceres/include/ceres/fpclassify.h index da8a4d086b8..bc2dc90026c 100644 --- a/extern/libmv/third_party/ceres/include/ceres/fpclassify.h +++ b/extern/libmv/third_party/ceres/include/ceres/fpclassify.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -50,26 +50,9 @@ namespace ceres { inline bool IsFinite (double x) { return _finite(x) != 0; } inline bool IsInfinite(double x) { return _finite(x) == 0 && _isnan(x) == 0; } inline bool IsNaN (double x) { return _isnan(x) != 0; } -inline bool IsNormal (double x) { - int classification = _fpclass(x); - return classification == _FPCLASS_NN || - classification == _FPCLASS_PN; -} - -#elif defined(ANDROID) && defined(_STLPORT_VERSION) - -// On Android, when using the STLPort, the C++ isnan and isnormal functions -// are defined as macros. -inline bool IsNaN (double x) { return isnan(x); } -inline bool IsNormal (double x) { return isnormal(x); } -// On Android NDK r6, when using STLPort, the isinf and isfinite functions are -// not available, so reimplement them. -inline bool IsInfinite(double x) { - return x == std::numeric_limits<double>::infinity() || - x == -std::numeric_limits<double>::infinity(); -} -inline bool IsFinite(double x) { - return !isnan(x) && !IsInfinite(x); +inline bool IsNormal (double x) { // NOLINT + const int classification = _fpclass(x); + return (classification == _FPCLASS_NN || classification == _FPCLASS_PN); } # else diff --git a/extern/libmv/third_party/ceres/include/ceres/gradient_checker.h b/extern/libmv/third_party/ceres/include/ceres/gradient_checker.h index 79ebae5f13e..28304159b44 100644 --- a/extern/libmv/third_party/ceres/include/ceres/gradient_checker.h +++ b/extern/libmv/third_party/ceres/include/ceres/gradient_checker.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -78,10 +78,10 @@ class GradientChecker { // block. // Derivatives as computed by the cost function. - vector<Matrix> term_jacobians; + std::vector<Matrix> term_jacobians; // Derivatives as computed by finite differencing. - vector<Matrix> finite_difference_jacobians; + std::vector<Matrix> finite_difference_jacobians; // Infinity-norm of term_jacobians - finite_difference_jacobians. double error_jacobians; @@ -119,7 +119,7 @@ class GradientChecker { // Do a consistency check between the term and the template parameters. CHECK_EQ(M, term->num_residuals()); const int num_residuals = M; - const vector<int32>& block_sizes = term->parameter_block_sizes(); + const std::vector<int32>& block_sizes = term->parameter_block_sizes(); const int num_blocks = block_sizes.size(); CHECK_LE(num_blocks, 5) << "Unable to test functions that take more " diff --git a/extern/libmv/third_party/ceres/include/ceres/gradient_problem.h b/extern/libmv/third_party/ceres/include/ceres/gradient_problem.h index 55a8be1df09..1226a4cd895 100644 --- a/extern/libmv/third_party/ceres/include/ceres/gradient_problem.h +++ b/extern/libmv/third_party/ceres/include/ceres/gradient_problem.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/include/ceres/gradient_problem_solver.h b/extern/libmv/third_party/ceres/include/ceres/gradient_problem_solver.h index db706f7dbaf..a7d0121ea0c 100644 --- a/extern/libmv/third_party/ceres/include/ceres/gradient_problem_solver.h +++ b/extern/libmv/third_party/ceres/include/ceres/gradient_problem_solver.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -81,7 +81,7 @@ class CERES_EXPORT GradientProblemSolver { // Returns true if the options struct has a valid // configuration. Returns false otherwise, and fills in *error // with a message describing the problem. - bool IsValid(string* error) const; + bool IsValid(std::string* error) const; // Minimizer options ---------------------------------------- LineSearchDirectionType line_search_direction_type; @@ -261,7 +261,7 @@ class CERES_EXPORT GradientProblemSolver { // executed, then set update_state_every_iteration to true. // // The solver does NOT take ownership of these pointers. - vector<IterationCallback*> callbacks; + std::vector<IterationCallback*> callbacks; }; struct CERES_EXPORT Summary { @@ -269,11 +269,11 @@ class CERES_EXPORT GradientProblemSolver { // A brief one line description of the state of the solver after // termination. - string BriefReport() const; + std::string BriefReport() const; // A full multiline description of the state of the solver after // termination. - string FullReport() const; + std::string FullReport() const; bool IsSolutionUsable() const; @@ -281,7 +281,7 @@ class CERES_EXPORT GradientProblemSolver { TerminationType termination_type; // Reason why the solver terminated. - string message; + std::string message; // Cost of the problem (value of the objective function) before // the optimization. @@ -292,7 +292,7 @@ class CERES_EXPORT GradientProblemSolver { double final_cost; // IterationSummary for each minimizer iteration in order. - vector<IterationSummary> iterations; + std::vector<IterationSummary> iterations; // Sum total of all time spent inside Ceres when Solve is called. double total_time_in_seconds; @@ -303,6 +303,10 @@ class CERES_EXPORT GradientProblemSolver { // Time (in seconds) spent evaluating the gradient. double gradient_evaluation_time_in_seconds; + // Time (in seconds) spent minimizing the interpolating polynomial + // to compute the next candidate step size as part of a line search. + double line_search_polynomial_minimization_time_in_seconds; + // Number of parameters in the probem. int num_parameters; diff --git a/extern/libmv/third_party/ceres/include/ceres/internal/autodiff.h b/extern/libmv/third_party/ceres/include/ceres/internal/autodiff.h index 3a96625e3fd..136152a36cd 100644 --- a/extern/libmv/third_party/ceres/include/ceres/internal/autodiff.h +++ b/extern/libmv/third_party/ceres/include/ceres/internal/autodiff.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -214,15 +214,15 @@ struct AutoDiff { // This block breaks the 80 column rule to keep it somewhat readable. DCHECK_GT(num_outputs, 0); DCHECK((!N1 && !N2 && !N3 && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && !N2 && !N3 && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && !N3 && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && !N5 && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && (N8 > 0) && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && (N8 > 0) && (N9 > 0))) + ((N1 > 0) && !N2 && !N3 && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || + ((N1 > 0) && (N2 > 0) && !N3 && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && !N5 && !N6 && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && !N6 && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && (N8 > 0) && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && (N8 > 0) && (N9 > 0))) // NOLINT << "Zero block cannot precede a non-zero block. Block sizes are " << "(ignore trailing 0s): " << N0 << ", " << N1 << ", " << N2 << ", " << N3 << ", " << N4 << ", " << N5 << ", " << N6 << ", " << N7 << ", " diff --git a/extern/libmv/third_party/ceres/include/ceres/internal/disable_warnings.h b/extern/libmv/third_party/ceres/include/ceres/internal/disable_warnings.h index 78924de1346..094124f7159 100644 --- a/extern/libmv/third_party/ceres/include/ceres/internal/disable_warnings.h +++ b/extern/libmv/third_party/ceres/include/ceres/internal/disable_warnings.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: 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 85df54b8f99..7138804ace4 100644 --- a/extern/libmv/third_party/ceres/include/ceres/internal/eigen.h +++ b/extern/libmv/third_party/ceres/include/ceres/internal/eigen.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/include/ceres/internal/fixed_array.h b/extern/libmv/third_party/ceres/include/ceres/internal/fixed_array.h index 694070b228c..387298c58d0 100644 --- a/extern/libmv/third_party/ceres/include/ceres/internal/fixed_array.h +++ b/extern/libmv/third_party/ceres/include/ceres/internal/fixed_array.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/include/ceres/internal/macros.h b/extern/libmv/third_party/ceres/include/ceres/internal/macros.h index 1ed55be6e03..bebb965e25b 100644 --- a/extern/libmv/third_party/ceres/include/ceres/internal/macros.h +++ b/extern/libmv/third_party/ceres/include/ceres/internal/macros.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/include/ceres/internal/manual_constructor.h b/extern/libmv/third_party/ceres/include/ceres/internal/manual_constructor.h index 7ea723d2a83..0d7633cef83 100644 --- a/extern/libmv/third_party/ceres/include/ceres/internal/manual_constructor.h +++ b/extern/libmv/third_party/ceres/include/ceres/internal/manual_constructor.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/include/ceres/internal/numeric_diff.h b/extern/libmv/third_party/ceres/include/ceres/internal/numeric_diff.h index 3b264b45af3..11e8275b1d3 100644 --- a/extern/libmv/third_party/ceres/include/ceres/internal/numeric_diff.h +++ b/extern/libmv/third_party/ceres/include/ceres/internal/numeric_diff.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -28,8 +28,9 @@ // // Author: sameeragarwal@google.com (Sameer Agarwal) // mierle@gmail.com (Keir Mierle) +// tbennun@gmail.com (Tal Ben-Nun) // -// Finite differencing routine used by NumericDiffCostFunction. +// Finite differencing routines used by NumericDiffCostFunction. #ifndef CERES_PUBLIC_INTERNAL_NUMERIC_DIFF_H_ #define CERES_PUBLIC_INTERNAL_NUMERIC_DIFF_H_ @@ -37,9 +38,12 @@ #include <cstring> #include "Eigen/Dense" +#include "Eigen/StdVector" #include "ceres/cost_function.h" +#include "ceres/internal/fixed_array.h" #include "ceres/internal/scoped_ptr.h" #include "ceres/internal/variadic_evaluate.h" +#include "ceres/numeric_diff_options.h" #include "ceres/types.h" #include "glog/logging.h" @@ -78,7 +82,7 @@ bool EvaluateImpl(const CostFunctor* functor, // specializations for member functions. The alternative is to repeat the main // class for differing numbers of parameters, which is also unfortunate. template <typename CostFunctor, - NumericDiffMethod kMethod, + NumericDiffMethodType kMethod, int kNumResiduals, int N0, int N1, int N2, int N3, int N4, int N5, int N6, int N7, int N8, int N9, @@ -88,9 +92,11 @@ struct NumericDiff { // Mutates parameters but must restore them before return. static bool EvaluateJacobianForParameterBlock( const CostFunctor* functor, - double const* residuals_at_eval_point, - const double relative_step_size, + const double* residuals_at_eval_point, + const NumericDiffOptions& options, int num_residuals, + int parameter_block_index, + int parameter_block_size, double **parameters, double *jacobian) { using Eigen::Map; @@ -98,8 +104,14 @@ struct NumericDiff { using Eigen::RowMajor; using Eigen::ColMajor; - const int NUM_RESIDUALS = + const int num_residuals_internal = (kNumResiduals != ceres::DYNAMIC ? kNumResiduals : num_residuals); + const int parameter_block_index_internal = + (kParameterBlock != ceres::DYNAMIC ? kParameterBlock : + parameter_block_index); + const int parameter_block_size_internal = + (kParameterBlockSize != ceres::DYNAMIC ? kParameterBlockSize : + parameter_block_size); typedef Matrix<double, kNumResiduals, 1> ResidualVector; typedef Matrix<double, kParameterBlockSize, 1> ParameterVector; @@ -115,73 +127,288 @@ struct NumericDiff { JacobianMatrix; Map<JacobianMatrix> parameter_jacobian(jacobian, - NUM_RESIDUALS, - kParameterBlockSize); + num_residuals_internal, + parameter_block_size_internal); - // Mutate 1 element at a time and then restore. - Map<ParameterVector> x_plus_delta(parameters[kParameterBlock], - kParameterBlockSize); + Map<ParameterVector> x_plus_delta( + parameters[parameter_block_index_internal], + parameter_block_size_internal); ParameterVector x(x_plus_delta); - ParameterVector step_size = x.array().abs() * relative_step_size; + ParameterVector step_size = x.array().abs() * + ((kMethod == RIDDERS) ? options.ridders_relative_initial_step_size : + options.relative_step_size); + + // It is not a good idea to make the step size arbitrarily + // small. This will lead to problems with round off and numerical + // instability when dividing by the step size. The general + // recommendation is to not go down below sqrt(epsilon). + double min_step_size = std::sqrt(std::numeric_limits<double>::epsilon()); - // To handle cases where a parameter is exactly zero, instead use - // the mean step_size for the other dimensions. If all the - // parameters are zero, there's no good answer. Take - // relative_step_size as a guess and hope for the best. - const double fallback_step_size = - (step_size.sum() == 0) - ? relative_step_size - : step_size.sum() / step_size.rows(); + // For Ridders' method, the initial step size is required to be large, + // thus ridders_relative_initial_step_size is used. + if (kMethod == RIDDERS) { + min_step_size = std::max(min_step_size, + options.ridders_relative_initial_step_size); + } // For each parameter in the parameter block, use finite differences to // compute the derivative for that parameter. + FixedArray<double> temp_residual_array(num_residuals_internal); + FixedArray<double> residual_array(num_residuals_internal); + Map<ResidualVector> residuals(residual_array.get(), + num_residuals_internal); + + for (int j = 0; j < parameter_block_size_internal; ++j) { + const double delta = std::max(min_step_size, step_size(j)); + + if (kMethod == RIDDERS) { + if (!EvaluateRiddersJacobianColumn(functor, j, delta, + options, + num_residuals_internal, + parameter_block_size_internal, + x.data(), + residuals_at_eval_point, + parameters, + x_plus_delta.data(), + temp_residual_array.get(), + residual_array.get())) { + return false; + } + } else { + if (!EvaluateJacobianColumn(functor, j, delta, + num_residuals_internal, + parameter_block_size_internal, + x.data(), + residuals_at_eval_point, + parameters, + x_plus_delta.data(), + temp_residual_array.get(), + residual_array.get())) { + return false; + } + } - ResidualVector residuals(NUM_RESIDUALS); - for (int j = 0; j < kParameterBlockSize; ++j) { - const double delta = - (step_size(j) == 0.0) ? fallback_step_size : step_size(j); + parameter_jacobian.col(j).matrix() = residuals; + } + return true; + } - x_plus_delta(j) = x(j) + delta; + static bool EvaluateJacobianColumn(const CostFunctor* functor, + int parameter_index, + double delta, + int num_residuals, + int parameter_block_size, + const double* x_ptr, + const double* residuals_at_eval_point, + double** parameters, + double* x_plus_delta_ptr, + double* temp_residuals_ptr, + double* residuals_ptr) { + using Eigen::Map; + using Eigen::Matrix; + + typedef Matrix<double, kNumResiduals, 1> ResidualVector; + typedef Matrix<double, kParameterBlockSize, 1> ParameterVector; + + Map<const ParameterVector> x(x_ptr, parameter_block_size); + Map<ParameterVector> x_plus_delta(x_plus_delta_ptr, + parameter_block_size); + + Map<ResidualVector> residuals(residuals_ptr, num_residuals); + Map<ResidualVector> temp_residuals(temp_residuals_ptr, num_residuals); + + // Mutate 1 element at a time and then restore. + x_plus_delta(parameter_index) = x(parameter_index) + delta; + + if (!EvaluateImpl<CostFunctor, N0, N1, N2, N3, N4, N5, N6, N7, N8, N9>( + functor, parameters, residuals.data(), functor)) { + return false; + } + + // Compute this column of the jacobian in 3 steps: + // 1. Store residuals for the forward part. + // 2. Subtract residuals for the backward (or 0) part. + // 3. Divide out the run. + double one_over_delta = 1.0 / delta; + if (kMethod == CENTRAL || kMethod == RIDDERS) { + // Compute the function on the other side of x(parameter_index). + x_plus_delta(parameter_index) = x(parameter_index) - delta; if (!EvaluateImpl<CostFunctor, N0, N1, N2, N3, N4, N5, N6, N7, N8, N9>( - functor, parameters, residuals.data(), functor)) { + functor, parameters, temp_residuals.data(), functor)) { return false; } - // Compute this column of the jacobian in 3 steps: - // 1. Store residuals for the forward part. - // 2. Subtract residuals for the backward (or 0) part. - // 3. Divide out the run. - parameter_jacobian.col(j) = residuals; + residuals -= temp_residuals; + one_over_delta /= 2; + } else { + // Forward difference only; reuse existing residuals evaluation. + residuals -= + Map<const ResidualVector>(residuals_at_eval_point, + num_residuals); + } - double one_over_delta = 1.0 / delta; - if (kMethod == CENTRAL) { - // Compute the function on the other side of x(j). - x_plus_delta(j) = x(j) - delta; + // Restore x_plus_delta. + x_plus_delta(parameter_index) = x(parameter_index); - if (!EvaluateImpl<CostFunctor, N0, N1, N2, N3, N4, N5, N6, N7, N8, N9>( - functor, parameters, residuals.data(), functor)) { - return false; + // Divide out the run to get slope. + residuals *= one_over_delta; + + return true; + } + + // This numeric difference implementation uses adaptive differentiation + // on the parameters to obtain the Jacobian matrix. The adaptive algorithm + // is based on Ridders' method for adaptive differentiation, which creates + // a Romberg tableau from varying step sizes and extrapolates the + // intermediate results to obtain the current computational error. + // + // References: + // C.J.F. Ridders, Accurate computation of F'(x) and F'(x) F"(x), Advances + // in Engineering Software (1978), Volume 4, Issue 2, April 1982, + // Pages 75-76, ISSN 0141-1195, + // http://dx.doi.org/10.1016/S0141-1195(82)80057-0. + static bool EvaluateRiddersJacobianColumn( + const CostFunctor* functor, + int parameter_index, + double delta, + const NumericDiffOptions& options, + int num_residuals, + int parameter_block_size, + const double* x_ptr, + const double* residuals_at_eval_point, + double** parameters, + double* x_plus_delta_ptr, + double* temp_residuals_ptr, + double* residuals_ptr) { + using Eigen::Map; + using Eigen::Matrix; + using Eigen::aligned_allocator; + + typedef Matrix<double, kNumResiduals, 1> ResidualVector; + typedef Matrix<double, kNumResiduals, Eigen::Dynamic> ResidualCandidateMatrix; + typedef Matrix<double, kParameterBlockSize, 1> ParameterVector; + + Map<const ParameterVector> x(x_ptr, parameter_block_size); + Map<ParameterVector> x_plus_delta(x_plus_delta_ptr, + parameter_block_size); + + Map<ResidualVector> residuals(residuals_ptr, num_residuals); + Map<ResidualVector> temp_residuals(temp_residuals_ptr, num_residuals); + + // In order for the algorithm to converge, the step size should be + // initialized to a value that is large enough to produce a significant + // change in the function. + // As the derivative is estimated, the step size decreases. + // By default, the step sizes are chosen so that the middle column + // of the Romberg tableau uses the input delta. + double current_step_size = delta * + pow(options.ridders_step_shrink_factor, + options.max_num_ridders_extrapolations / 2); + + // Double-buffering temporary differential candidate vectors + // from previous step size. + ResidualCandidateMatrix stepsize_candidates_a( + num_residuals, + options.max_num_ridders_extrapolations); + ResidualCandidateMatrix stepsize_candidates_b( + num_residuals, + options.max_num_ridders_extrapolations); + ResidualCandidateMatrix* current_candidates = &stepsize_candidates_a; + ResidualCandidateMatrix* previous_candidates = &stepsize_candidates_b; + + // Represents the computational error of the derivative. This variable is + // initially set to a large value, and is set to the difference between + // current and previous finite difference extrapolations. + // norm_error is supposed to decrease as the finite difference tableau + // generation progresses, serving both as an estimate for differentiation + // error and as a measure of differentiation numerical stability. + double norm_error = std::numeric_limits<double>::max(); + + // Loop over decreasing step sizes until: + // 1. Error is smaller than a given value (ridders_epsilon), + // 2. Maximal order of extrapolation reached, or + // 3. Extrapolation becomes numerically unstable. + for (int i = 0; i < options.max_num_ridders_extrapolations; ++i) { + // Compute the numerical derivative at this step size. + if (!EvaluateJacobianColumn(functor, parameter_index, current_step_size, + num_residuals, + parameter_block_size, + x.data(), + residuals_at_eval_point, + parameters, + x_plus_delta.data(), + temp_residuals.data(), + current_candidates->col(0).data())) { + // Something went wrong; bail. + return false; + } + + // Store initial results. + if (i == 0) { + residuals = current_candidates->col(0); + } + + // Shrink differentiation step size. + current_step_size /= options.ridders_step_shrink_factor; + + // Extrapolation factor for Richardson acceleration method (see below). + double richardson_factor = options.ridders_step_shrink_factor * + options.ridders_step_shrink_factor; + for (int k = 1; k <= i; ++k) { + // Extrapolate the various orders of finite differences using + // the Richardson acceleration method. + current_candidates->col(k) = + (richardson_factor * current_candidates->col(k - 1) - + previous_candidates->col(k - 1)) / (richardson_factor - 1.0); + + richardson_factor *= options.ridders_step_shrink_factor * + options.ridders_step_shrink_factor; + + // Compute the difference between the previous value and the current. + double candidate_error = std::max( + (current_candidates->col(k) - + current_candidates->col(k - 1)).norm(), + (current_candidates->col(k) - + previous_candidates->col(k - 1)).norm()); + + // If the error has decreased, update results. + if (candidate_error <= norm_error) { + norm_error = candidate_error; + residuals = current_candidates->col(k); + + // If the error is small enough, stop. + if (norm_error < options.ridders_epsilon) { + break; + } } + } - parameter_jacobian.col(j) -= residuals; - one_over_delta /= 2; - } else { - // Forward difference only; reuse existing residuals evaluation. - parameter_jacobian.col(j) -= - Map<const ResidualVector>(residuals_at_eval_point, NUM_RESIDUALS); + // After breaking out of the inner loop, declare convergence. + if (norm_error < options.ridders_epsilon) { + break; + } + + // Check to see if the current gradient estimate is numerically unstable. + // If so, bail out and return the last stable result. + if (i > 0) { + double tableau_error = (current_candidates->col(i) - + previous_candidates->col(i - 1)).norm(); + + // Compare current error to the chosen candidate's error. + if (tableau_error >= 2 * norm_error) { + break; + } } - x_plus_delta(j) = x(j); // Restore x_plus_delta. - // Divide out the run to get slope. - parameter_jacobian.col(j) *= one_over_delta; + std::swap(current_candidates, previous_candidates); } return true; } }; template <typename CostFunctor, - NumericDiffMethod kMethod, + NumericDiffMethodType kMethod, int kNumResiduals, int N0, int N1, int N2, int N3, int N4, int N5, int N6, int N7, int N8, int N9, @@ -192,11 +419,22 @@ struct NumericDiff<CostFunctor, kMethod, kNumResiduals, // Mutates parameters but must restore them before return. static bool EvaluateJacobianForParameterBlock( const CostFunctor* functor, - double const* residuals_at_eval_point, - const double relative_step_size, + const double* residuals_at_eval_point, + const NumericDiffOptions& options, const int num_residuals, + const int parameter_block_index, + const int parameter_block_size, double **parameters, double *jacobian) { + // Silence unused parameter compiler warnings. + (void)functor; + (void)residuals_at_eval_point; + (void)options; + (void)num_residuals; + (void)parameter_block_index; + (void)parameter_block_size; + (void)parameters; + (void)jacobian; LOG(FATAL) << "Control should never reach here."; return true; } diff --git a/extern/libmv/third_party/ceres/include/ceres/internal/port.h b/extern/libmv/third_party/ceres/include/ceres/internal/port.h index e38eb713aa8..e57049dde4b 100644 --- a/extern/libmv/third_party/ceres/include/ceres/internal/port.h +++ b/extern/libmv/third_party/ceres/include/ceres/internal/port.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -34,8 +34,6 @@ // This file needs to compile as c code. #ifdef __cplusplus -#include <string> - #include "ceres/internal/config.h" #if defined(CERES_TR1_MEMORY_HEADER) @@ -46,16 +44,6 @@ namespace ceres { -// It is unfortunate that this import of the entire standard namespace is -// necessary. The reasons are historical and won't be explained here, but -// suffice to say it is not a mistake and can't be removed without breaking -// things outside of the Ceres optimization package. -using namespace std; - -// This is necessary to properly handle the case that there is a different -// "string" implementation in the global namespace. -using std::string; - #if defined(CERES_TR1_SHARED_PTR) using std::tr1::shared_ptr; #else diff --git a/extern/libmv/third_party/ceres/include/ceres/internal/reenable_warnings.h b/extern/libmv/third_party/ceres/include/ceres/internal/reenable_warnings.h index 1f477d8d2ac..7e410259d64 100644 --- a/extern/libmv/third_party/ceres/include/ceres/internal/reenable_warnings.h +++ b/extern/libmv/third_party/ceres/include/ceres/internal/reenable_warnings.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/include/ceres/internal/scoped_ptr.h b/extern/libmv/third_party/ceres/include/ceres/internal/scoped_ptr.h index 5dfb551243c..fa0ac25a031 100644 --- a/extern/libmv/third_party/ceres/include/ceres/internal/scoped_ptr.h +++ b/extern/libmv/third_party/ceres/include/ceres/internal/scoped_ptr.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/include/ceres/internal/variadic_evaluate.h b/extern/libmv/third_party/ceres/include/ceres/internal/variadic_evaluate.h index 9a473d5b25c..b3515b96d18 100644 --- a/extern/libmv/third_party/ceres/include/ceres/internal/variadic_evaluate.h +++ b/extern/libmv/third_party/ceres/include/ceres/internal/variadic_evaluate.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -35,6 +35,7 @@ #include <stddef.h> #include "ceres/jet.h" +#include "ceres/types.h" #include "ceres/internal/eigen.h" #include "ceres/internal/fixed_array.h" #include "glog/logging.h" @@ -176,6 +177,17 @@ struct VariadicEvaluate<Functor, T, N0, 0, 0, 0, 0, 0, 0, 0, 0, 0> { } }; +// Template instantiation for dynamically-sized functors. +template<typename Functor, typename T> +struct VariadicEvaluate<Functor, T, ceres::DYNAMIC, ceres::DYNAMIC, + ceres::DYNAMIC, ceres::DYNAMIC, ceres::DYNAMIC, + ceres::DYNAMIC, ceres::DYNAMIC, ceres::DYNAMIC, + ceres::DYNAMIC, ceres::DYNAMIC> { + static bool Call(const Functor& functor, T const *const *input, T* output) { + return functor(input, output); + } +}; + } // namespace internal } // namespace ceres diff --git a/extern/libmv/third_party/ceres/include/ceres/iteration_callback.h b/extern/libmv/third_party/ceres/include/ceres/iteration_callback.h index 237ada6e0c9..6bab00439c5 100644 --- a/extern/libmv/third_party/ceres/include/ceres/iteration_callback.h +++ b/extern/libmv/third_party/ceres/include/ceres/iteration_callback.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/include/ceres/jet.h b/extern/libmv/third_party/ceres/include/ceres/jet.h index 74ce1e9dd53..a21fd7adb90 100644 --- a/extern/libmv/third_party/ceres/include/ceres/jet.h +++ b/extern/libmv/third_party/ceres/include/ceres/jet.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -106,8 +106,8 @@ // Jet<double, 2> y(1); // Pick the 1st dual number for y. // Jet<double, 2> z = f(x, y); // -// LOG(INFO) << "df/dx = " << z.a[0] -// << "df/dy = " << z.a[1]; +// LOG(INFO) << "df/dx = " << z.v[0] +// << "df/dy = " << z.v[1]; // // Most users should not use Jet objects directly; a wrapper around Jet objects, // which makes computing the derivative, gradient, or jacobian of templated @@ -482,6 +482,41 @@ Jet<T, N> tanh(const Jet<T, N>& f) { return Jet<T, N>(tanh_a, tmp * f.v); } +// Bessel functions of the first kind with integer order equal to 0, 1, n. +inline double BesselJ0(double x) { return j0(x); } +inline double BesselJ1(double x) { return j1(x); } +inline double BesselJn(int n, double x) { return jn(n, x); } + +// For the formulae of the derivatives of the Bessel functions see the book: +// Olver, Lozier, Boisvert, Clark, NIST Handbook of Mathematical Functions, +// Cambridge University Press 2010. +// +// Formulae are also available at http://dlmf.nist.gov + +// See formula http://dlmf.nist.gov/10.6#E3 +// j0(a + h) ~= j0(a) - j1(a) h +template <typename T, int N> inline +Jet<T, N> BesselJ0(const Jet<T, N>& f) { + return Jet<T, N>(BesselJ0(f.a), + -BesselJ1(f.a) * f.v); +} + +// See formula http://dlmf.nist.gov/10.6#E1 +// j1(a + h) ~= j1(a) + 0.5 ( j0(a) - j2(a) ) h +template <typename T, int N> inline +Jet<T, N> BesselJ1(const Jet<T, N>& f) { + return Jet<T, N>(BesselJ1(f.a), + T(0.5) * (BesselJ0(f.a) - BesselJn(2, f.a)) * f.v); +} + +// See formula http://dlmf.nist.gov/10.6#E1 +// j_n(a + h) ~= j_n(a) + 0.5 ( j_{n-1}(a) - j_{n+1}(a) ) h +template <typename T, int N> inline +Jet<T, N> BesselJn(int n, const Jet<T, N>& f) { + return Jet<T, N>(BesselJn(n, f.a), + T(0.5) * (BesselJn(n - 1, f.a) - BesselJn(n + 1, f.a)) * f.v); +} + // Jet Classification. It is not clear what the appropriate semantics are for // these classifications. This picks that IsFinite and isnormal are "all" // operations, i.e. all elements of the jet must be finite for the jet itself @@ -573,22 +608,101 @@ Jet<T, N> pow(const Jet<T, N>& f, double g) { } // pow -- base is a constant, exponent is a differentiable function. -// (a)^(p+dp) ~= a^p + a^p log(a) dp +// We have various special cases, see the comment for pow(Jet, Jet) for +// analysis: +// +// 1. For f > 0 we have: (f)^(g + dg) ~= f^g + f^g log(f) dg +// +// 2. For f == 0 and g > 0 we have: (f)^(g + dg) ~= f^g +// +// 3. For f < 0 and integer g we have: (f)^(g + dg) ~= f^g but if dg +// != 0, the derivatives are not defined and we return NaN. + template <typename T, int N> inline Jet<T, N> pow(double f, const Jet<T, N>& g) { + if (f == 0 && g.a > 0) { + // Handle case 2. + return Jet<T, N>(T(0.0)); + } + if (f < 0 && g.a == floor(g.a)) { + // Handle case 3. + Jet<T, N> ret(pow(f, g.a)); + for (int i = 0; i < N; i++) { + if (g.v[i] != T(0.0)) { + // Return a NaN when g.v != 0. + ret.v[i] = std::numeric_limits<T>::quiet_NaN(); + } + } + return ret; + } + // Handle case 1. T const tmp = pow(f, g.a); return Jet<T, N>(tmp, log(f) * tmp * g.v); } +// pow -- both base and exponent are differentiable functions. This has a +// variety of special cases that require careful handling. +// +// 1. For f > 0: +// (f + df)^(g + dg) ~= f^g + f^(g - 1) * (g * df + f * log(f) * dg) +// The numerical evaluation of f * log(f) for f > 0 is well behaved, even for +// extremely small values (e.g. 1e-99). +// +// 2. For f == 0 and g > 1: (f + df)^(g + dg) ~= 0 +// This cases is needed because log(0) can not be evaluated in the f > 0 +// expression. However the function f*log(f) is well behaved around f == 0 +// and its limit as f-->0 is zero. +// +// 3. For f == 0 and g == 1: (f + df)^(g + dg) ~= 0 + df +// +// 4. For f == 0 and 0 < g < 1: The value is finite but the derivatives are not. +// +// 5. For f == 0 and g < 0: The value and derivatives of f^g are not finite. +// +// 6. For f == 0 and g == 0: The C standard incorrectly defines 0^0 to be 1 +// "because there are applications that can exploit this definition". We +// (arbitrarily) decree that derivatives here will be nonfinite, since that +// is consistent with the behavior for f == 0, g < 0 and 0 < g < 1. +// Practically any definition could have been justified because mathematical +// consistency has been lost at this point. +// +// 7. For f < 0, g integer, dg == 0: (f + df)^(g + dg) ~= f^g + g * f^(g - 1) df +// This is equivalent to the case where f is a differentiable function and g +// is a constant (to first order). +// +// 8. For f < 0, g integer, dg != 0: The value is finite but the derivatives are +// not, because any change in the value of g moves us away from the point +// with a real-valued answer into the region with complex-valued answers. +// +// 9. For f < 0, g noninteger: The value and derivatives of f^g are not finite. -// pow -- both base and exponent are differentiable functions. -// (a+da)^(b+db) ~= a^b + b * a^(b-1) da + a^b log(a) * db template <typename T, int N> inline Jet<T, N> pow(const Jet<T, N>& f, const Jet<T, N>& g) { + if (f.a == 0 && g.a >= 1) { + // Handle cases 2 and 3. + if (g.a > 1) { + return Jet<T, N>(T(0.0)); + } + return f; + } + if (f.a < 0 && g.a == floor(g.a)) { + // Handle cases 7 and 8. + T const tmp = g.a * pow(f.a, g.a - T(1.0)); + Jet<T, N> ret(pow(f.a, g.a), tmp * f.v); + for (int i = 0; i < N; i++) { + if (g.v[i] != T(0.0)) { + // Return a NaN when g.v != 0. + ret.v[i] = std::numeric_limits<T>::quiet_NaN(); + } + } + return ret; + } + // Handle the remaining cases. For cases 4,5,6,9 we allow the log() function + // to generate -HUGE_VAL or NaN, since those cases result in a nonfinite + // derivative. T const tmp1 = pow(f.a, g.a); T const tmp2 = g.a * pow(f.a, g.a - T(1.0)); T const tmp3 = tmp1 * log(f.a); - return Jet<T, N>(tmp1, tmp2 * f.v + tmp3 * g.v); } diff --git a/extern/libmv/third_party/ceres/include/ceres/local_parameterization.h b/extern/libmv/third_party/ceres/include/ceres/local_parameterization.h index 656c4d46662..67633de309f 100644 --- a/extern/libmv/third_party/ceres/include/ceres/local_parameterization.h +++ b/extern/libmv/third_party/ceres/include/ceres/local_parameterization.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -34,6 +34,7 @@ #include <vector> #include "ceres/internal/port.h" +#include "ceres/internal/scoped_ptr.h" #include "ceres/internal/disable_warnings.h" namespace ceres { @@ -173,7 +174,7 @@ class CERES_EXPORT IdentityParameterization : public LocalParameterization { class CERES_EXPORT SubsetParameterization : public LocalParameterization { public: explicit SubsetParameterization(int size, - const vector<int>& constant_parameters); + const std::vector<int>& constant_parameters); virtual ~SubsetParameterization() {} virtual bool Plus(const double* x, const double* delta, @@ -191,7 +192,7 @@ class CERES_EXPORT SubsetParameterization : public LocalParameterization { private: const int local_size_; - vector<int> constancy_mask_; + std::vector<char> constancy_mask_; }; // Plus(x, delta) = [cos(|delta|), sin(|delta|) delta / |delta|] * x @@ -210,6 +211,89 @@ class CERES_EXPORT QuaternionParameterization : public LocalParameterization { virtual int LocalSize() const { return 3; } }; + +// This provides a parameterization for homogeneous vectors which are commonly +// used in Structure for Motion problems. One example where they are used is +// in representing points whose triangulation is ill-conditioned. Here +// it is advantageous to use an over-parameterization since homogeneous vectors +// can represent points at infinity. +// +// The plus operator is defined as +// Plus(x, delta) = +// [sin(0.5 * |delta|) * delta / |delta|, cos(0.5 * |delta|)] * x +// with * defined as an operator which applies the update orthogonal to x to +// remain on the sphere. We assume that the last element of x is the scalar +// component. The size of the homogeneous vector is required to be greater than +// 1. +class CERES_EXPORT HomogeneousVectorParameterization : + public LocalParameterization { + public: + explicit HomogeneousVectorParameterization(int size); + virtual ~HomogeneousVectorParameterization() {} + virtual bool Plus(const double* x, + const double* delta, + double* x_plus_delta) const; + virtual bool ComputeJacobian(const double* x, + double* jacobian) const; + virtual int GlobalSize() const { return size_; } + virtual int LocalSize() const { return size_ - 1; } + + private: + const int size_; +}; + +// Construct a local parameterization by taking the Cartesian product +// of a number of other local parameterizations. This is useful, when +// a parameter block is the cartesian product of two or more +// manifolds. For example the parameters of a camera consist of a +// rotation and a translation, i.e., SO(3) x R^3. +// +// Currently this class supports taking the cartesian product of up to +// four local parameterizations. +// +// Example usage: +// +// ProductParameterization product_param(new QuaterionionParameterization(), +// new IdentityParameterization(3)); +// +// is the local parameterization for a rigid transformation, where the +// rotation is represented using a quaternion. +class CERES_EXPORT ProductParameterization : public LocalParameterization { + public: + // + // NOTE: All the constructors take ownership of the input local + // parameterizations. + // + ProductParameterization(LocalParameterization* local_param1, + LocalParameterization* local_param2); + + ProductParameterization(LocalParameterization* local_param1, + LocalParameterization* local_param2, + LocalParameterization* local_param3); + + ProductParameterization(LocalParameterization* local_param1, + LocalParameterization* local_param2, + LocalParameterization* local_param3, + LocalParameterization* local_param4); + + virtual ~ProductParameterization(); + virtual bool Plus(const double* x, + const double* delta, + double* x_plus_delta) const; + virtual bool ComputeJacobian(const double* x, + double* jacobian) const; + virtual int GlobalSize() const { return global_size_; } + virtual int LocalSize() const { return local_size_; } + + private: + void Init(); + + std::vector<LocalParameterization*> local_params_; + int local_size_; + int global_size_; + int buffer_size_; +}; + } // namespace ceres #include "ceres/internal/reenable_warnings.h" diff --git a/extern/libmv/third_party/ceres/include/ceres/loss_function.h b/extern/libmv/third_party/ceres/include/ceres/loss_function.h index 2c585009990..0512c135143 100644 --- a/extern/libmv/third_party/ceres/include/ceres/loss_function.h +++ b/extern/libmv/third_party/ceres/include/ceres/loss_function.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -274,10 +274,28 @@ class CERES_EXPORT TolerantLoss : public LossFunction { const double a_, b_, c_; }; +// This is the Tukey biweight loss function which aggressively +// attempts to suppress large errors. +// +// The term is computed as: +// +// rho(s) = a^2 / 6 * (1 - (1 - s / a^2)^3 ) for s <= a^2, +// rho(s) = a^2 / 6 for s > a^2. +// +// At s = 0: rho = [0, 0.5, -1 / a^2] +class CERES_EXPORT TukeyLoss : public ceres::LossFunction { + public: + explicit TukeyLoss(double a) : a_squared_(a * a) { } + virtual void Evaluate(double, double*) const; + + private: + const double a_squared_; +}; + // Composition of two loss functions. The error is the result of first // evaluating g followed by f to yield the composition f(g(s)). // The loss functions must not be NULL. -class ComposedLoss : public LossFunction { +class CERES_EXPORT ComposedLoss : public LossFunction { public: explicit ComposedLoss(const LossFunction* f, Ownership ownership_f, const LossFunction* g, Ownership ownership_g); @@ -340,6 +358,9 @@ class CERES_EXPORT ScaledLoss : public LossFunction { // whose scale can be mutated after an optimization problem has been // constructed. // +// Since we treat the a NULL Loss function as the Identity loss +// function, rho = NULL is a valid input. +// // Example usage // // Problem problem; @@ -376,8 +397,14 @@ class CERES_EXPORT LossFunctionWrapper : public LossFunction { } virtual void Evaluate(double sq_norm, double out[3]) const { - CHECK_NOTNULL(rho_.get()); - rho_->Evaluate(sq_norm, out); + if (rho_.get() == NULL) { + out[0] = sq_norm; + out[1] = 1.0; + out[2] = 0.0; + } + else { + rho_->Evaluate(sq_norm, out); + } } void Reset(LossFunction* rho, Ownership ownership) { @@ -396,6 +423,6 @@ class CERES_EXPORT LossFunctionWrapper : public LossFunction { } // namespace ceres -#include "ceres/internal/disable_warnings.h" +#include "ceres/internal/reenable_warnings.h" #endif // CERES_PUBLIC_LOSS_FUNCTION_H_ diff --git a/extern/libmv/third_party/ceres/include/ceres/normal_prior.h b/extern/libmv/third_party/ceres/include/ceres/normal_prior.h index df665054530..cd98b4c846b 100644 --- a/extern/libmv/third_party/ceres/include/ceres/normal_prior.h +++ b/extern/libmv/third_party/ceres/include/ceres/normal_prior.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/include/ceres/numeric_diff_cost_function.h b/extern/libmv/third_party/ceres/include/ceres/numeric_diff_cost_function.h index de6b74ad552..fa96078df02 100644 --- a/extern/libmv/third_party/ceres/include/ceres/numeric_diff_cost_function.h +++ b/extern/libmv/third_party/ceres/include/ceres/numeric_diff_cost_function.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -132,7 +132,7 @@ // // ALTERNATE INTERFACE // -// For a variety of reason, including compatibility with legacy code, +// For a variety of reasons, including compatibility with legacy code, // NumericDiffCostFunction can also take CostFunction objects as // input. The following describes how. // @@ -165,6 +165,7 @@ #include "ceres/cost_function.h" #include "ceres/internal/numeric_diff.h" #include "ceres/internal/scoped_ptr.h" +#include "ceres/numeric_diff_options.h" #include "ceres/sized_cost_function.h" #include "ceres/types.h" #include "glog/logging.h" @@ -172,7 +173,7 @@ namespace ceres { template <typename CostFunctor, - NumericDiffMethod method = CENTRAL, + NumericDiffMethodType method = CENTRAL, int kNumResiduals = 0, // Number of residuals, or ceres::DYNAMIC int N0 = 0, // Number of parameters in block 0. int N1 = 0, // Number of parameters in block 1. @@ -189,19 +190,43 @@ class NumericDiffCostFunction N0, N1, N2, N3, N4, N5, N6, N7, N8, N9> { public: + NumericDiffCostFunction( + CostFunctor* functor, + Ownership ownership = TAKE_OWNERSHIP, + int num_residuals = kNumResiduals, + const NumericDiffOptions& options = NumericDiffOptions()) + : functor_(functor), + ownership_(ownership), + options_(options) { + if (kNumResiduals == DYNAMIC) { + SizedCostFunction<kNumResiduals, + N0, N1, N2, N3, N4, + N5, N6, N7, N8, N9> + ::set_num_residuals(num_residuals); + } + } + + // Deprecated. New users should avoid using this constructor. Instead, use the + // constructor with NumericDiffOptions. NumericDiffCostFunction(CostFunctor* functor, - Ownership ownership = TAKE_OWNERSHIP, - int num_residuals = kNumResiduals, - const double relative_step_size = 1e-6) + Ownership ownership, + int num_residuals, + const double relative_step_size) :functor_(functor), ownership_(ownership), - relative_step_size_(relative_step_size) { + options_() { + LOG(WARNING) << "This constructor is deprecated and will be removed in " + "a future version. Please use the NumericDiffOptions " + "constructor instead."; + if (kNumResiduals == DYNAMIC) { SizedCostFunction<kNumResiduals, N0, N1, N2, N3, N4, N5, N6, N7, N8, N9> ::set_num_residuals(num_residuals); } + + options_.relative_step_size = relative_step_size; } ~NumericDiffCostFunction() { @@ -250,25 +275,25 @@ class NumericDiffCostFunction if (N8) parameters_reference_copy[8] = parameters_reference_copy[7] + N7; if (N9) parameters_reference_copy[9] = parameters_reference_copy[8] + N8; -#define COPY_PARAMETER_BLOCK(block) \ +#define CERES_COPY_PARAMETER_BLOCK(block) \ if (N ## block) memcpy(parameters_reference_copy[block], \ parameters[block], \ sizeof(double) * N ## block); // NOLINT - COPY_PARAMETER_BLOCK(0); - COPY_PARAMETER_BLOCK(1); - COPY_PARAMETER_BLOCK(2); - COPY_PARAMETER_BLOCK(3); - COPY_PARAMETER_BLOCK(4); - COPY_PARAMETER_BLOCK(5); - COPY_PARAMETER_BLOCK(6); - COPY_PARAMETER_BLOCK(7); - COPY_PARAMETER_BLOCK(8); - COPY_PARAMETER_BLOCK(9); + CERES_COPY_PARAMETER_BLOCK(0); + CERES_COPY_PARAMETER_BLOCK(1); + CERES_COPY_PARAMETER_BLOCK(2); + CERES_COPY_PARAMETER_BLOCK(3); + CERES_COPY_PARAMETER_BLOCK(4); + CERES_COPY_PARAMETER_BLOCK(5); + CERES_COPY_PARAMETER_BLOCK(6); + CERES_COPY_PARAMETER_BLOCK(7); + CERES_COPY_PARAMETER_BLOCK(8); + CERES_COPY_PARAMETER_BLOCK(9); -#undef COPY_PARAMETER_BLOCK +#undef CERES_COPY_PARAMETER_BLOCK -#define EVALUATE_JACOBIAN_FOR_BLOCK(block) \ +#define CERES_EVALUATE_JACOBIAN_FOR_BLOCK(block) \ if (N ## block && jacobians[block] != NULL) { \ if (!NumericDiff<CostFunctor, \ method, \ @@ -278,28 +303,30 @@ class NumericDiffCostFunction N ## block >::EvaluateJacobianForParameterBlock( \ functor_.get(), \ residuals, \ - relative_step_size_, \ + options_, \ SizedCostFunction<kNumResiduals, \ N0, N1, N2, N3, N4, \ N5, N6, N7, N8, N9>::num_residuals(), \ + block, \ + N ## block, \ parameters_reference_copy.get(), \ jacobians[block])) { \ return false; \ } \ } - EVALUATE_JACOBIAN_FOR_BLOCK(0); - EVALUATE_JACOBIAN_FOR_BLOCK(1); - EVALUATE_JACOBIAN_FOR_BLOCK(2); - EVALUATE_JACOBIAN_FOR_BLOCK(3); - EVALUATE_JACOBIAN_FOR_BLOCK(4); - EVALUATE_JACOBIAN_FOR_BLOCK(5); - EVALUATE_JACOBIAN_FOR_BLOCK(6); - EVALUATE_JACOBIAN_FOR_BLOCK(7); - EVALUATE_JACOBIAN_FOR_BLOCK(8); - EVALUATE_JACOBIAN_FOR_BLOCK(9); + CERES_EVALUATE_JACOBIAN_FOR_BLOCK(0); + CERES_EVALUATE_JACOBIAN_FOR_BLOCK(1); + CERES_EVALUATE_JACOBIAN_FOR_BLOCK(2); + CERES_EVALUATE_JACOBIAN_FOR_BLOCK(3); + CERES_EVALUATE_JACOBIAN_FOR_BLOCK(4); + CERES_EVALUATE_JACOBIAN_FOR_BLOCK(5); + CERES_EVALUATE_JACOBIAN_FOR_BLOCK(6); + CERES_EVALUATE_JACOBIAN_FOR_BLOCK(7); + CERES_EVALUATE_JACOBIAN_FOR_BLOCK(8); + CERES_EVALUATE_JACOBIAN_FOR_BLOCK(9); -#undef EVALUATE_JACOBIAN_FOR_BLOCK +#undef CERES_EVALUATE_JACOBIAN_FOR_BLOCK return true; } @@ -307,7 +334,7 @@ class NumericDiffCostFunction private: internal::scoped_ptr<CostFunctor> functor_; Ownership ownership_; - const double relative_step_size_; + NumericDiffOptions options_; }; } // namespace ceres diff --git a/extern/libmv/third_party/ceres/include/ceres/numeric_diff_options.h b/extern/libmv/third_party/ceres/include/ceres/numeric_diff_options.h new file mode 100644 index 00000000000..119c8a86596 --- /dev/null +++ b/extern/libmv/third_party/ceres/include/ceres/numeric_diff_options.h @@ -0,0 +1,79 @@ +// Ceres Solver - A fast non-linear least squares minimizer +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ +// +// 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: tbennun@gmail.com (Tal Ben-Nun) +// + +#ifndef CERES_PUBLIC_NUMERIC_DIFF_OPTIONS_H_ +#define CERES_PUBLIC_NUMERIC_DIFF_OPTIONS_H_ + +namespace ceres { + +// Options pertaining to numeric differentiation (e.g., convergence criteria, +// step sizes). +struct CERES_EXPORT NumericDiffOptions { + NumericDiffOptions() { + relative_step_size = 1e-6; + ridders_relative_initial_step_size = 1e-2; + max_num_ridders_extrapolations = 10; + ridders_epsilon = 1e-12; + ridders_step_shrink_factor = 2.0; + } + + // Numeric differentiation step size (multiplied by parameter block's + // order of magnitude). If parameters are close to zero, the step size + // is set to sqrt(machine_epsilon). + double relative_step_size; + + // Initial step size for Ridders adaptive numeric differentiation (multiplied + // by parameter block's order of magnitude). + // If parameters are close to zero, Ridders' method sets the step size + // directly to this value. This parameter is separate from + // "relative_step_size" in order to set a different default value. + // + // Note: For Ridders' method to converge, the step size should be initialized + // to a value that is large enough to produce a significant change in the + // function. As the derivative is estimated, the step size decreases. + double ridders_relative_initial_step_size; + + // Maximal number of adaptive extrapolations (sampling) in Ridders' method. + int max_num_ridders_extrapolations; + + // Convergence criterion on extrapolation error for Ridders adaptive + // differentiation. The available error estimation methods are defined in + // NumericDiffErrorType and set in the "ridders_error_method" field. + double ridders_epsilon; + + // The factor in which to shrink the step size with each extrapolation in + // Ridders' method. + double ridders_step_shrink_factor; +}; + +} // namespace ceres + +#endif // CERES_PUBLIC_NUMERIC_DIFF_OPTIONS_H_ diff --git a/extern/libmv/third_party/ceres/include/ceres/ordered_groups.h b/extern/libmv/third_party/ceres/include/ceres/ordered_groups.h index c316d712e97..aa1bd3a7da1 100644 --- a/extern/libmv/third_party/ceres/include/ceres/ordered_groups.h +++ b/extern/libmv/third_party/ceres/include/ceres/ordered_groups.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -63,7 +63,8 @@ class OrderedGroups { return false; } - typename map<T, int>::const_iterator it = element_to_group_.find(element); + typename std::map<T, int>::const_iterator it = + element_to_group_.find(element); if (it != element_to_group_.end()) { if (it->second == group) { // Element is already in the right group, nothing to do. @@ -107,7 +108,7 @@ class OrderedGroups { // Bulk remove elements. The return value indicates the number of // elements successfully removed. - int Remove(const vector<T>& elements) { + int Remove(const std::vector<T>& elements) { if (NumElements() == 0 || elements.size() == 0) { return 0; } @@ -121,14 +122,18 @@ class OrderedGroups { // Reverse the order of the groups in place. void Reverse() { - typename map<int, set<T> >::reverse_iterator it = + if (NumGroups() == 0) { + return; + } + + typename std::map<int, std::set<T> >::reverse_iterator it = group_to_elements_.rbegin(); - map<int, set<T> > new_group_to_elements; + std::map<int, std::set<T> > new_group_to_elements; new_group_to_elements[it->first] = it->second; int new_group_id = it->first + 1; for (++it; it != group_to_elements_.rend(); ++it) { - for (typename set<T>::const_iterator element_it = it->second.begin(); + for (typename std::set<T>::const_iterator element_it = it->second.begin(); element_it != it->second.end(); ++element_it) { element_to_group_[*element_it] = new_group_id; @@ -143,7 +148,8 @@ class OrderedGroups { // Return the group id for the element. If the element is not a // member of any group, return -1. int GroupId(const T element) const { - typename map<T, int>::const_iterator it = element_to_group_.find(element); + typename std::map<T, int>::const_iterator it = + element_to_group_.find(element); if (it == element_to_group_.end()) { return -1; } @@ -151,14 +157,15 @@ class OrderedGroups { } bool IsMember(const T element) const { - typename map<T, int>::const_iterator it = element_to_group_.find(element); + typename std::map<T, int>::const_iterator it = + element_to_group_.find(element); return (it != element_to_group_.end()); } // This function always succeeds, i.e., implicitly there exists a // group for every integer. int GroupSize(const int group) const { - typename map<int, set<T> >::const_iterator it = + typename std::map<int, std::set<T> >::const_iterator it = group_to_elements_.find(group); return (it == group_to_elements_.end()) ? 0 : it->second.size(); } @@ -180,17 +187,17 @@ class OrderedGroups { return group_to_elements_.begin()->first; } - const map<int, set<T> >& group_to_elements() const { + const std::map<int, std::set<T> >& group_to_elements() const { return group_to_elements_; } - const map<T, int>& element_to_group() const { + const std::map<T, int>& element_to_group() const { return element_to_group_; } private: - map<int, set<T> > group_to_elements_; - map<T, int> element_to_group_; + std::map<int, std::set<T> > group_to_elements_; + std::map<T, int> element_to_group_; }; // Typedef for the most commonly used version of OrderedGroups. diff --git a/extern/libmv/third_party/ceres/include/ceres/problem.h b/extern/libmv/third_party/ceres/include/ceres/problem.h index f75ede3a5c6..409274c62c2 100644 --- a/extern/libmv/third_party/ceres/include/ceres/problem.h +++ b/extern/libmv/third_party/ceres/include/ceres/problem.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -211,9 +211,10 @@ class CERES_EXPORT Problem { // problem.AddResidualBlock(new MyUnaryCostFunction(...), NULL, x1); // problem.AddResidualBlock(new MyBinaryCostFunction(...), NULL, x2, x1); // - ResidualBlockId AddResidualBlock(CostFunction* cost_function, - LossFunction* loss_function, - const vector<double*>& parameter_blocks); + ResidualBlockId AddResidualBlock( + CostFunction* cost_function, + LossFunction* loss_function, + const std::vector<double*>& parameter_blocks); // Convenience methods for adding residuals with a small number of // parameters. This is the common case. Instead of specifying the @@ -356,17 +357,17 @@ class CERES_EXPORT Problem { // Fills the passed parameter_blocks vector with pointers to the // parameter blocks currently in the problem. After this call, // parameter_block.size() == NumParameterBlocks. - void GetParameterBlocks(vector<double*>* parameter_blocks) const; + void GetParameterBlocks(std::vector<double*>* parameter_blocks) const; // Fills the passed residual_blocks vector with pointers to the // residual blocks currently in the problem. After this call, // residual_blocks.size() == NumResidualBlocks. - void GetResidualBlocks(vector<ResidualBlockId>* residual_blocks) const; + void GetResidualBlocks(std::vector<ResidualBlockId>* residual_blocks) const; // Get all the parameter blocks that depend on the given residual block. void GetParameterBlocksForResidualBlock( const ResidualBlockId residual_block, - vector<double*>* parameter_blocks) const; + std::vector<double*>* parameter_blocks) const; // Get the CostFunction for the given residual block. const CostFunction* GetCostFunctionForResidualBlock( @@ -385,7 +386,7 @@ class CERES_EXPORT Problem { // block will incur a scan of the entire Problem object. void GetResidualBlocksForParameterBlock( const double* values, - vector<ResidualBlockId>* residual_blocks) const; + std::vector<ResidualBlockId>* residual_blocks) const; // Options struct to control Problem::Evaluate. struct EvaluateOptions { @@ -408,18 +409,17 @@ class CERES_EXPORT Problem { // used to add parameter blocks to the Problem. These parameter // block should NOT point to new memory locations. Bad things will // happen otherwise. - vector<double*> parameter_blocks; + std::vector<double*> parameter_blocks; // The set of residual blocks to evaluate. This vector determines // the order in which the residuals occur, and how the rows of the // jacobian are ordered. If residual_blocks is empty, then it is - // assumed to be equal to the vector containing all the residual - // blocks. If this vector is empty, then it is assumed to be equal - // to a vector containing ALL the residual blocks. Generally - // speaking the residual blocks will occur in the order in which - // they were added to the problem. But, this may change if the - // user removes any residual blocks from the problem. - vector<ResidualBlockId> residual_blocks; + // assumed to be equal to the vector containing ALL the residual + // blocks. Generally speaking the residual blocks will occur in + // the order in which they were added to the problem. But, this + // may change if the user removes any residual blocks from the + // problem. + std::vector<ResidualBlockId> residual_blocks; // Even though the residual blocks in the problem may contain loss // functions, setting apply_loss_function to false will turn off @@ -463,8 +463,8 @@ class CERES_EXPORT Problem { // columns in the jacobian). bool Evaluate(const EvaluateOptions& options, double* cost, - vector<double>* residuals, - vector<double>* gradient, + std::vector<double>* residuals, + std::vector<double>* gradient, CRSMatrix* jacobian); private: diff --git a/extern/libmv/third_party/ceres/include/ceres/rotation.h b/extern/libmv/third_party/ceres/include/ceres/rotation.h index e3dbfe84a5a..e9496d772e4 100644 --- a/extern/libmv/third_party/ceres/include/ceres/rotation.h +++ b/extern/libmv/third_party/ceres/include/ceres/rotation.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -47,6 +47,7 @@ #include <algorithm> #include <cmath> +#include <limits> #include "glog/logging.h" namespace ceres { @@ -95,6 +96,17 @@ template<typename T> void QuaternionToAngleAxis(const T* quaternion, T* angle_axis); // Conversions between 3x3 rotation matrix (in column major order) and +// quaternion rotation representations. Templated for use with +// autodifferentiation. +template <typename T> +void RotationMatrixToQuaternion(const T* R, T* quaternion); + +template <typename T, int row_stride, int col_stride> +void RotationMatrixToQuaternion( + const MatrixAdapter<const T, row_stride, col_stride>& R, + T* quaternion); + +// Conversions between 3x3 rotation matrix (in column major order) and // axis-angle rotation representations. Templated for use with // autodifferentiation. template <typename T> @@ -141,11 +153,11 @@ void EulerAnglesToRotationMatrix( // the cross-product matrix of [a b c]. Together with the property that // R(q1 * q2) = R(q1) * R(q2) this uniquely defines the mapping from q to R. // -// The rotation matrix is row-major. -// // No normalization of the quaternion is performed, i.e. // R = ||q||^2 * Q, where Q is an orthonormal matrix // such that det(Q) = 1 and Q*Q' = I +// +// WARNING: The rotation matrix is ROW MAJOR template <typename T> inline void QuaternionToScaledRotation(const T q[4], T R[3 * 3]); @@ -156,6 +168,8 @@ void QuaternionToScaledRotation( // Same as above except that the rotation matrix is normalized by the // Frobenius norm, so that R * R' = I (and det(R) = 1). +// +// WARNING: The rotation matrix is ROW MAJOR template <typename T> inline void QuaternionToRotation(const T q[4], T R[3 * 3]); @@ -294,6 +308,46 @@ inline void QuaternionToAngleAxis(const T* quaternion, T* angle_axis) { } } +template <typename T> +void RotationMatrixToQuaternion(const T* R, T* angle_axis) { + RotationMatrixToQuaternion(ColumnMajorAdapter3x3(R), angle_axis); +} + +// This algorithm comes from "Quaternion Calculus and Fast Animation", +// Ken Shoemake, 1987 SIGGRAPH course notes +template <typename T, int row_stride, int col_stride> +void RotationMatrixToQuaternion( + const MatrixAdapter<const T, row_stride, col_stride>& R, + T* quaternion) { + const T trace = R(0, 0) + R(1, 1) + R(2, 2); + if (trace >= 0.0) { + T t = sqrt(trace + T(1.0)); + quaternion[0] = T(0.5) * t; + t = T(0.5) / t; + quaternion[1] = (R(2, 1) - R(1, 2)) * t; + quaternion[2] = (R(0, 2) - R(2, 0)) * t; + quaternion[3] = (R(1, 0) - R(0, 1)) * t; + } else { + int i = 0; + if (R(1, 1) > R(0, 0)) { + i = 1; + } + + if (R(2, 2) > R(i, i)) { + i = 2; + } + + const int j = (i + 1) % 3; + const int k = (j + 1) % 3; + T t = sqrt(R(i, i) - R(j, j) - R(k, k) + T(1.0)); + quaternion[i + 1] = T(0.5) * t; + t = T(0.5) / t; + quaternion[0] = (R(k, j) - R(j, k)) * t; + quaternion[j + 1] = (R(j, i) + R(i, j)) * t; + quaternion[k + 1] = (R(k, i) + R(i, k)) * t; + } +} + // The conversion of a rotation matrix to the angle-axis form is // numerically problematic when then rotation angle is close to zero // or to Pi. The following implementation detects when these two cases @@ -308,80 +362,10 @@ template <typename T, int row_stride, int col_stride> void RotationMatrixToAngleAxis( const MatrixAdapter<const T, row_stride, col_stride>& R, T* angle_axis) { - // x = k * 2 * sin(theta), where k is the axis of rotation. - angle_axis[0] = R(2, 1) - R(1, 2); - angle_axis[1] = R(0, 2) - R(2, 0); - angle_axis[2] = R(1, 0) - R(0, 1); - - static const T kOne = T(1.0); - static const T kTwo = T(2.0); - - // Since the right hand side may give numbers just above 1.0 or - // below -1.0 leading to atan misbehaving, we threshold. - T costheta = std::min(std::max((R(0, 0) + R(1, 1) + R(2, 2) - kOne) / kTwo, - T(-1.0)), - kOne); - - // sqrt is guaranteed to give non-negative results, so we only - // threshold above. - T sintheta = std::min(sqrt(angle_axis[0] * angle_axis[0] + - angle_axis[1] * angle_axis[1] + - angle_axis[2] * angle_axis[2]) / kTwo, - kOne); - - // Use the arctan2 to get the right sign on theta - const T theta = atan2(sintheta, costheta); - - // Case 1: sin(theta) is large enough, so dividing by it is not a - // problem. We do not use abs here, because while jets.h imports - // std::abs into the namespace, here in this file, abs resolves to - // the int version of the function, which returns zero always. - // - // We use a threshold much larger then the machine epsilon, because - // if sin(theta) is small, not only do we risk overflow but even if - // that does not occur, just dividing by a small number will result - // in numerical garbage. So we play it safe. - static const double kThreshold = 1e-12; - if ((sintheta > kThreshold) || (sintheta < -kThreshold)) { - const T r = theta / (kTwo * sintheta); - for (int i = 0; i < 3; ++i) { - angle_axis[i] *= r; - } - return; - } - - // Case 2: theta ~ 0, means sin(theta) ~ theta to a good - // approximation. - if (costheta > 0.0) { - const T kHalf = T(0.5); - for (int i = 0; i < 3; ++i) { - angle_axis[i] *= kHalf; - } - return; - } - - // Case 3: theta ~ pi, this is the hard case. Since theta is large, - // and sin(theta) is small. Dividing by theta by sin(theta) will - // either give an overflow or worse still numerically meaningless - // results. Thus we use an alternate more complicated formula - // here. - - // Since cos(theta) is negative, division by (1-cos(theta)) cannot - // overflow. - const T inv_one_minus_costheta = kOne / (kOne - costheta); - - // We now compute the absolute value of coordinates of the axis - // vector using the diagonal entries of R. To resolve the sign of - // these entries, we compare the sign of angle_axis[i]*sin(theta) - // with the sign of sin(theta). If they are the same, then - // angle_axis[i] should be positive, otherwise negative. - for (int i = 0; i < 3; ++i) { - angle_axis[i] = theta * sqrt((R(i, i) - costheta) * inv_one_minus_costheta); - if (((sintheta < 0.0) && (angle_axis[i] > 0.0)) || - ((sintheta > 0.0) && (angle_axis[i] < 0.0))) { - angle_axis[i] = -angle_axis[i]; - } - } + T quaternion[4]; + RotationMatrixToQuaternion(R, quaternion); + QuaternionToAngleAxis(quaternion, angle_axis); + return; } template <typename T> diff --git a/extern/libmv/third_party/ceres/include/ceres/sized_cost_function.h b/extern/libmv/third_party/ceres/include/ceres/sized_cost_function.h index 4f98d4eb95c..b10421e81be 100644 --- a/extern/libmv/third_party/ceres/include/ceres/sized_cost_function.h +++ b/extern/libmv/third_party/ceres/include/ceres/sized_cost_function.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -55,15 +55,15 @@ class SizedCostFunction : public CostFunction { // This block breaks the 80 column rule to keep it somewhat readable. CHECK((!N1 && !N2 && !N3 && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && !N2 && !N3 && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && !N3 && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && !N5 && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && (N8 > 0) && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && (N8 > 0) && (N9 > 0))) + ((N1 > 0) && !N2 && !N3 && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || + ((N1 > 0) && (N2 > 0) && !N3 && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && !N5 && !N6 && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && !N6 && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && (N8 > 0) && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && (N8 > 0) && (N9 > 0))) // NOLINT << "Zero block cannot precede a non-zero block. Block sizes are " << "(ignore trailing 0s): " << N0 << ", " << N1 << ", " << N2 << ", " << N3 << ", " << N4 << ", " << N5 << ", " << N6 << ", " << N7 << ", " @@ -71,19 +71,19 @@ class SizedCostFunction : public CostFunction { set_num_residuals(kNumResiduals); -#define ADD_PARAMETER_BLOCK(N) \ +#define CERES_ADD_PARAMETER_BLOCK(N) \ if (N) mutable_parameter_block_sizes()->push_back(N); - ADD_PARAMETER_BLOCK(N0); - ADD_PARAMETER_BLOCK(N1); - ADD_PARAMETER_BLOCK(N2); - ADD_PARAMETER_BLOCK(N3); - ADD_PARAMETER_BLOCK(N4); - ADD_PARAMETER_BLOCK(N5); - ADD_PARAMETER_BLOCK(N6); - ADD_PARAMETER_BLOCK(N7); - ADD_PARAMETER_BLOCK(N8); - ADD_PARAMETER_BLOCK(N9); -#undef ADD_PARAMETER_BLOCK + CERES_ADD_PARAMETER_BLOCK(N0); + CERES_ADD_PARAMETER_BLOCK(N1); + CERES_ADD_PARAMETER_BLOCK(N2); + CERES_ADD_PARAMETER_BLOCK(N3); + CERES_ADD_PARAMETER_BLOCK(N4); + CERES_ADD_PARAMETER_BLOCK(N5); + CERES_ADD_PARAMETER_BLOCK(N6); + CERES_ADD_PARAMETER_BLOCK(N7); + CERES_ADD_PARAMETER_BLOCK(N8); + CERES_ADD_PARAMETER_BLOCK(N9); +#undef CERES_ADD_PARAMETER_BLOCK } virtual ~SizedCostFunction() { } diff --git a/extern/libmv/third_party/ceres/include/ceres/solver.h b/extern/libmv/third_party/ceres/include/ceres/solver.h index a5efa2a3915..318cf48cb83 100644 --- a/extern/libmv/third_party/ceres/include/ceres/solver.h +++ b/extern/libmv/third_party/ceres/include/ceres/solver.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -92,7 +92,7 @@ class CERES_EXPORT Solver { gradient_tolerance = 1e-10; parameter_tolerance = 1e-8; -#if defined(CERES_NO_SUITESPARSE) && defined(CERES_NO_CXSPARSE) && !defined(CERES_ENABLE_LGPL_CODE) +#if defined(CERES_NO_SUITESPARSE) && defined(CERES_NO_CXSPARSE) && !defined(CERES_ENABLE_LGPL_CODE) // NOLINT linear_solver_type = DENSE_QR; #else linear_solver_type = SPARSE_NORMAL_CHOLESKY; @@ -104,7 +104,8 @@ class CERES_EXPORT Solver { // Choose a default sparse linear algebra library in the order: // - // SUITE_SPARSE > CX_SPARSE > EIGEN_SPARSE + // SUITE_SPARSE > CX_SPARSE > EIGEN_SPARSE > NO_SPARSE + sparse_linear_algebra_library_type = NO_SPARSE; #if !defined(CERES_NO_SUITESPARSE) sparse_linear_algebra_library_type = SUITE_SPARSE; #else @@ -140,7 +141,7 @@ class CERES_EXPORT Solver { // Returns true if the options struct has a valid // configuration. Returns false otherwise, and fills in *error // with a message describing the problem. - bool IsValid(string* error) const; + bool IsValid(std::string* error) const; // Minimizer options ---------------------------------------- @@ -676,13 +677,13 @@ class CERES_EXPORT Solver { // List of iterations at which the minimizer should dump the trust // region problem. Useful for testing and benchmarking. If empty // (default), no problems are dumped. - vector<int> trust_region_minimizer_iterations_to_dump; + std::vector<int> trust_region_minimizer_iterations_to_dump; // Directory to which the problems should be written to. Should be // non-empty if trust_region_minimizer_iterations_to_dump is // non-empty and trust_region_problem_dump_format_type is not // CONSOLE. - string trust_region_problem_dump_directory; + std::string trust_region_problem_dump_directory; DumpFormatType trust_region_problem_dump_format_type; // Finite differences options ---------------------------------------------- @@ -746,7 +747,7 @@ class CERES_EXPORT Solver { // executed, then set update_state_every_iteration to true. // // The solver does NOT take ownership of these pointers. - vector<IterationCallback*> callbacks; + std::vector<IterationCallback*> callbacks; }; struct CERES_EXPORT Summary { @@ -754,11 +755,11 @@ class CERES_EXPORT Solver { // A brief one line description of the state of the solver after // termination. - string BriefReport() const; + std::string BriefReport() const; // A full multiline description of the state of the solver after // termination. - string FullReport() const; + std::string FullReport() const; bool IsSolutionUsable() const; @@ -768,7 +769,7 @@ class CERES_EXPORT Solver { TerminationType termination_type; // Reason why the solver terminated. - string message; + std::string message; // Cost of the problem (value of the objective function) before // the optimization. @@ -784,7 +785,7 @@ class CERES_EXPORT Solver { double fixed_cost; // IterationSummary for each minimizer iteration in order. - vector<IterationSummary> iterations; + std::vector<IterationSummary> iterations; // Number of minimizer iterations in which the step was // accepted. Unless use_non_monotonic_steps is true this is also @@ -832,6 +833,26 @@ class CERES_EXPORT Solver { // Time (in seconds) spent doing inner iterations. double inner_iteration_time_in_seconds; + // Cumulative timing information for line searches performed as part of the + // solve. Note that in addition to the case when the Line Search minimizer + // is used, the Trust Region minimizer also uses a line search when + // solving a constrained problem. + + // Time (in seconds) spent evaluating the univariate cost function as part + // of a line search. + double line_search_cost_evaluation_time_in_seconds; + + // Time (in seconds) spent evaluating the gradient of the univariate cost + // function as part of a line search. + double line_search_gradient_evaluation_time_in_seconds; + + // Time (in seconds) spent minimizing the interpolating polynomial + // to compute the next candidate step size as part of a line search. + double line_search_polynomial_minimization_time_in_seconds; + + // Total time (in seconds) spent performing line searches. + double line_search_total_time_in_seconds; + // Number of parameter blocks in the problem. int num_parameter_blocks; @@ -871,6 +892,9 @@ class CERES_EXPORT Solver { // Number of residuals in the reduced problem. int num_residuals_reduced; + // Is the reduced problem bounds constrained. + bool is_constrained; + // Number of threads specified by the user for Jacobian and // residual evaluation. int num_threads_given; @@ -902,7 +926,7 @@ class CERES_EXPORT Solver { // Size of the elimination groups given by the user as hints to // the linear solver. - vector<int> linear_solver_ordering_given; + std::vector<int> linear_solver_ordering_given; // Size of the parameter groups used by the solver when ordering // the columns of the Jacobian. This maybe different from @@ -910,7 +934,7 @@ class CERES_EXPORT Solver { // linear_solver_ordering_given blank and asked for an automatic // ordering, or if the problem contains some constant or inactive // parameter blocks. - vector<int> linear_solver_ordering_used; + std::vector<int> linear_solver_ordering_used; // True if the user asked for inner iterations to be used as part // of the optimization. @@ -924,7 +948,7 @@ class CERES_EXPORT Solver { // Size of the parameter groups given by the user for performing // inner iterations. - vector<int> inner_iteration_ordering_given; + std::vector<int> inner_iteration_ordering_given; // Size of the parameter groups given used by the solver for // performing inner iterations. This maybe different from @@ -932,7 +956,7 @@ class CERES_EXPORT Solver { // inner_iteration_ordering_given blank and asked for an automatic // ordering, or if the problem contains some constant or inactive // parameter blocks. - vector<int> inner_iteration_ordering_used; + std::vector<int> inner_iteration_ordering_used; // Type of the preconditioner requested by the user. PreconditionerType preconditioner_type_given; diff --git a/extern/libmv/third_party/ceres/include/ceres/types.h b/extern/libmv/third_party/ceres/include/ceres/types.h index a07c8933e64..2ea41803629 100644 --- a/extern/libmv/third_party/ceres/include/ceres/types.h +++ b/extern/libmv/third_party/ceres/include/ceres/types.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -157,7 +157,12 @@ enum SparseLinearAlgebraLibraryType { // Eigen's sparse linear algebra routines. In particular Ceres uses // the Simplicial LDLT routines. - EIGEN_SPARSE + EIGEN_SPARSE, + + // No sparse linear solver should be used. This does not necessarily + // imply that Ceres was built without any sparse library, although that + // is the likely use case, merely that one should not be used. + NO_SPARSE }; enum DenseLinearAlgebraLibraryType { @@ -392,9 +397,19 @@ enum DimensionType { DYNAMIC = -1 }; -enum NumericDiffMethod { +// The differentiation method used to compute numerical derivatives in +// NumericDiffCostFunction and DynamicNumericDiffCostFunction. +enum NumericDiffMethodType { + // Compute central finite difference: f'(x) ~ (f(x+h) - f(x-h)) / 2h. CENTRAL, - FORWARD + + // Compute forward finite difference: f'(x) ~ (f(x+h) - f(x)) / h. + FORWARD, + + // Adaptive numerical differentiation using Ridders' method. Provides more + // accurate and robust derivatives at the expense of additional cost + // function evaluations. + RIDDERS }; enum LineSearchInterpolationType { @@ -411,67 +426,73 @@ enum CovarianceAlgorithmType { CERES_EXPORT const char* LinearSolverTypeToString( LinearSolverType type); -CERES_EXPORT bool StringToLinearSolverType(string value, +CERES_EXPORT bool StringToLinearSolverType(std::string value, LinearSolverType* type); CERES_EXPORT const char* PreconditionerTypeToString(PreconditionerType type); -CERES_EXPORT bool StringToPreconditionerType(string value, +CERES_EXPORT bool StringToPreconditionerType(std::string value, PreconditionerType* type); CERES_EXPORT const char* VisibilityClusteringTypeToString( VisibilityClusteringType type); -CERES_EXPORT bool StringToVisibilityClusteringType(string value, +CERES_EXPORT bool StringToVisibilityClusteringType(std::string value, VisibilityClusteringType* type); CERES_EXPORT const char* SparseLinearAlgebraLibraryTypeToString( SparseLinearAlgebraLibraryType type); CERES_EXPORT bool StringToSparseLinearAlgebraLibraryType( - string value, + std::string value, SparseLinearAlgebraLibraryType* type); CERES_EXPORT const char* DenseLinearAlgebraLibraryTypeToString( DenseLinearAlgebraLibraryType type); CERES_EXPORT bool StringToDenseLinearAlgebraLibraryType( - string value, + std::string value, DenseLinearAlgebraLibraryType* type); CERES_EXPORT const char* TrustRegionStrategyTypeToString( TrustRegionStrategyType type); -CERES_EXPORT bool StringToTrustRegionStrategyType(string value, +CERES_EXPORT bool StringToTrustRegionStrategyType(std::string value, TrustRegionStrategyType* type); CERES_EXPORT const char* DoglegTypeToString(DoglegType type); -CERES_EXPORT bool StringToDoglegType(string value, DoglegType* type); +CERES_EXPORT bool StringToDoglegType(std::string value, DoglegType* type); CERES_EXPORT const char* MinimizerTypeToString(MinimizerType type); -CERES_EXPORT bool StringToMinimizerType(string value, MinimizerType* type); +CERES_EXPORT bool StringToMinimizerType(std::string value, MinimizerType* type); CERES_EXPORT const char* LineSearchDirectionTypeToString( LineSearchDirectionType type); -CERES_EXPORT bool StringToLineSearchDirectionType(string value, +CERES_EXPORT bool StringToLineSearchDirectionType(std::string value, LineSearchDirectionType* type); CERES_EXPORT const char* LineSearchTypeToString(LineSearchType type); -CERES_EXPORT bool StringToLineSearchType(string value, LineSearchType* type); +CERES_EXPORT bool StringToLineSearchType(std::string value, LineSearchType* type); CERES_EXPORT const char* NonlinearConjugateGradientTypeToString( NonlinearConjugateGradientType type); CERES_EXPORT bool StringToNonlinearConjugateGradientType( - string value, + std::string value, NonlinearConjugateGradientType* type); CERES_EXPORT const char* LineSearchInterpolationTypeToString( LineSearchInterpolationType type); CERES_EXPORT bool StringToLineSearchInterpolationType( - string value, + std::string value, LineSearchInterpolationType* type); CERES_EXPORT const char* CovarianceAlgorithmTypeToString( CovarianceAlgorithmType type); CERES_EXPORT bool StringToCovarianceAlgorithmType( - string value, + std::string value, CovarianceAlgorithmType* type); +CERES_EXPORT const char* NumericDiffMethodTypeToString( + NumericDiffMethodType type); +CERES_EXPORT bool StringToNumericDiffMethodType( + std::string value, + NumericDiffMethodType* type); + CERES_EXPORT const char* TerminationTypeToString(TerminationType type); CERES_EXPORT bool IsSchurType(LinearSolverType type); diff --git a/extern/libmv/third_party/ceres/include/ceres/version.h b/extern/libmv/third_party/ceres/include/ceres/version.h index 370b08af73e..66505a515c9 100644 --- a/extern/libmv/third_party/ceres/include/ceres/version.h +++ b/extern/libmv/third_party/ceres/include/ceres/version.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -32,9 +32,8 @@ #define CERES_PUBLIC_VERSION_H_ #define CERES_VERSION_MAJOR 1 -#define CERES_VERSION_MINOR 10 +#define CERES_VERSION_MINOR 11 #define CERES_VERSION_REVISION 0 -#define CERES_VERSION_ABI 1 // Classic CPP stringifcation; the extra level of indirection allows the // preprocessor to expand the macro before being converted to a string. diff --git a/extern/libmv/third_party/ceres/internal/ceres/array_utils.cc b/extern/libmv/third_party/ceres/internal/ceres/array_utils.cc index 205ddaf27c9..7be3c78ce24 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/array_utils.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/array_utils.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -41,6 +41,8 @@ namespace ceres { namespace internal { +using std::string; + // It is a near impossibility that user code generates this exact // value in normal operation, thus we will use it to fill arrays // before passing them to user code. If on return an element of the @@ -71,7 +73,7 @@ int FindInvalidValue(const int size, const double* x) { } return size; -}; +} void InvalidateArray(const int size, double* x) { if (x != NULL) { diff --git a/extern/libmv/third_party/ceres/internal/ceres/array_utils.h b/extern/libmv/third_party/ceres/internal/ceres/array_utils.h index 7f56947066b..2d2ffca8809 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/array_utils.h +++ b/extern/libmv/third_party/ceres/internal/ceres/array_utils.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -43,6 +43,7 @@ #ifndef CERES_INTERNAL_ARRAY_UTILS_H_ #define CERES_INTERNAL_ARRAY_UTILS_H_ +#include <string> #include "ceres/internal/port.h" namespace ceres { @@ -63,7 +64,7 @@ int FindInvalidValue(const int size, const double* x); // Utility routine to print an array of doubles to a string. If the // array pointer is NULL, it is treated as an array of zeros. -void AppendArrayToString(const int size, const double* x, string* result); +void AppendArrayToString(const int size, const double* x, std::string* result); extern const double kImpossibleValue; diff --git a/extern/libmv/third_party/ceres/internal/ceres/blas.cc b/extern/libmv/third_party/ceres/internal/ceres/blas.cc index b919e13c4a9..3ba63bbed5a 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/blas.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/blas.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -32,6 +32,7 @@ #include "ceres/internal/port.h" #include "glog/logging.h" +#ifndef CERES_NO_LAPACK extern "C" void dsyrk_(char* uplo, char* trans, int* n, @@ -42,6 +43,7 @@ extern "C" void dsyrk_(char* uplo, double* beta, double* c, int* ldc); +#endif namespace ceres { namespace internal { diff --git a/extern/libmv/third_party/ceres/internal/ceres/blas.h b/extern/libmv/third_party/ceres/internal/ceres/blas.h index 2ab666395b9..a43301c5d18 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/blas.h +++ b/extern/libmv/third_party/ceres/internal/ceres/blas.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/block_evaluate_preparer.cc b/extern/libmv/third_party/ceres/internal/ceres/block_evaluate_preparer.cc index 9edc4fa23bd..59c0d3ecc10 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/block_evaluate_preparer.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/block_evaluate_preparer.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/block_evaluate_preparer.h b/extern/libmv/third_party/ceres/internal/ceres/block_evaluate_preparer.h index 354acc031f4..4378689729f 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/block_evaluate_preparer.h +++ b/extern/libmv/third_party/ceres/internal/ceres/block_evaluate_preparer.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/block_jacobi_preconditioner.cc b/extern/libmv/third_party/ceres/internal/ceres/block_jacobi_preconditioner.cc index 7f79a4f993d..22d4b351c51 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/block_jacobi_preconditioner.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/block_jacobi_preconditioner.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -43,7 +43,7 @@ namespace internal { BlockJacobiPreconditioner::BlockJacobiPreconditioner( const BlockSparseMatrix& A) { const CompressedRowBlockStructure* bs = A.block_structure(); - vector<int> blocks(bs->cols.size()); + std::vector<int> blocks(bs->cols.size()); for (int i = 0; i < blocks.size(); ++i) { blocks[i] = bs->cols[i].size; } @@ -60,7 +60,7 @@ bool BlockJacobiPreconditioner::UpdateImpl(const BlockSparseMatrix& A, m_->SetZero(); for (int i = 0; i < bs->rows.size(); ++i) { const int row_block_size = bs->rows[i].block.size; - const vector<Cell>& cells = bs->rows[i].cells; + const std::vector<Cell>& cells = bs->rows[i].cells; for (int j = 0; j < cells.size(); ++j) { const int block_id = cells[j].block_id; const int col_block_size = bs->cols[block_id].size; diff --git a/extern/libmv/third_party/ceres/internal/ceres/block_jacobi_preconditioner.h b/extern/libmv/third_party/ceres/internal/ceres/block_jacobi_preconditioner.h index e23e0e2d24c..14007295823 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/block_jacobi_preconditioner.h +++ b/extern/libmv/third_party/ceres/internal/ceres/block_jacobi_preconditioner.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/block_jacobian_writer.cc b/extern/libmv/third_party/ceres/internal/ceres/block_jacobian_writer.cc index f90c350cc80..7a3fee4fbdf 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/block_jacobian_writer.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/block_jacobian_writer.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -41,6 +41,9 @@ namespace ceres { namespace internal { + +using std::vector; + namespace { // Given the residual block ordering, build a lookup table to determine which @@ -163,8 +166,7 @@ SparseMatrix* BlockJacobianWriter::CreateJacobian() const { } // Construct the cells in each row. - const vector<ResidualBlock*>& residual_blocks = - program_->residual_blocks(); + const vector<ResidualBlock*>& residual_blocks = program_->residual_blocks(); int row_block_position = 0; bs->rows.resize(residual_blocks.size()); for (int i = 0; i < residual_blocks.size(); ++i) { diff --git a/extern/libmv/third_party/ceres/internal/ceres/block_jacobian_writer.h b/extern/libmv/third_party/ceres/internal/ceres/block_jacobian_writer.h index 140c7211129..8e6f45130a4 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/block_jacobian_writer.h +++ b/extern/libmv/third_party/ceres/internal/ceres/block_jacobian_writer.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -115,10 +115,10 @@ class BlockJacobianWriter { // // which indicates that dr/dx is located at values_[0], and dr/dz is at // values_[12]. See BlockEvaluatePreparer::Prepare()'s comments about 'j'. - vector<int*> jacobian_layout_; + std::vector<int*> jacobian_layout_; // The pointers in jacobian_layout_ point directly into this vector. - vector<int> jacobian_layout_storage_; + std::vector<int> jacobian_layout_storage_; }; } // namespace internal 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 e5822792fa1..61748ef6f7f 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 @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -39,7 +39,7 @@ namespace ceres { namespace internal { BlockRandomAccessDenseMatrix::BlockRandomAccessDenseMatrix( - const vector<int>& blocks) { + const std::vector<int>& blocks) { const int num_blocks = blocks.size(); block_layout_.resize(num_blocks, 0); num_rows_ = 0; 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 d160fd96013..89689082561 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 @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -56,7 +56,7 @@ class BlockRandomAccessDenseMatrix : public BlockRandomAccessMatrix { public: // blocks is a vector of block sizes. The resulting matrix has // blocks.size() * blocks.size() cells. - explicit BlockRandomAccessDenseMatrix(const vector<int>& blocks); + explicit BlockRandomAccessDenseMatrix(const std::vector<int>& blocks); // The destructor is not thread safe. It assumes that no one is // modifying any cells when the matrix is being destroyed. @@ -85,7 +85,7 @@ class BlockRandomAccessDenseMatrix : public BlockRandomAccessMatrix { private: int num_rows_; - vector<int> block_layout_; + std::vector<int> block_layout_; scoped_array<double> values_; scoped_array<CellInfo> cell_infos_; diff --git a/extern/libmv/third_party/ceres/internal/ceres/block_random_access_diagonal_matrix.cc b/extern/libmv/third_party/ceres/internal/ceres/block_random_access_diagonal_matrix.cc index b7ff33184cb..052690d18be 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/block_random_access_diagonal_matrix.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/block_random_access_diagonal_matrix.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -45,6 +45,8 @@ namespace ceres { namespace internal { +using std::vector; + // TODO(sameeragarwal): Drop the dependence on TripletSparseMatrix. BlockRandomAccessDiagonalMatrix::BlockRandomAccessDiagonalMatrix( diff --git a/extern/libmv/third_party/ceres/internal/ceres/block_random_access_diagonal_matrix.h b/extern/libmv/third_party/ceres/internal/ceres/block_random_access_diagonal_matrix.h index ea9967817db..07ffc9d4a0d 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/block_random_access_diagonal_matrix.h +++ b/extern/libmv/third_party/ceres/internal/ceres/block_random_access_diagonal_matrix.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -52,7 +52,7 @@ namespace internal { class BlockRandomAccessDiagonalMatrix : public BlockRandomAccessMatrix { public: // blocks is an array of block sizes. - explicit BlockRandomAccessDiagonalMatrix(const vector<int>& blocks); + explicit BlockRandomAccessDiagonalMatrix(const std::vector<int>& blocks); // The destructor is not thread safe. It assumes that no one is // modifying any cells when the matrix is being destroyed. @@ -85,8 +85,8 @@ class BlockRandomAccessDiagonalMatrix : public BlockRandomAccessMatrix { private: // row/column block sizes. - const vector<int> blocks_; - vector<CellInfo*> layout_; + const std::vector<int> blocks_; + std::vector<CellInfo*> layout_; // The underlying matrix object which actually stores the cells. scoped_ptr<TripletSparseMatrix> tsm_; diff --git a/extern/libmv/third_party/ceres/internal/ceres/block_random_access_matrix.cc b/extern/libmv/third_party/ceres/internal/ceres/block_random_access_matrix.cc index 58fe4a10de3..347d765bbca 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/block_random_access_matrix.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/block_random_access_matrix.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/block_random_access_matrix.h b/extern/libmv/third_party/ceres/internal/ceres/block_random_access_matrix.h index b76cb78b160..34c8bf5cd4d 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/block_random_access_matrix.h +++ b/extern/libmv/third_party/ceres/internal/ceres/block_random_access_matrix.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/block_random_access_sparse_matrix.cc b/extern/libmv/third_party/ceres/internal/ceres/block_random_access_sparse_matrix.cc index c43a9b78feb..5432ec1064a 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/block_random_access_sparse_matrix.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/block_random_access_sparse_matrix.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -44,6 +44,11 @@ namespace ceres { namespace internal { +using std::make_pair; +using std::pair; +using std::set; +using std::vector; + BlockRandomAccessSparseMatrix::BlockRandomAccessSparseMatrix( const vector<int>& blocks, const set<pair<int, int> >& block_pairs) diff --git a/extern/libmv/third_party/ceres/internal/ceres/block_random_access_sparse_matrix.h b/extern/libmv/third_party/ceres/internal/ceres/block_random_access_sparse_matrix.h index 51b5d20cfe0..2b3c7fdabae 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/block_random_access_sparse_matrix.h +++ b/extern/libmv/third_party/ceres/internal/ceres/block_random_access_sparse_matrix.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -57,8 +57,9 @@ class BlockRandomAccessSparseMatrix : public BlockRandomAccessMatrix { // blocks is an array of block sizes. block_pairs is a set of // <row_block_id, col_block_id> pairs to identify the non-zero cells // of this matrix. - BlockRandomAccessSparseMatrix(const vector<int>& blocks, - const set<pair<int, int> >& block_pairs); + BlockRandomAccessSparseMatrix( + const std::vector<int>& blocks, + const std::set<std::pair<int, int> >& block_pairs); // The destructor is not thread safe. It assumes that no one is // modifying any cells when the matrix is being destroyed. @@ -103,8 +104,8 @@ class BlockRandomAccessSparseMatrix : public BlockRandomAccessMatrix { const int64 kMaxRowBlocks; // row/column block sizes. - const vector<int> blocks_; - vector<int> block_positions_; + const std::vector<int> blocks_; + std::vector<int> block_positions_; // A mapping from <row_block_id, col_block_id> to the position in // the values array of tsm_ where the block is stored. @@ -114,7 +115,7 @@ class BlockRandomAccessSparseMatrix : public BlockRandomAccessMatrix { // In order traversal of contents of the matrix. This allows us to // implement a matrix-vector which is 20% faster than using the // iterator in the Layout object instead. - vector<pair<pair<int, int>, double*> > cell_values_; + std::vector<std::pair<std::pair<int, int>, double*> > cell_values_; // The underlying matrix object which actually stores the cells. scoped_ptr<TripletSparseMatrix> tsm_; diff --git a/extern/libmv/third_party/ceres/internal/ceres/block_sparse_matrix.cc b/extern/libmv/third_party/ceres/internal/ceres/block_sparse_matrix.cc index a4872626114..68d0780156c 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/block_sparse_matrix.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/block_sparse_matrix.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -42,6 +42,8 @@ namespace ceres { namespace internal { +using std::vector; + BlockSparseMatrix::~BlockSparseMatrix() {} BlockSparseMatrix::BlockSparseMatrix( @@ -82,7 +84,7 @@ BlockSparseMatrix::BlockSparseMatrix( } void BlockSparseMatrix::SetZero() { - fill(values_.get(), values_.get() + num_nonzeros_, 0.0); + std::fill(values_.get(), values_.get() + num_nonzeros_, 0.0); } void BlockSparseMatrix::RightMultiply(const double* x, double* y) const { diff --git a/extern/libmv/third_party/ceres/internal/ceres/block_sparse_matrix.h b/extern/libmv/third_party/ceres/internal/ceres/block_sparse_matrix.h index e17d12a706e..2f9afb738f8 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/block_sparse_matrix.h +++ b/extern/libmv/third_party/ceres/internal/ceres/block_sparse_matrix.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/block_structure.cc b/extern/libmv/third_party/ceres/internal/ceres/block_structure.cc index 00c4ce2814b..6479b60f700 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/block_structure.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/block_structure.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/block_structure.h b/extern/libmv/third_party/ceres/internal/ceres/block_structure.h index 656716ef022..6e7003addb6 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/block_structure.h +++ b/extern/libmv/third_party/ceres/internal/ceres/block_structure.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -71,20 +71,20 @@ bool CellLessThan(const Cell& lhs, const Cell& rhs); struct CompressedList { Block block; - vector<Cell> cells; + std::vector<Cell> cells; }; typedef CompressedList CompressedRow; typedef CompressedList CompressedColumn; struct CompressedRowBlockStructure { - vector<Block> cols; - vector<CompressedRow> rows; + std::vector<Block> cols; + std::vector<CompressedRow> rows; }; struct CompressedColumnBlockStructure { - vector<Block> rows; - vector<CompressedColumn> cols; + std::vector<Block> rows; + std::vector<CompressedColumn> cols; }; } // namespace internal diff --git a/extern/libmv/third_party/ceres/internal/ceres/c_api.cc b/extern/libmv/third_party/ceres/internal/ceres/c_api.cc index 1fd01c9f0bd..ada8f3e0013 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/c_api.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/c_api.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/callbacks.cc b/extern/libmv/third_party/ceres/internal/ceres/callbacks.cc index 7d5ce2548e4..50a0ec19924 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/callbacks.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/callbacks.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -37,6 +37,8 @@ namespace ceres { namespace internal { +using std::string; + StateUpdatingCallback::StateUpdatingCallback(Program* program, double* parameters) : program_(program), parameters_(parameters) {} @@ -78,27 +80,27 @@ CallbackReturnType LoggingCallback::operator()( summary.cumulative_time_in_seconds); } else if (minimizer_type == TRUST_REGION) { if (summary.iteration == 0) { - output = "iter cost cost_change |gradient| |step| tr_ratio tr_radius ls_iter iter_time total_time\n"; + output = "iter cost cost_change |gradient| |step| tr_ratio tr_radius ls_iter iter_time total_time\n"; // NOLINT } const char* kReportRowFormat = - "% 4d % 8e % 3.2e % 3.2e % 3.2e % 3.2e % 3.2e % 4d % 3.2e % 3.2e"; + "% 4d % 8e % 3.2e % 3.2e % 3.2e % 3.2e % 3.2e % 4d % 3.2e % 3.2e"; // NOLINT output += StringPrintf(kReportRowFormat, - summary.iteration, - summary.cost, - summary.cost_change, - summary.gradient_max_norm, - summary.step_norm, - summary.relative_decrease, - summary.trust_region_radius, - summary.linear_solver_iterations, - summary.iteration_time_in_seconds, - summary.cumulative_time_in_seconds); + summary.iteration, + summary.cost, + summary.cost_change, + summary.gradient_max_norm, + summary.step_norm, + summary.relative_decrease, + summary.trust_region_radius, + summary.linear_solver_iterations, + summary.iteration_time_in_seconds, + summary.cumulative_time_in_seconds); } else { LOG(FATAL) << "Unknown minimizer type."; } if (log_to_stdout_) { - cout << output << endl; + std::cout << output << std::endl; } else { VLOG(1) << output; } diff --git a/extern/libmv/third_party/ceres/internal/ceres/callbacks.h b/extern/libmv/third_party/ceres/internal/ceres/callbacks.h index 93704dfd6d1..33c66df5c11 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/callbacks.h +++ b/extern/libmv/third_party/ceres/internal/ceres/callbacks.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/canonical_views_clustering.cc b/extern/libmv/third_party/ceres/internal/ceres/canonical_views_clustering.cc index 9bbab4b2377..b655b1eccd3 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/canonical_views_clustering.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/canonical_views_clustering.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -45,6 +45,8 @@ namespace ceres { namespace internal { +using std::vector; + typedef HashMap<int, int> IntMap; typedef HashSet<int> IntSet; diff --git a/extern/libmv/third_party/ceres/internal/ceres/canonical_views_clustering.h b/extern/libmv/third_party/ceres/internal/ceres/canonical_views_clustering.h index d3fa5725831..6b0b38a854d 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/canonical_views_clustering.h +++ b/extern/libmv/third_party/ceres/internal/ceres/canonical_views_clustering.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -102,7 +102,7 @@ struct CanonicalViewsClusteringOptions; void ComputeCanonicalViewsClustering( const CanonicalViewsClusteringOptions& options, const WeightedGraph<int>& graph, - vector<int>* centers, + std::vector<int>* centers, HashMap<int, int>* membership); struct CanonicalViewsClusteringOptions { diff --git a/extern/libmv/third_party/ceres/internal/ceres/casts.h b/extern/libmv/third_party/ceres/internal/ceres/casts.h index 99cf2186cc7..f18fdea2d86 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/casts.h +++ b/extern/libmv/third_party/ceres/internal/ceres/casts.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/cgnr_linear_operator.h b/extern/libmv/third_party/ceres/internal/ceres/cgnr_linear_operator.h index f32d8d95c19..44c07cabd01 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/cgnr_linear_operator.h +++ b/extern/libmv/third_party/ceres/internal/ceres/cgnr_linear_operator.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/cgnr_solver.cc b/extern/libmv/third_party/ceres/internal/ceres/cgnr_solver.cc index 88e61d9ed1b..61fae758d5b 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/cgnr_solver.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/cgnr_solver.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/cgnr_solver.h b/extern/libmv/third_party/ceres/internal/ceres/cgnr_solver.h index c63484c628b..f7a15736925 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/cgnr_solver.h +++ b/extern/libmv/third_party/ceres/internal/ceres/cgnr_solver.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/collections_port.h b/extern/libmv/third_party/ceres/internal/ceres/collections_port.h index 3f976b9fb59..e699a661b8b 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/collections_port.h +++ b/extern/libmv/third_party/ceres/internal/ceres/collections_port.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -69,7 +69,6 @@ #include <utility> #include "ceres/integral_types.h" -#include "ceres/internal/port.h" // Some systems don't have access to unordered_map/unordered_set. In // that case, substitute the hash map/set with normal map/set. The diff --git a/extern/libmv/third_party/ceres/internal/ceres/compressed_col_sparse_matrix_utils.cc b/extern/libmv/third_party/ceres/internal/ceres/compressed_col_sparse_matrix_utils.cc index b62a6ed3830..ebb2a62c544 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/compressed_col_sparse_matrix_utils.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/compressed_col_sparse_matrix_utils.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -38,12 +38,15 @@ namespace ceres { namespace internal { -void CompressedColumnScalarMatrixToBlockMatrix(const int* scalar_rows, - const int* scalar_cols, - const vector<int>& row_blocks, - const vector<int>& col_blocks, - vector<int>* block_rows, - vector<int>* block_cols) { +using std::vector; + +void CompressedColumnScalarMatrixToBlockMatrix( + const int* scalar_rows, + const int* scalar_cols, + const vector<int>& row_blocks, + const vector<int>& col_blocks, + vector<int>* block_rows, + vector<int>* block_cols) { CHECK_NOTNULL(block_rows)->clear(); CHECK_NOTNULL(block_cols)->clear(); const int num_row_blocks = row_blocks.size(); @@ -66,9 +69,10 @@ void CompressedColumnScalarMatrixToBlockMatrix(const int* scalar_rows, for (int col_block = 0; col_block < num_col_blocks; ++col_block) { int column_size = 0; for (int idx = scalar_cols[c]; idx < scalar_cols[c + 1]; ++idx) { - vector<int>::const_iterator it = lower_bound(row_block_starts.begin(), - row_block_starts.end(), - scalar_rows[idx]); + vector<int>::const_iterator it = + std::lower_bound(row_block_starts.begin(), + row_block_starts.end(), + scalar_rows[idx]); // Since we are using lower_bound, it will return the row id // where the row block starts. For everything but the first row // of the block, where these values will be the same, we can diff --git a/extern/libmv/third_party/ceres/internal/ceres/compressed_col_sparse_matrix_utils.h b/extern/libmv/third_party/ceres/internal/ceres/compressed_col_sparse_matrix_utils.h index c8de2a1591a..da2109fba3e 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/compressed_col_sparse_matrix_utils.h +++ b/extern/libmv/third_party/ceres/internal/ceres/compressed_col_sparse_matrix_utils.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -47,19 +47,21 @@ namespace internal { // and column block j, then it is expected that A contains at least // one non-zero entry corresponding to the top left entry of c_ij, // as that entry is used to detect the presence of a non-zero c_ij. -void CompressedColumnScalarMatrixToBlockMatrix(const int* scalar_rows, - const int* scalar_cols, - const vector<int>& row_blocks, - const vector<int>& col_blocks, - vector<int>* block_rows, - vector<int>* block_cols); +void CompressedColumnScalarMatrixToBlockMatrix( + const int* scalar_rows, + const int* scalar_cols, + const std::vector<int>& row_blocks, + const std::vector<int>& col_blocks, + std::vector<int>* block_rows, + std::vector<int>* block_cols); // Given a set of blocks and a permutation of these blocks, compute // the corresponding "scalar" ordering, where the scalar ordering of // size sum(blocks). -void BlockOrderingToScalarOrdering(const vector<int>& blocks, - const vector<int>& block_ordering, - vector<int>* scalar_ordering); +void BlockOrderingToScalarOrdering( + const std::vector<int>& blocks, + const std::vector<int>& block_ordering, + std::vector<int>* scalar_ordering); // Solve the linear system // @@ -120,7 +122,7 @@ void SolveRTRWithSparseRHS(IntegerType num_cols, const double* values, const int rhs_nonzero_index, double* solution) { - fill(solution, solution + num_cols, 0.0); + std::fill(solution, solution + num_cols, 0.0); solution[rhs_nonzero_index] = 1.0 / values[cols[rhs_nonzero_index + 1] - 1]; for (IntegerType c = rhs_nonzero_index + 1; c < num_cols; ++c) { diff --git a/extern/libmv/third_party/ceres/internal/ceres/compressed_row_jacobian_writer.cc b/extern/libmv/third_party/ceres/internal/ceres/compressed_row_jacobian_writer.cc index ed8db14c99a..64b6ac00447 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/compressed_row_jacobian_writer.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/compressed_row_jacobian_writer.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -30,6 +30,9 @@ #include "ceres/compressed_row_jacobian_writer.h" +#include <utility> +#include <vector> + #include "ceres/casts.h" #include "ceres/compressed_row_sparse_matrix.h" #include "ceres/parameter_block.h" @@ -40,6 +43,10 @@ namespace ceres { namespace internal { +using std::make_pair; +using std::pair; +using std::vector; + void CompressedRowJacobianWriter::PopulateJacobianRowAndColumnBlockVectors( const Program* program, CompressedRowSparseMatrix* jacobian) { const vector<ParameterBlock*>& parameter_blocks = @@ -214,9 +221,9 @@ void CompressedRowJacobianWriter::Write(int residual_id, double* column_block_begin = jacobian_values + jacobian_rows[residual_offset + r] + col_pos; - copy(block_row_begin, - block_row_begin + parameter_block_size, - column_block_begin); + std::copy(block_row_begin, + block_row_begin + parameter_block_size, + column_block_begin); } col_pos += parameter_block_size; } diff --git a/extern/libmv/third_party/ceres/internal/ceres/compressed_row_jacobian_writer.h b/extern/libmv/third_party/ceres/internal/ceres/compressed_row_jacobian_writer.h index a722a7c28e3..1cd01235ccf 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/compressed_row_jacobian_writer.h +++ b/extern/libmv/third_party/ceres/internal/ceres/compressed_row_jacobian_writer.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -33,6 +33,9 @@ #ifndef CERES_INTERNAL_COMPRESSED_ROW_JACOBIAN_WRITER_H_ #define CERES_INTERNAL_COMPRESSED_ROW_JACOBIAN_WRITER_H_ +#include <utility> +#include <vector> + #include "ceres/evaluator.h" #include "ceres/scratch_evaluate_preparer.h" @@ -80,7 +83,7 @@ class CompressedRowJacobianWriter { static void GetOrderedParameterBlocks( const Program* program, int residual_id, - vector<pair<int, int> >* evaluated_jacobian_blocks); + std::vector<std::pair<int, int> >* evaluated_jacobian_blocks); // JacobianWriter interface. diff --git a/extern/libmv/third_party/ceres/internal/ceres/compressed_row_sparse_matrix.cc b/extern/libmv/third_party/ceres/internal/ceres/compressed_row_sparse_matrix.cc index 7993ed6917a..91d18bbd604 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/compressed_row_sparse_matrix.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/compressed_row_sparse_matrix.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -40,6 +40,9 @@ namespace ceres { namespace internal { + +using std::vector; + namespace { // Helper functor used by the constructor for reordering the contents @@ -155,7 +158,7 @@ CompressedRowSparseMatrix::~CompressedRowSparseMatrix() { } void CompressedRowSparseMatrix::SetZero() { - fill(values_.begin(), values_.end(), 0); + std::fill(values_.begin(), values_.end(), 0); } void CompressedRowSparseMatrix::RightMultiply(const double* x, @@ -184,7 +187,7 @@ void CompressedRowSparseMatrix::LeftMultiply(const double* x, double* y) const { void CompressedRowSparseMatrix::SquaredColumnNorm(double* x) const { CHECK_NOTNULL(x); - fill(x, x + num_cols_, 0.0); + std::fill(x, x + num_cols_, 0.0); for (int idx = 0; idx < rows_[num_rows_]; ++idx) { x[cols_[idx]] += values_[idx] * values_[idx]; } @@ -238,26 +241,38 @@ void CompressedRowSparseMatrix::AppendRows(const CompressedRowSparseMatrix& m) { << "The matrix being appended has: " << m.row_blocks().size() << " row blocks."; + if (m.num_rows() == 0) { + return; + } + if (cols_.size() < num_nonzeros() + m.num_nonzeros()) { cols_.resize(num_nonzeros() + m.num_nonzeros()); values_.resize(num_nonzeros() + m.num_nonzeros()); } // Copy the contents of m into this matrix. - copy(m.cols(), m.cols() + m.num_nonzeros(), &cols_[num_nonzeros()]); - copy(m.values(), m.values() + m.num_nonzeros(), &values_[num_nonzeros()]); + DCHECK_LT(num_nonzeros(), cols_.size()); + if (m.num_nonzeros() > 0) { + std::copy(m.cols(), m.cols() + m.num_nonzeros(), &cols_[num_nonzeros()]); + std::copy(m.values(), + m.values() + m.num_nonzeros(), + &values_[num_nonzeros()]); + } + rows_.resize(num_rows_ + m.num_rows() + 1); // new_rows = [rows_, m.row() + rows_[num_rows_]] - fill(rows_.begin() + num_rows_, - rows_.begin() + num_rows_ + m.num_rows() + 1, - rows_[num_rows_]); + std::fill(rows_.begin() + num_rows_, + rows_.begin() + num_rows_ + m.num_rows() + 1, + rows_[num_rows_]); for (int r = 0; r < m.num_rows() + 1; ++r) { rows_[num_rows_ + r] += m.rows()[r]; } num_rows_ += m.num_rows(); - row_blocks_.insert(row_blocks_.end(), m.row_blocks().begin(), m.row_blocks().end()); + row_blocks_.insert(row_blocks_.end(), + m.row_blocks().begin(), + m.row_blocks().end()); } void CompressedRowSparseMatrix::ToTextFile(FILE* file) const { @@ -329,7 +344,7 @@ CompressedRowSparseMatrix* CompressedRowSparseMatrix::CreateBlockDiagonalMatrix( int* rows = matrix->mutable_rows(); int* cols = matrix->mutable_cols(); double* values = matrix->mutable_values(); - fill(values, values + num_nonzeros, 0.0); + std::fill(values, values + num_nonzeros, 0.0); int idx_cursor = 0; int col_cursor = 0; @@ -481,8 +496,9 @@ CompressedRowSparseMatrix::CreateOuterProductMatrixAndProgram( const CompressedRowSparseMatrix& m, vector<int>* program) { CHECK_NOTNULL(program)->clear(); - CHECK_GT(m.num_nonzeros(), 0) << "Congratulations, " - << "you found a bug in Ceres. Please report it."; + CHECK_GT(m.num_nonzeros(), 0) + << "Congratulations, " + << "you found a bug in Ceres. Please report it."; vector<ProductTerm> product; const vector<int>& row_blocks = m.row_blocks(); @@ -495,7 +511,9 @@ CompressedRowSparseMatrix::CreateOuterProductMatrixAndProgram( // Compute the lower triangular part of the product. for (int idx1 = m.rows()[r]; idx1 < m.rows()[r + 1]; ++idx1) { for (int idx2 = m.rows()[r]; idx2 <= idx1; ++idx2) { - product.push_back(ProductTerm(m.cols()[idx1], m.cols()[idx2], product.size())); + product.push_back(ProductTerm(m.cols()[idx1], + m.cols()[idx2], + product.size())); } } row_block_begin = row_block_end; diff --git a/extern/libmv/third_party/ceres/internal/ceres/compressed_row_sparse_matrix.h b/extern/libmv/third_party/ceres/internal/ceres/compressed_row_sparse_matrix.h index a0ba7eeb6ce..987339d09a1 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/compressed_row_sparse_matrix.h +++ b/extern/libmv/third_party/ceres/internal/ceres/compressed_row_sparse_matrix.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -109,11 +109,11 @@ class CompressedRowSparseMatrix : public SparseMatrix { const int* rows() const { return &rows_[0]; } int* mutable_rows() { return &rows_[0]; } - const vector<int>& row_blocks() const { return row_blocks_; } - vector<int>* mutable_row_blocks() { return &row_blocks_; } + const std::vector<int>& row_blocks() const { return row_blocks_; } + std::vector<int>* mutable_row_blocks() { return &row_blocks_; } - const vector<int>& col_blocks() const { return col_blocks_; } - vector<int>* mutable_col_blocks() { return &col_blocks_; } + const std::vector<int>& col_blocks() const { return col_blocks_; } + std::vector<int>* mutable_col_blocks() { return &col_blocks_; } // Destructive array resizing method. void SetMaxNumNonZeros(int num_nonzeros); @@ -129,7 +129,7 @@ class CompressedRowSparseMatrix : public SparseMatrix { static CompressedRowSparseMatrix* CreateBlockDiagonalMatrix( const double* diagonal, - const vector<int>& blocks); + const std::vector<int>& blocks); // Compute the sparsity structure of the product m.transpose() * m // and create a CompressedRowSparseMatrix corresponding to it. @@ -147,30 +147,30 @@ class CompressedRowSparseMatrix : public SparseMatrix { // this information for each row in the row block. static CompressedRowSparseMatrix* CreateOuterProductMatrixAndProgram( const CompressedRowSparseMatrix& m, - vector<int>* program); + std::vector<int>* program); // Compute the values array for the expression m.transpose() * m, // where the matrix used to store the result and a program have been // created using the CreateOuterProductMatrixAndProgram function // above. static void ComputeOuterProduct(const CompressedRowSparseMatrix& m, - const vector<int>& program, + const std::vector<int>& program, CompressedRowSparseMatrix* result); private: int num_rows_; int num_cols_; - vector<int> rows_; - vector<int> cols_; - vector<double> values_; + std::vector<int> rows_; + std::vector<int> cols_; + std::vector<double> values_; // If the matrix has an underlying block structure, then it can also // carry with it row and column block sizes. This is auxilliary and // optional information for use by algorithms operating on the // matrix. The class itself does not make use of this information in // any way. - vector<int> row_blocks_; - vector<int> col_blocks_; + std::vector<int> row_blocks_; + std::vector<int> col_blocks_; CERES_DISALLOW_COPY_AND_ASSIGN(CompressedRowSparseMatrix); }; diff --git a/extern/libmv/third_party/ceres/internal/ceres/conditioned_cost_function.cc b/extern/libmv/third_party/ceres/internal/ceres/conditioned_cost_function.cc index 7322790f717..08899e3d246 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/conditioned_cost_function.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/conditioned_cost_function.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -45,7 +45,7 @@ namespace ceres { // the one it's wrapping. ConditionedCostFunction::ConditionedCostFunction( CostFunction* wrapped_cost_function, - const vector<CostFunction*>& conditioners, + const std::vector<CostFunction*>& conditioners, Ownership ownership) : wrapped_cost_function_(wrapped_cost_function), conditioners_(conditioners), diff --git a/extern/libmv/third_party/ceres/internal/ceres/conjugate_gradients_solver.cc b/extern/libmv/third_party/ceres/internal/ceres/conjugate_gradients_solver.cc index 3071a0918e4..3702276a2fb 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/conjugate_gradients_solver.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/conjugate_gradients_solver.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -114,7 +114,6 @@ LinearSolver::Summary ConjugateGradientsSolver::Solve( double Q0 = -1.0 * xref.dot(bref + r); for (summary.num_iterations = 1;; ++summary.num_iterations) { - // Apply preconditioner if (per_solve_options.preconditioner != NULL) { z.setZero(); @@ -129,7 +128,7 @@ LinearSolver::Summary ConjugateGradientsSolver::Solve( summary.termination_type = LINEAR_SOLVER_FAILURE; summary.message = StringPrintf("Numerical failure. rho = r'z = %e.", rho); break; - }; + } if (summary.num_iterations == 1) { p = z; @@ -138,7 +137,8 @@ LinearSolver::Summary ConjugateGradientsSolver::Solve( if (IsZeroOrInfinity(beta)) { summary.termination_type = LINEAR_SOLVER_FAILURE; summary.message = StringPrintf( - "Numerical failure. beta = rho_n / rho_{n-1} = %e.", beta); + "Numerical failure. beta = rho_n / rho_{n-1} = %e, " + "rho_n = %e, rho_{n-1} = %e", beta, rho, last_rho); break; } p = z + beta * p; @@ -149,8 +149,11 @@ LinearSolver::Summary ConjugateGradientsSolver::Solve( A->RightMultiply(p.data(), q.data()); const double pq = p.dot(q); if ((pq <= 0) || IsInfinite(pq)) { - summary.termination_type = LINEAR_SOLVER_FAILURE; - summary.message = StringPrintf("Numerical failure. p'q = %e.", pq); + summary.termination_type = LINEAR_SOLVER_NO_CONVERGENCE; + summary.message = StringPrintf( + "Matrix is indefinite, no more progress can be made. " + "p'q = %e. |p| = %e, |q| = %e", + pq, p.norm(), q.norm()); break; } @@ -158,7 +161,8 @@ LinearSolver::Summary ConjugateGradientsSolver::Solve( if (IsInfinite(alpha)) { summary.termination_type = LINEAR_SOLVER_FAILURE; summary.message = - StringPrintf("Numerical failure. alpha = rho / pq = %e", alpha); + StringPrintf("Numerical failure. alpha = rho / pq = %e, " + "rho = %e, pq = %e.", alpha, rho, pq); break; } @@ -210,9 +214,11 @@ LinearSolver::Summary ConjugateGradientsSolver::Solve( summary.num_iterations >= options_.min_num_iterations) { summary.termination_type = LINEAR_SOLVER_SUCCESS; summary.message = - StringPrintf("Convergence: zeta = %e < %e", + StringPrintf("Iteration: %d Convergence: zeta = %e < %e. |r| = %e", + summary.num_iterations, zeta, - per_solve_options.q_tolerance); + per_solve_options.q_tolerance, + r.norm()); break; } Q0 = Q1; @@ -223,7 +229,10 @@ LinearSolver::Summary ConjugateGradientsSolver::Solve( summary.num_iterations >= options_.min_num_iterations) { summary.termination_type = LINEAR_SOLVER_SUCCESS; summary.message = - StringPrintf("Convergence. |r| = %e <= %e.", norm_r, tol_r); + StringPrintf("Iteration: %d Convergence. |r| = %e <= %e.", + summary.num_iterations, + norm_r, + tol_r); break; } @@ -233,7 +242,7 @@ LinearSolver::Summary ConjugateGradientsSolver::Solve( } return summary; -}; +} } // namespace internal } // namespace ceres diff --git a/extern/libmv/third_party/ceres/internal/ceres/conjugate_gradients_solver.h b/extern/libmv/third_party/ceres/internal/ceres/conjugate_gradients_solver.h index b8dfa56b526..a1e18334414 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/conjugate_gradients_solver.h +++ b/extern/libmv/third_party/ceres/internal/ceres/conjugate_gradients_solver.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/coordinate_descent_minimizer.cc b/extern/libmv/third_party/ceres/internal/ceres/coordinate_descent_minimizer.cc index 0d8adee7cd8..c6b42cf1516 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/coordinate_descent_minimizer.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/coordinate_descent_minimizer.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -48,11 +48,17 @@ #include "ceres/solver.h" #include "ceres/trust_region_minimizer.h" #include "ceres/trust_region_strategy.h" -#include "ceres/parameter_block_ordering.h" namespace ceres { namespace internal { +using std::map; +using std::max; +using std::min; +using std::set; +using std::string; +using std::vector; + CoordinateDescentMinimizer::~CoordinateDescentMinimizer() { } @@ -244,7 +250,7 @@ bool CoordinateDescentMinimizer::IsOrderingValid( // Verify that each group is an independent set map<int, set<double*> >::const_iterator it = group_to_elements.begin(); - for ( ; it != group_to_elements.end(); ++it) { + for (; it != group_to_elements.end(); ++it) { if (!program.IsParameterBlockSetIndependent(it->second)) { *message = StringPrintf("The user-provided " diff --git a/extern/libmv/third_party/ceres/internal/ceres/coordinate_descent_minimizer.h b/extern/libmv/third_party/ceres/internal/ceres/coordinate_descent_minimizer.h index c1f8ffcd02a..25ea04ce622 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/coordinate_descent_minimizer.h +++ b/extern/libmv/third_party/ceres/internal/ceres/coordinate_descent_minimizer.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -60,7 +60,7 @@ class CoordinateDescentMinimizer : public Minimizer { bool Init(const Program& program, const ProblemImpl::ParameterMap& parameter_map, const ParameterBlockOrdering& ordering, - string* error); + std::string* error); // Minimizer interface. virtual ~CoordinateDescentMinimizer(); @@ -71,7 +71,7 @@ class CoordinateDescentMinimizer : public Minimizer { // Verify that each group in the ordering forms an independent set. static bool IsOrderingValid(const Program& program, const ParameterBlockOrdering& ordering, - string* message); + std::string* message); // Find a recursive decomposition of the Hessian matrix as a set // of independent sets of decreasing size and invert it. This @@ -85,13 +85,13 @@ class CoordinateDescentMinimizer : public Minimizer { double* parameters, Solver::Summary* summary); - vector<ParameterBlock*> parameter_blocks_; - vector<vector<ResidualBlock*> > residual_blocks_; + std::vector<ParameterBlock*> parameter_blocks_; + std::vector<std::vector<ResidualBlock*> > residual_blocks_; // The optimization is performed in rounds. In each round all the // parameter blocks that form one independent set are optimized in // parallel. This array, marks the boundaries of the independent // sets in parameter_blocks_. - vector<int> independent_set_offsets_; + std::vector<int> independent_set_offsets_; Evaluator::Options evaluator_options_; }; diff --git a/extern/libmv/third_party/ceres/internal/ceres/corrector.cc b/extern/libmv/third_party/ceres/internal/ceres/corrector.cc index 581fc6d4fc0..720182868c1 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/corrector.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/corrector.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/corrector.h b/extern/libmv/third_party/ceres/internal/ceres/corrector.h index 2137221784e..315f012ab1d 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/corrector.h +++ b/extern/libmv/third_party/ceres/internal/ceres/corrector.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/covariance.cc b/extern/libmv/third_party/ceres/internal/ceres/covariance.cc index 35146c582b2..690847945a9 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/covariance.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/covariance.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -38,6 +38,9 @@ namespace ceres { +using std::pair; +using std::vector; + Covariance::Covariance(const Covariance::Options& options) { impl_.reset(new internal::CovarianceImpl(options)); } @@ -54,9 +57,20 @@ bool Covariance::Compute( bool Covariance::GetCovarianceBlock(const double* parameter_block1, const double* parameter_block2, double* covariance_block) const { - return impl_->GetCovarianceBlock(parameter_block1, - parameter_block2, - covariance_block); + return impl_->GetCovarianceBlockInTangentOrAmbientSpace(parameter_block1, + parameter_block2, + true, // ambient + covariance_block); +} + +bool Covariance::GetCovarianceBlockInTangentSpace( + const double* parameter_block1, + const double* parameter_block2, + double* covariance_block) const { + return impl_->GetCovarianceBlockInTangentOrAmbientSpace(parameter_block1, + parameter_block2, + false, // tangent + covariance_block); } } // namespace ceres diff --git a/extern/libmv/third_party/ceres/internal/ceres/covariance_impl.cc b/extern/libmv/third_party/ceres/internal/ceres/covariance_impl.cc index cfbfb445343..3e8302bed55 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/covariance_impl.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/covariance_impl.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -38,26 +38,11 @@ #include <cstdlib> #include <utility> #include <vector> -#include "Eigen/SparseCore" -// Suppress unused local variable warning from Eigen Ordering.h #included by -// SparseQR in Eigen 3.2.0. This was fixed in Eigen 3.2.1, but 3.2.0 is still -// widely used (Ubuntu 14.04), and Ceres won't compile otherwise due to -Werror. -#if defined(_MSC_VER) -#pragma warning( push ) -#pragma warning( disable : 4189 ) -#else -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-but-set-variable" -#endif +#include "Eigen/SparseCore" #include "Eigen/SparseQR" -#if defined(_MSC_VER) -#pragma warning( pop ) -#else -#pragma GCC diagnostic pop -#endif - #include "Eigen/SVD" + #include "ceres/compressed_col_sparse_matrix_utils.h" #include "ceres/compressed_row_sparse_matrix.h" #include "ceres/covariance.h" @@ -73,6 +58,12 @@ namespace ceres { namespace internal { +using std::make_pair; +using std::map; +using std::pair; +using std::swap; +using std::vector; + typedef vector<pair<const double*, const double*> > CovarianceBlocks; CovarianceImpl::CovarianceImpl(const Covariance::Options& options) @@ -106,9 +97,11 @@ bool CovarianceImpl::Compute(const CovarianceBlocks& covariance_blocks, return is_valid_; } -bool CovarianceImpl::GetCovarianceBlock(const double* original_parameter_block1, - const double* original_parameter_block2, - double* covariance_block) const { +bool CovarianceImpl::GetCovarianceBlockInTangentOrAmbientSpace( + const double* original_parameter_block1, + const double* original_parameter_block2, + bool lift_covariance_to_ambient_space, + double* covariance_block) const { CHECK(is_computed_) << "Covariance::GetCovarianceBlock called before Covariance::Compute"; CHECK(is_valid_) @@ -137,7 +130,7 @@ bool CovarianceImpl::GetCovarianceBlock(const double* original_parameter_block1, const double* parameter_block2 = original_parameter_block2; const bool transpose = parameter_block1 > parameter_block2; if (transpose) { - std::swap(parameter_block1, parameter_block2); + swap(parameter_block1, parameter_block2); } // Find where in the covariance matrix the block is located. @@ -181,14 +174,17 @@ bool CovarianceImpl::GetCovarianceBlock(const double* original_parameter_block1, block1_size, row_size); - // Fast path when there are no local parameterizations. - if (local_param1 == NULL && local_param2 == NULL) { + // Fast path when there are no local parameterizations or if the + // user does not want it lifted to the ambient space. + if ((local_param1 == NULL && local_param2 == NULL) || + !lift_covariance_to_ambient_space) { if (transpose) { - MatrixRef(covariance_block, block2_size, block1_size) = - cov.block(0, offset, block1_size, block2_size).transpose(); + MatrixRef(covariance_block, block2_local_size, block1_local_size) = + cov.block(0, offset, block1_local_size, + block2_local_size).transpose(); } else { - MatrixRef(covariance_block, block1_size, block2_size) = - cov.block(0, offset, block1_size, block2_size); + MatrixRef(covariance_block, block1_local_size, block2_local_size) = + cov.block(0, offset, block1_local_size, block2_local_size); } return true; } @@ -257,7 +253,8 @@ bool CovarianceImpl::ComputeCovarianceSparsity( problem->GetParameterBlocks(&all_parameter_blocks); const ProblemImpl::ParameterMap& parameter_map = problem->parameter_map(); constant_parameter_blocks_.clear(); - vector<double*>& active_parameter_blocks = evaluate_options_.parameter_blocks; + vector<double*>& active_parameter_blocks = + evaluate_options_.parameter_blocks; active_parameter_blocks.clear(); for (int i = 0; i < all_parameter_blocks.size(); ++i) { double* parameter_block = all_parameter_blocks[i]; @@ -270,7 +267,7 @@ bool CovarianceImpl::ComputeCovarianceSparsity( } } - sort(active_parameter_blocks.begin(), active_parameter_blocks.end()); + std::sort(active_parameter_blocks.begin(), active_parameter_blocks.end()); // Compute the number of rows. Map each parameter block to the // first row corresponding to it in the covariance matrix using the @@ -609,8 +606,8 @@ bool CovarianceImpl::ComputeCovarianceValuesUsingDenseSVD() { sqrt(options_.min_reciprocal_condition_number); const bool automatic_truncation = (options_.null_space_rank < 0); - const int max_rank = min(num_singular_values, - num_singular_values - options_.null_space_rank); + const int max_rank = std::min(num_singular_values, + num_singular_values - options_.null_space_rank); // Compute the squared inverse of the singular values. Truncate the // computation based on min_singular_value_ratio and @@ -687,7 +684,7 @@ bool CovarianceImpl::ComputeCovarianceValuesUsingEigenSparseQR() { qr_solver(sparse_jacobian); event_logger.AddEvent("QRDecomposition"); - if(qr_solver.info() != Eigen::Success) { + if (qr_solver.info() != Eigen::Success) { LOG(ERROR) << "Eigen::SparseQR decomposition failed."; return false; } diff --git a/extern/libmv/third_party/ceres/internal/ceres/covariance_impl.h b/extern/libmv/third_party/ceres/internal/ceres/covariance_impl.h index 135f4a1d624..eb0cd040666 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/covariance_impl.h +++ b/extern/libmv/third_party/ceres/internal/ceres/covariance_impl.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -41,7 +41,6 @@ #include "ceres/suitesparse.h" namespace ceres { - namespace internal { class CompressedRowSparseMatrix; @@ -52,15 +51,19 @@ class CovarianceImpl { ~CovarianceImpl(); bool Compute( - const vector<pair<const double*, const double*> >& covariance_blocks, + const std::vector<std::pair<const double*, + const double*> >& covariance_blocks, ProblemImpl* problem); - bool GetCovarianceBlock(const double* parameter_block1, - const double* parameter_block2, - double* covariance_block) const; + bool GetCovarianceBlockInTangentOrAmbientSpace( + const double* parameter_block1, + const double* parameter_block2, + bool lift_covariance_to_ambient_space, + double* covariance_block) const; bool ComputeCovarianceSparsity( - const vector<pair<const double*, const double*> >& covariance_blocks, + const std::vector<std::pair<const double*, + const double*> >& covariance_blocks, ProblemImpl* problem); bool ComputeCovarianceValues(); @@ -78,8 +81,8 @@ class CovarianceImpl { Problem::EvaluateOptions evaluate_options_; bool is_computed_; bool is_valid_; - map<const double*, int> parameter_block_to_row_index_; - set<const double*> constant_parameter_blocks_; + std::map<const double*, int> parameter_block_to_row_index_; + std::set<const double*> constant_parameter_blocks_; scoped_ptr<CompressedRowSparseMatrix> covariance_matrix_; }; diff --git a/extern/libmv/third_party/ceres/internal/ceres/cxsparse.cc b/extern/libmv/third_party/ceres/internal/ceres/cxsparse.cc index 87503d06c99..60b58089bb5 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/cxsparse.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/cxsparse.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -38,13 +38,14 @@ #include <vector> #include "ceres/compressed_col_sparse_matrix_utils.h" #include "ceres/compressed_row_sparse_matrix.h" -#include "ceres/internal/port.h" #include "ceres/triplet_sparse_matrix.h" #include "glog/logging.h" namespace ceres { namespace internal { +using std::vector; + CXSparse::CXSparse() : scratch_(NULL), scratch_size_(0) { } @@ -128,7 +129,7 @@ cs_dis* CXSparse::BlockAnalyzeCholesky(cs_di* A, int* ordering = cs_amd(1, &block_matrix); vector<int> block_ordering(num_row_blocks, -1); - copy(ordering, ordering + num_row_blocks, &block_ordering[0]); + std::copy(ordering, ordering + num_row_blocks, &block_ordering[0]); cs_free(ordering); vector<int> scalar_ordering; @@ -191,7 +192,7 @@ cs_di* CXSparse::CreateSparseMatrix(TripletSparseMatrix* tsm) { void CXSparse::ApproximateMinimumDegreeOrdering(cs_di* A, int* ordering) { int* cs_ordering = cs_amd(1, A); - copy(cs_ordering, cs_ordering + A->m, ordering); + std::copy(cs_ordering, cs_ordering + A->m, ordering); cs_free(cs_ordering); } diff --git a/extern/libmv/third_party/ceres/internal/ceres/cxsparse.h b/extern/libmv/third_party/ceres/internal/ceres/cxsparse.h index 5868401b961..26dd1927a78 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/cxsparse.h +++ b/extern/libmv/third_party/ceres/internal/ceres/cxsparse.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -107,8 +107,8 @@ class CXSparse { // The returned matrix should be deallocated with Free when not used // anymore. cs_dis* BlockAnalyzeCholesky(cs_di* A, - const vector<int>& row_blocks, - const vector<int>& col_blocks); + const std::vector<int>& row_blocks, + const std::vector<int>& col_blocks); // Compute an fill-reducing approximate minimum degree ordering of // the matrix A. ordering should be non-NULL and should point to @@ -133,8 +133,7 @@ typedef void cs_dis; class CXSparse { public: - void Free(void*) {}; - + void Free(void* arg) {} }; #endif // CERES_NO_CXSPARSE diff --git a/extern/libmv/third_party/ceres/internal/ceres/dense_jacobian_writer.h b/extern/libmv/third_party/ceres/internal/ceres/dense_jacobian_writer.h index be743a8591c..1b04f383f09 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/dense_jacobian_writer.h +++ b/extern/libmv/third_party/ceres/internal/ceres/dense_jacobian_writer.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -70,10 +70,7 @@ class DenseJacobianWriter { int residual_offset, double **jacobians, SparseMatrix* jacobian) { - DenseSparseMatrix* dense_jacobian; - if (jacobian != NULL) { - dense_jacobian = down_cast<DenseSparseMatrix*>(jacobian); - } + DenseSparseMatrix* dense_jacobian = down_cast<DenseSparseMatrix*>(jacobian); const ResidualBlock* residual_block = program_->residual_blocks()[residual_id]; int num_parameter_blocks = residual_block->NumParameterBlocks(); 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 f44d6da824c..b13cf3fc9f6 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 @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/dense_normal_cholesky_solver.h b/extern/libmv/third_party/ceres/internal/ceres/dense_normal_cholesky_solver.h index e35053f5234..11287ebf675 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/dense_normal_cholesky_solver.h +++ b/extern/libmv/third_party/ceres/internal/ceres/dense_normal_cholesky_solver.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/dense_qr_solver.cc b/extern/libmv/third_party/ceres/internal/ceres/dense_qr_solver.cc index 4388357bd2d..e85fdfc0c68 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/dense_qr_solver.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/dense_qr_solver.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/dense_qr_solver.h b/extern/libmv/third_party/ceres/internal/ceres/dense_qr_solver.h index e745c63cb44..1a6e0898c56 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/dense_qr_solver.h +++ b/extern/libmv/third_party/ceres/internal/ceres/dense_qr_solver.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: 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 d67474fed32..19db867d4aa 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 @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: 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 981e2d14562..b011bfddee7 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 @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/detect_structure.cc b/extern/libmv/third_party/ceres/internal/ceres/detect_structure.cc index ea5bf2e9690..959a0ee3c84 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/detect_structure.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/detect_structure.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -54,8 +54,8 @@ void DetectStructure(const CompressedRowBlockStructure& bs, if (row.cells.front().block_id >= num_eliminate_blocks) { break; } - const int e_block_id = row.cells.front().block_id; + // Detect fixed or dynamic row block size. if (*row_block_size == 0) { *row_block_size = row.block.size; } else if (*row_block_size != Eigen::Dynamic && @@ -66,7 +66,8 @@ void DetectStructure(const CompressedRowBlockStructure& bs, *row_block_size = Eigen::Dynamic; } - + // Detect fixed or dynamic e-block size. + const int e_block_id = row.cells.front().block_id; if (*e_block_size == 0) { *e_block_size = bs.cols[e_block_id].size; } else if (*e_block_size != Eigen::Dynamic && @@ -77,19 +78,24 @@ void DetectStructure(const CompressedRowBlockStructure& bs, *e_block_size = Eigen::Dynamic; } - if (*f_block_size == 0) { - if (row.cells.size() > 1) { + // Detect fixed or dynamic f-block size. We are only interested in + // rows with e-blocks, and the e-block is always the first block, + // so only rows of size greater than 1 are of interest. + if (row.cells.size() > 1) { + if (*f_block_size == 0) { const int f_block_id = row.cells[1].block_id; *f_block_size = bs.cols[f_block_id].size; } - } else if (*f_block_size != Eigen::Dynamic) { - for (int c = 1; c < row.cells.size(); ++c) { - if (*f_block_size != bs.cols[row.cells[c].block_id].size) { + + for (int c = 1; + (c < row.cells.size()) && (*f_block_size != Eigen::Dynamic); + ++c) { + const int f_block_id = row.cells[c].block_id; + if (*f_block_size != bs.cols[f_block_id].size) { VLOG(2) << "Dynamic f block size because the block size " << "changed from " << *f_block_size << " to " - << bs.cols[row.cells[c].block_id].size; + << bs.cols[f_block_id].size; *f_block_size = Eigen::Dynamic; - break; } } } diff --git a/extern/libmv/third_party/ceres/internal/ceres/detect_structure.h b/extern/libmv/third_party/ceres/internal/ceres/detect_structure.h index 5f8e1b4ff46..602581c846e 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/detect_structure.h +++ b/extern/libmv/third_party/ceres/internal/ceres/detect_structure.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -51,6 +51,10 @@ namespace internal { // For more details about e_blocks and f_blocks, see // schur_eliminator.h. This information is used to initialized an // appropriate template specialization of SchurEliminator. +// +// Note: The structure of rows without any e-blocks has no effect on +// the values returned by this function. It is entirely possible that +// the f_block_size and row_blocks_size is not constant in such rows. void DetectStructure(const CompressedRowBlockStructure& bs, const int num_eliminate_blocks, int* row_block_size, diff --git a/extern/libmv/third_party/ceres/internal/ceres/dogleg_strategy.cc b/extern/libmv/third_party/ceres/internal/ceres/dogleg_strategy.cc index f29376db793..839e1816338 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/dogleg_strategy.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/dogleg_strategy.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -120,7 +120,8 @@ TrustRegionStrategy::Summary DoglegStrategy::ComputeStep( // jacobian->SquaredColumnNorm(diagonal_.data()); for (int i = 0; i < n; ++i) { - diagonal_[i] = min(max(diagonal_[i], min_diagonal_), max_diagonal_); + diagonal_[i] = std::min(std::max(diagonal_[i], min_diagonal_), + max_diagonal_); } diagonal_ = diagonal_.array().sqrt(); @@ -618,13 +619,13 @@ void DoglegStrategy::StepAccepted(double step_quality) { } if (step_quality > increase_threshold_) { - radius_ = max(radius_, 3.0 * dogleg_step_norm_); + radius_ = std::max(radius_, 3.0 * dogleg_step_norm_); } // Reduce the regularization multiplier, in the hope that whatever // was causing the rank deficiency has gone away and we can return // to doing a pure Gauss-Newton solve. - mu_ = max(min_mu_, 2.0 * mu_ / mu_increase_factor_); + mu_ = std::max(min_mu_, 2.0 * mu_ / mu_increase_factor_); reuse_ = false; } diff --git a/extern/libmv/third_party/ceres/internal/ceres/dogleg_strategy.h b/extern/libmv/third_party/ceres/internal/ceres/dogleg_strategy.h index 71c785cc3f7..046b9d824c9 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/dogleg_strategy.h +++ b/extern/libmv/third_party/ceres/internal/ceres/dogleg_strategy.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/dynamic_compressed_row_finalizer.h b/extern/libmv/third_party/ceres/internal/ceres/dynamic_compressed_row_finalizer.h index 5e6b0d84510..a25a3083120 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/dynamic_compressed_row_finalizer.h +++ b/extern/libmv/third_party/ceres/internal/ceres/dynamic_compressed_row_finalizer.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -48,4 +48,4 @@ struct DynamicCompressedRowJacobianFinalizer { } // namespace internal } // namespace ceres -#endif // CERES_INTERNAL_DYNAMIC_COMPRESED_ROW_FINALISER_H_ +#endif // CERES_INTERNAL_DYNAMIC_COMPRESED_ROW_FINALISER_H_ diff --git a/extern/libmv/third_party/ceres/internal/ceres/dynamic_compressed_row_jacobian_writer.cc b/extern/libmv/third_party/ceres/internal/ceres/dynamic_compressed_row_jacobian_writer.cc index b46cb797ff2..fd5d89e350a 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/dynamic_compressed_row_jacobian_writer.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/dynamic_compressed_row_jacobian_writer.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -39,6 +39,9 @@ namespace ceres { namespace internal { +using std::pair; +using std::vector; + ScratchEvaluatePreparer* DynamicCompressedRowJacobianWriter::CreateEvaluatePreparers(int num_threads) { return ScratchEvaluatePreparer::Create(*program_, num_threads); diff --git a/extern/libmv/third_party/ceres/internal/ceres/dynamic_compressed_row_jacobian_writer.h b/extern/libmv/third_party/ceres/internal/ceres/dynamic_compressed_row_jacobian_writer.h index df9581b145d..6e5ac38f07e 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/dynamic_compressed_row_jacobian_writer.h +++ b/extern/libmv/third_party/ceres/internal/ceres/dynamic_compressed_row_jacobian_writer.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -80,4 +80,4 @@ class DynamicCompressedRowJacobianWriter { } // namespace internal } // namespace ceres -#endif // CERES_INTERNAL_DYNAMIC_COMPRESSED_ROW_JACOBIAN_WRITER_H_ +#endif // CERES_INTERNAL_DYNAMIC_COMPRESSED_ROW_JACOBIAN_WRITER_H_ diff --git a/extern/libmv/third_party/ceres/internal/ceres/dynamic_compressed_row_sparse_matrix.cc b/extern/libmv/third_party/ceres/internal/ceres/dynamic_compressed_row_sparse_matrix.cc index f285d52a342..f020768ce10 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/dynamic_compressed_row_sparse_matrix.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/dynamic_compressed_row_sparse_matrix.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/dynamic_compressed_row_sparse_matrix.h b/extern/libmv/third_party/ceres/internal/ceres/dynamic_compressed_row_sparse_matrix.h index 7a89a708658..cab860bddbd 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/dynamic_compressed_row_sparse_matrix.h +++ b/extern/libmv/third_party/ceres/internal/ceres/dynamic_compressed_row_sparse_matrix.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -41,6 +41,8 @@ #ifndef CERES_INTERNAL_DYNAMIC_COMPRESSED_ROW_SPARSE_MATRIX_H_ #define CERES_INTERNAL_DYNAMIC_COMPRESSED_ROW_SPARSE_MATRIX_H_ +#include <vector> + #include "ceres/compressed_row_sparse_matrix.h" namespace ceres { @@ -89,11 +91,11 @@ class DynamicCompressedRowSparseMatrix : public CompressedRowSparseMatrix { void Finalize(int num_additional_elements); private: - vector<vector<int> > dynamic_cols_; - vector<vector<double> > dynamic_values_; + std::vector<std::vector<int> > dynamic_cols_; + std::vector<std::vector<double> > dynamic_values_; }; } // namespace internal } // namespace ceres -#endif // CERES_INTERNAL_DYNAMIC_COMPRESSED_ROW_SPARSE_MATRIX_H_ +#endif // CERES_INTERNAL_DYNAMIC_COMPRESSED_ROW_SPARSE_MATRIX_H_ diff --git a/extern/libmv/third_party/ceres/internal/ceres/evaluator.cc b/extern/libmv/third_party/ceres/internal/ceres/evaluator.cc index c94c62c29b5..baba9afa11b 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/evaluator.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/evaluator.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -50,7 +50,7 @@ Evaluator::~Evaluator() {} Evaluator* Evaluator::Create(const Evaluator::Options& options, Program* program, - string* error) { + std::string* error) { switch (options.linear_solver_type) { case DENSE_QR: case DENSE_NORMAL_CHOLESKY: diff --git a/extern/libmv/third_party/ceres/internal/ceres/evaluator.h b/extern/libmv/third_party/ceres/internal/ceres/evaluator.h index 8fc60b87869..fea307919d0 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/evaluator.h +++ b/extern/libmv/third_party/ceres/internal/ceres/evaluator.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -72,7 +72,7 @@ class Evaluator { static Evaluator* Create(const Options& options, Program* program, - string* error); + std::string* error); // This is used for computing the cost, residual and Jacobian for // returning to the user. For actually solving the optimization @@ -95,8 +95,8 @@ class Evaluator { static bool Evaluate(Program* program, int num_threads, double* cost, - vector<double>* residuals, - vector<double>* gradient, + std::vector<double>* residuals, + std::vector<double>* gradient, CRSMatrix* jacobian); // Build and return a sparse matrix for storing and working with the Jacobian @@ -190,12 +190,12 @@ class Evaluator { // that the base class implementation does not have to worry about // life time issues. Further, these calls are not expected to be // frequent or performance sensitive. - virtual map<string, int> CallStatistics() const { - return map<string, int>(); + virtual std::map<std::string, int> CallStatistics() const { + return std::map<std::string, int>(); } - virtual map<string, double> TimeStatistics() const { - return map<string, double>(); + virtual std::map<std::string, double> TimeStatistics() const { + return std::map<std::string, double>(); } }; diff --git a/extern/libmv/third_party/ceres/internal/ceres/execution_summary.h b/extern/libmv/third_party/ceres/internal/ceres/execution_summary.h index 29bdc69ecd7..aa9929d8974 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/execution_summary.h +++ b/extern/libmv/third_party/ceres/internal/ceres/execution_summary.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -46,30 +46,30 @@ namespace internal { // can be used for reporting times associated with various activities. class ExecutionSummary { public: - void IncrementTimeBy(const string& name, const double value) { + void IncrementTimeBy(const std::string& name, const double value) { CeresMutexLock l(×_mutex_); times_[name] += value; } - void IncrementCall(const string& name) { + void IncrementCall(const std::string& name) { CeresMutexLock l(&calls_mutex_); calls_[name] += 1; } - const map<string, double>& times() const { return times_; } - const map<string, int>& calls() const { return calls_; } + const std::map<std::string, double>& times() const { return times_; } + const std::map<std::string, int>& calls() const { return calls_; } private: Mutex times_mutex_; - map<string, double> times_; + std::map<std::string, double> times_; Mutex calls_mutex_; - map<string, int> calls_; + std::map<std::string, int> calls_; }; class ScopedExecutionTimer { public: - ScopedExecutionTimer(const string& name, ExecutionSummary* summary) + ScopedExecutionTimer(const std::string& name, ExecutionSummary* summary) : start_time_(WallTimeInSeconds()), name_(name), summary_(summary) {} @@ -80,7 +80,7 @@ class ScopedExecutionTimer { private: const double start_time_; - const string name_; + const std::string name_; ExecutionSummary* summary_; }; diff --git a/extern/libmv/third_party/ceres/internal/ceres/file.cc b/extern/libmv/third_party/ceres/internal/ceres/file.cc index 5226c85e6ee..c95a44d2c38 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/file.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/file.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/file.h b/extern/libmv/third_party/ceres/internal/ceres/file.h index 4741d650646..219b459b919 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/file.h +++ b/extern/libmv/third_party/ceres/internal/ceres/file.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -39,12 +39,13 @@ namespace ceres { namespace internal { -void WriteStringToFileOrDie(const string &data, const string &filename); -void ReadFileToStringOrDie(const string &filename, string *data); +void WriteStringToFileOrDie(const std::string &data, + const std::string &filename); +void ReadFileToStringOrDie(const std::string &filename, std::string *data); // Join two path components, adding a slash if necessary. If basename is an // absolute path then JoinPath ignores dirname and simply returns basename. -string JoinPath(const string& dirname, const string& basename); +std::string JoinPath(const std::string& dirname, const std::string& basename); } // namespace internal } // namespace ceres 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 2ec3c5b42ca..e89e7a48c98 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,6 +1,6 @@ # 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/ +# Copyright 2015 Google Inc. All rights reserved. +# http://ceres-solver.org/ # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: @@ -55,6 +55,7 @@ SPECIALIZATIONS = [(2, 2, 2), (2, 2, "Eigen::Dynamic"), (2, 3, 3), (2, 3, 4), + (2, 3, 6), (2, 3, 9), (2, 3, "Eigen::Dynamic"), (2, 4, 3), @@ -69,8 +70,8 @@ SPECIALIZATIONS = [(2, 2, 2), (4, 4, "Eigen::Dynamic"), ("Eigen::Dynamic", "Eigen::Dynamic", "Eigen::Dynamic")] HEADER = """// 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/generate_partitioned_matrix_view_specializations.py b/extern/libmv/third_party/ceres/internal/ceres/generate_partitioned_matrix_view_specializations.py index c9bdf238ce0..c4ac3cf2332 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generate_partitioned_matrix_view_specializations.py +++ b/extern/libmv/third_party/ceres/internal/ceres/generate_partitioned_matrix_view_specializations.py @@ -1,6 +1,6 @@ # Ceres Solver - A fast non-linear least squares minimizer -# Copyright 2013 Google Inc. All rights reserved. -# http://code.google.com/p/ceres-solver/ +# Copyright 2015 Google Inc. All rights reserved. +# http://ceres-solver.org/ # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: @@ -53,6 +53,7 @@ SPECIALIZATIONS = [(2, 2, 2), (2, 2, "Eigen::Dynamic"), (2, 3, 3), (2, 3, 4), + (2, 3, 6), (2, 3, 9), (2, 3, "Eigen::Dynamic"), (2, 4, 3), @@ -67,8 +68,8 @@ SPECIALIZATIONS = [(2, 2, 2), (4, 4, "Eigen::Dynamic"), ("Eigen::Dynamic", "Eigen::Dynamic", "Eigen::Dynamic")] HEADER = """// Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_2_2.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_2_2.cc index a7d802ad8c0..500115b9897 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_2_2.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_2_2.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_2_3.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_2_3.cc index 89e6f7750b1..1384cb619e3 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_2_3.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_2_3.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_2_4.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_2_4.cc index 3a3e8b67243..030035ec97b 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_2_4.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_2_4.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_2_d.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_2_d.cc index 661f135cd10..c9501b50170 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_2_d.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_2_d.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_3_3.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_3_3.cc index e79e001d6c6..c2639bff69e 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_3_3.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_3_3.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_3_4.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_3_4.cc index 2f1ae68d66a..693e43959c1 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_3_4.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_3_4.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_3_6.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_3_6.cc new file mode 100644 index 00000000000..7b9368ffefd --- /dev/null +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_3_6.cc @@ -0,0 +1,59 @@ +// Ceres Solver - A fast non-linear least squares minimizer +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ +// +// 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 PartitionedMatrixView. +// +// ======================================== +// THIS FILE IS AUTOGENERATED. DO NOT EDIT. +// THIS FILE IS AUTOGENERATED. DO NOT EDIT. +// THIS FILE IS AUTOGENERATED. DO NOT EDIT. +// THIS FILE IS AUTOGENERATED. DO NOT EDIT. +//========================================= +// +// This file is generated using generate_partitioned_matrix_view_specializations.py. +// Editing it manually is not recommended. + +// This include must come before any #ifndef check on Ceres compile options. +#include "ceres/internal/port.h" + +#ifndef CERES_RESTRICT_SCHUR_SPECIALIZATION + +#include "ceres/partitioned_matrix_view_impl.h" +#include "ceres/internal/eigen.h" + +namespace ceres { +namespace internal { + +template class PartitionedMatrixView<2, 3, 6>; + +} // namespace internal +} // namespace ceres + +#endif // CERES_RESTRICT_SCHUR_SPECIALIZATION diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_3_9.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_3_9.cc index ab405503925..e72c5f6937a 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_3_9.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_3_9.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_3_d.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_3_d.cc index 89ecff73319..c1f410eb64c 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_3_d.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_3_d.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_4_3.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_4_3.cc index 182707d7df7..7292c333d5d 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_4_3.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_4_3.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_4_4.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_4_4.cc index a2cf8f4a9dd..891d65a8646 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_4_4.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_4_4.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_4_8.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_4_8.cc index a2637691cb0..395f6bd4c13 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_4_8.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_4_8.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_4_9.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_4_9.cc index d853860326e..88952b10e34 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_4_9.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_4_9.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_4_d.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_4_d.cc index 7d622fcabbb..7733e1993eb 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_4_d.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_4_d.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_d_d.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_d_d.cc index 31981cae461..117a0cdb8c1 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_d_d.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_2_d_d.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_4_4_2.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_4_4_2.cc index d51ab5ff715..a620bb70dba 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_4_4_2.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_4_4_2.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_4_4_3.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_4_4_3.cc index 4b17fbdecde..2978630832c 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_4_4_3.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_4_4_3.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_4_4_4.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_4_4_4.cc index 7b5fe0f35a7..bcd03b02e3a 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_4_4_4.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_4_4_4.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_4_4_d.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_4_4_d.cc index c31fed395a8..6b541ecf0d9 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_4_4_d.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_4_4_d.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_d_d_d.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_d_d_d.cc index a3308ede789..85111e722c4 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_d_d_d.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/partitioned_matrix_view_d_d_d.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: 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 db2a4dc6b44..ac07a3f229e 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,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: 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 f53c12a4373..0ec09553f9e 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,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: 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 9e29383b00f..74a42cc4a16 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,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: 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 541def6fc37..5ce757fda5d 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,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: 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 e450263825b..2e7ae28b4ea 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,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: 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 0618c684af8..443207070cf 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,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_3_6.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_3_6.cc new file mode 100644 index 00000000000..ac2f358b383 --- /dev/null +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_3_6.cc @@ -0,0 +1,59 @@ +// Ceres Solver - A fast non-linear least squares minimizer +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ +// +// 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. +// +// ======================================== +// THIS FILE IS AUTOGENERATED. DO NOT EDIT. +// THIS FILE IS AUTOGENERATED. DO NOT EDIT. +// THIS FILE IS AUTOGENERATED. DO NOT EDIT. +// THIS FILE IS AUTOGENERATED. DO NOT EDIT. +//========================================= +// +// This file is generated using generate_eliminator_specialization.py. +// Editing it manually is not recommended. + +// This include must come before any #ifndef check on Ceres compile options. +#include "ceres/internal/port.h" + +#ifndef CERES_RESTRICT_SCHUR_SPECIALIZATION + +#include "ceres/schur_eliminator_impl.h" +#include "ceres/internal/eigen.h" + +namespace ceres { +namespace internal { + +template class SchurEliminator<2, 3, 6>; + +} // namespace internal +} // namespace ceres + +#endif // CERES_RESTRICT_SCHUR_SPECIALIZATION 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 c1ca665d45f..930ab440fa5 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,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: 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 1b6092c75a9..486c53d36f4 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,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: 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 edce8ef717b..6f247a7b832 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,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: 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 a6f3c52d7f2..c44cd045263 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,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_4_8.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_4_8.cc index bf2f0abb1cf..c9a0d5fc729 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_4_8.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_4_8.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_4_9.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_4_9.cc index a63d0bbe0a6..b0455b0bca0 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_4_9.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_4_9.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: 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 b3a7fffb33e..3234380f23c 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,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_d_d.cc b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_d_d.cc index f4d28cd1642..311f8556932 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_d_d.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/generated/schur_eliminator_2_d_d.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: 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 d1eadc1fc83..bc40bd55296 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,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: 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 c340dbfc754..cca88c802b0 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,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: 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 b7d58ad026f..33c94a907b9 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,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: 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 47e00592b4e..1a1866f93a8 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,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: 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 d54a03cadd4..6b18ef8c863 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,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/gradient_checking_cost_function.cc b/extern/libmv/third_party/ceres/internal/ceres/gradient_checking_cost_function.cc index 3272848a499..580fd260e15 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/gradient_checking_cost_function.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/gradient_checking_cost_function.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -51,6 +51,12 @@ namespace ceres { namespace internal { + +using std::abs; +using std::max; +using std::string; +using std::vector; + namespace { // True if x and y have an absolute relative difference less than @@ -67,20 +73,20 @@ bool IsClose(double x, double y, double relative_precision, if (!relative_error) { relative_error = &local_relative_error; } - *absolute_error = fabs(x - y); - *relative_error = *absolute_error / max(fabs(x), fabs(y)); + *absolute_error = abs(x - y); + *relative_error = *absolute_error / max(abs(x), abs(y)); if (x == 0 || y == 0) { // If x or y is exactly zero, then relative difference doesn't have any // meaning. Take the absolute difference instead. *relative_error = *absolute_error; } - return fabs(*relative_error) < fabs(relative_precision); + return abs(*relative_error) < abs(relative_precision); } class GradientCheckingCostFunction : public CostFunction { public: GradientCheckingCostFunction(const CostFunction* function, - double relative_step_size, + const NumericDiffOptions& options, double relative_precision, const string& extra_info) : function_(function), @@ -91,7 +97,7 @@ class GradientCheckingCostFunction : public CostFunction { new DynamicNumericDiffCostFunction<CostFunction, CENTRAL>( function, DO_NOT_TAKE_OWNERSHIP, - relative_step_size); + options); const vector<int32>& parameter_block_sizes = function->parameter_block_sizes(); @@ -181,8 +187,7 @@ class GradientCheckingCostFunction : public CostFunction { relative_precision_, &relative_error, &absolute_error); - worst_relative_error = std::max(worst_relative_error, - relative_error); + worst_relative_error = max(worst_relative_error, relative_error); StringAppendF(&m, "%6d %4d %4d %17g %17g %17g %17g %17g %17g", k, i, j, @@ -230,8 +235,11 @@ CostFunction *CreateGradientCheckingCostFunction( double relative_step_size, double relative_precision, const string& extra_info) { + NumericDiffOptions numeric_diff_options; + numeric_diff_options.relative_step_size = relative_step_size; + return new GradientCheckingCostFunction(cost_function, - relative_step_size, + numeric_diff_options, relative_precision, extra_info); } diff --git a/extern/libmv/third_party/ceres/internal/ceres/gradient_checking_cost_function.h b/extern/libmv/third_party/ceres/internal/ceres/gradient_checking_cost_function.h index d49c8e6c244..cf92cb72bc5 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/gradient_checking_cost_function.h +++ b/extern/libmv/third_party/ceres/internal/ceres/gradient_checking_cost_function.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -61,7 +61,7 @@ CostFunction* CreateGradientCheckingCostFunction( const CostFunction* cost_function, double relative_step_size, double relative_precision, - const string& extra_info); + const std::string& extra_info); // Create a new ProblemImpl object from the input problem_impl, where // each CostFunctions in problem_impl are wrapped inside a diff --git a/extern/libmv/third_party/ceres/internal/ceres/gradient_problem.cc b/extern/libmv/third_party/ceres/internal/ceres/gradient_problem.cc index 8f9a842bd89..4ebd3e60610 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/gradient_problem.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/gradient_problem.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/gradient_problem_evaluator.h b/extern/libmv/third_party/ceres/internal/ceres/gradient_problem_evaluator.h index 20053de2af6..2c562544768 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/gradient_problem_evaluator.h +++ b/extern/libmv/third_party/ceres/internal/ceres/gradient_problem_evaluator.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -79,11 +79,11 @@ class GradientProblemEvaluator : public Evaluator { virtual int NumResiduals() const { return 1; } - virtual map<string, int> CallStatistics() const { + virtual std::map<std::string, int> CallStatistics() const { return execution_summary_.calls(); } - virtual map<string, double> TimeStatistics() const { + virtual std::map<std::string, double> TimeStatistics() const { return execution_summary_.times(); } diff --git a/extern/libmv/third_party/ceres/internal/ceres/gradient_problem_solver.cc b/extern/libmv/third_party/ceres/internal/ceres/gradient_problem_solver.cc index 4024f4cc4e6..9a549c23dac 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/gradient_problem_solver.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/gradient_problem_solver.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -46,6 +46,7 @@ namespace ceres { using internal::StringPrintf; using internal::StringAppendF; +using std::string; namespace { @@ -138,6 +139,7 @@ void GradientProblemSolver::Solve(const GradientProblemSolver::Options& options, solver_summary.fixed_cost = 0.0; solver_summary.preprocessor_time_in_seconds = 0.0; solver_summary.postprocessor_time_in_seconds = 0.0; + solver_summary.line_search_polynomial_minimization_time_in_seconds = 0.0; minimizer->Minimize(minimizer_options, solution.data(), &solver_summary); @@ -146,13 +148,15 @@ void GradientProblemSolver::Solve(const GradientProblemSolver::Options& options, summary->initial_cost = solver_summary.initial_cost; summary->final_cost = solver_summary.final_cost; summary->iterations = solver_summary.iterations; + summary->line_search_polynomial_minimization_time_in_seconds = + solver_summary.line_search_polynomial_minimization_time_in_seconds; if (summary->IsSolutionUsable()) { parameters = solution; SetSummaryFinalCost(summary); } - const map<string, double>& evaluator_time_statistics = + const std::map<string, double>& evaluator_time_statistics = minimizer_options.evaluator->TimeStatistics(); summary->cost_evaluation_time_in_seconds = FindWithDefault(evaluator_time_statistics, "Evaluator::Residual", 0.0); @@ -172,6 +176,7 @@ GradientProblemSolver::Summary::Summary() total_time_in_seconds(-1.0), cost_evaluation_time_in_seconds(-1.0), gradient_evaluation_time_in_seconds(-1.0), + line_search_polynomial_minimization_time_in_seconds(-1.0), num_parameters(-1), num_local_parameters(-1), line_search_direction_type(LBFGS), @@ -195,7 +200,7 @@ string GradientProblemSolver::Summary::BriefReport() const { initial_cost, final_cost, TerminationTypeToString(termination_type)); -}; +} string GradientProblemSolver::Summary::FullReport() const { using internal::VersionString; @@ -246,18 +251,20 @@ string GradientProblemSolver::Summary::FullReport() const { StringAppendF(&report, "\nTime (in seconds):\n"); - StringAppendF(&report, "\n Cost evaluation %23.3f\n", + StringAppendF(&report, "\n Cost evaluation %23.4f\n", cost_evaluation_time_in_seconds); - StringAppendF(&report, " Gradient evaluation %23.3f\n", + StringAppendF(&report, " Gradient evaluation %23.4f\n", gradient_evaluation_time_in_seconds); + StringAppendF(&report, " Polynomial minimization %17.4f\n", + line_search_polynomial_minimization_time_in_seconds); - StringAppendF(&report, "Total %25.3f\n\n", + StringAppendF(&report, "Total %25.4f\n\n", total_time_in_seconds); StringAppendF(&report, "Termination: %25s (%s)\n", TerminationTypeToString(termination_type), message.c_str()); return report; -}; +} void Solve(const GradientProblemSolver::Options& options, const GradientProblem& problem, diff --git a/extern/libmv/third_party/ceres/internal/ceres/graph.h b/extern/libmv/third_party/ceres/internal/ceres/graph.h index f639d15323d..b96b67265cb 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/graph.h +++ b/extern/libmv/third_party/ceres/internal/ceres/graph.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -139,9 +139,9 @@ class WeightedGraph { for (typename HashSet<Vertex>::const_iterator it = sinks.begin(); it != sinks.end(); ++it) { if (vertex < *it) { - edge_weights_.erase(make_pair(vertex, *it)); + edge_weights_.erase(std::make_pair(vertex, *it)); } else { - edge_weights_.erase(make_pair(*it, vertex)); + edge_weights_.erase(std::make_pair(*it, vertex)); } edges_[*it].erase(vertex); } @@ -165,9 +165,9 @@ class WeightedGraph { } if (vertex1 < vertex2) { - edge_weights_[make_pair(vertex1, vertex2)] = weight; + edge_weights_[std::make_pair(vertex1, vertex2)] = weight; } else { - edge_weights_[make_pair(vertex2, vertex1)] = weight; + edge_weights_[std::make_pair(vertex2, vertex1)] = weight; } } @@ -188,9 +188,11 @@ class WeightedGraph { // the edge weight is zero. double EdgeWeight(const Vertex& vertex1, const Vertex& vertex2) const { if (vertex1 < vertex2) { - return FindWithDefault(edge_weights_, make_pair(vertex1, vertex2), 0.0); + return FindWithDefault(edge_weights_, + std::make_pair(vertex1, vertex2), 0.0); } else { - return FindWithDefault(edge_weights_, make_pair(vertex2, vertex1), 0.0); + return FindWithDefault(edge_weights_, + std::make_pair(vertex2, vertex1), 0.0); } } @@ -206,13 +208,13 @@ class WeightedGraph { static double InvalidWeight() { return std::numeric_limits<double>::quiet_NaN(); - }; + } private: HashSet<Vertex> vertices_; HashMap<Vertex, double> vertex_weights_; HashMap<Vertex, HashSet<Vertex> > edges_; - HashMap<pair<Vertex, Vertex>, double> edge_weights_; + HashMap<std::pair<Vertex, Vertex>, double> edge_weights_; CERES_DISALLOW_COPY_AND_ASSIGN(WeightedGraph); }; diff --git a/extern/libmv/third_party/ceres/internal/ceres/graph_algorithms.h b/extern/libmv/third_party/ceres/internal/ceres/graph_algorithms.h index fb75e2f45f2..d1d3f52cd22 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/graph_algorithms.h +++ b/extern/libmv/third_party/ceres/internal/ceres/graph_algorithms.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -95,7 +95,7 @@ class VertexDegreeLessThan { // cardinality of S. template <typename Vertex> int IndependentSetOrdering(const Graph<Vertex>& graph, - vector<Vertex>* ordering) { + std::vector<Vertex>* ordering) { const HashSet<Vertex>& vertices = graph.vertices(); const int num_vertices = vertices.size(); @@ -110,7 +110,7 @@ int IndependentSetOrdering(const Graph<Vertex>& graph, // Mark all vertices white. HashMap<Vertex, char> vertex_color; - vector<Vertex> vertex_queue; + std::vector<Vertex> vertex_queue; for (typename HashSet<Vertex>::const_iterator it = vertices.begin(); it != vertices.end(); ++it) { @@ -119,8 +119,8 @@ int IndependentSetOrdering(const Graph<Vertex>& graph, } - sort(vertex_queue.begin(), vertex_queue.end(), - VertexTotalOrdering<Vertex>(graph)); + std::sort(vertex_queue.begin(), vertex_queue.end(), + VertexTotalOrdering<Vertex>(graph)); // Iterate over vertex_queue. Pick the first white vertex, add it // to the independent set. Mark it black and its neighbors grey. @@ -145,7 +145,7 @@ int IndependentSetOrdering(const Graph<Vertex>& graph, // Iterate over the vertices and add all the grey vertices to the // ordering. At this stage there should only be black or grey // vertices in the graph. - for (typename vector<Vertex>::const_iterator it = vertex_queue.begin(); + for (typename std::vector<Vertex>::const_iterator it = vertex_queue.begin(); it != vertex_queue.end(); ++it) { const Vertex vertex = *it; @@ -171,7 +171,7 @@ int IndependentSetOrdering(const Graph<Vertex>& graph, // ordering algorithm over all. template <typename Vertex> int StableIndependentSetOrdering(const Graph<Vertex>& graph, - vector<Vertex>* ordering) { + std::vector<Vertex>* ordering) { CHECK_NOTNULL(ordering); const HashSet<Vertex>& vertices = graph.vertices(); const int num_vertices = vertices.size(); @@ -182,10 +182,10 @@ int StableIndependentSetOrdering(const Graph<Vertex>& graph, const char kGrey = 1; const char kBlack = 2; - vector<Vertex> vertex_queue(*ordering); + std::vector<Vertex> vertex_queue(*ordering); - stable_sort(vertex_queue.begin(), vertex_queue.end(), - VertexDegreeLessThan<Vertex>(graph)); + std::stable_sort(vertex_queue.begin(), vertex_queue.end(), + VertexDegreeLessThan<Vertex>(graph)); // Mark all vertices white. HashMap<Vertex, char> vertex_color; @@ -220,7 +220,7 @@ int StableIndependentSetOrdering(const Graph<Vertex>& graph, // Iterate over the vertices and add all the grey vertices to the // ordering. At this stage there should only be black or grey // vertices in the graph. - for (typename vector<Vertex>::const_iterator it = vertex_queue.begin(); + for (typename std::vector<Vertex>::const_iterator it = vertex_queue.begin(); it != vertex_queue.end(); ++it) { const Vertex vertex = *it; @@ -274,7 +274,7 @@ template <typename Vertex> WeightedGraph<Vertex>* Degree2MaximumSpanningForest(const WeightedGraph<Vertex>& graph) { // Array of edges sorted in decreasing order of their weights. - vector<pair<double, pair<Vertex, Vertex> > > weighted_edges; + std::vector<std::pair<double, std::pair<Vertex, Vertex> > > weighted_edges; WeightedGraph<Vertex>* forest = new WeightedGraph<Vertex>(); // Disjoint-set to keep track of the connected components in the @@ -302,19 +302,20 @@ Degree2MaximumSpanningForest(const WeightedGraph<Vertex>& graph) { continue; } const double weight = graph.EdgeWeight(vertex1, vertex2); - weighted_edges.push_back(make_pair(weight, make_pair(vertex1, vertex2))); + weighted_edges.push_back( + std::make_pair(weight, std::make_pair(vertex1, vertex2))); } } // The elements of this vector, are pairs<edge_weight, // edge>. Sorting it using the reverse iterators gives us the edges // in decreasing order of edges. - sort(weighted_edges.rbegin(), weighted_edges.rend()); + std::sort(weighted_edges.rbegin(), weighted_edges.rend()); // Greedily add edges to the spanning tree/forest as long as they do // not violate the degree/cycle constraint. for (int i =0; i < weighted_edges.size(); ++i) { - const pair<Vertex, Vertex>& edge = weighted_edges[i].second; + const std::pair<Vertex, Vertex>& edge = weighted_edges[i].second; const Vertex vertex1 = edge.first; const Vertex vertex2 = edge.second; @@ -350,7 +351,7 @@ Degree2MaximumSpanningForest(const WeightedGraph<Vertex>& graph) { // lookup. if (root2 < root1) { std::swap(root1, root2); - }; + } disjoint_set[root2] = root1; } diff --git a/extern/libmv/third_party/ceres/internal/ceres/householder_vector.h b/extern/libmv/third_party/ceres/internal/ceres/householder_vector.h new file mode 100644 index 00000000000..f54feea054d --- /dev/null +++ b/extern/libmv/third_party/ceres/internal/ceres/householder_vector.h @@ -0,0 +1,85 @@ +// Ceres Solver - A fast non-linear least squares minimizer +// Copyright 2015 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: vitus@google.com (Michael Vitus) + +#ifndef CERES_PUBLIC_HOUSEHOLDER_VECTOR_H_ +#define CERES_PUBLIC_HOUSEHOLDER_VECTOR_H_ + +#include "Eigen/Core" +#include "glog/logging.h" + +namespace ceres { +namespace internal { + +// Algorithm 5.1.1 from 'Matrix Computations' by Golub et al. (Johns Hopkins +// Studies in Mathematical Sciences) but using the nth element of the input +// vector as pivot instead of first. This computes the vector v with v(n) = 1 +// and beta such that H = I - beta * v * v^T is orthogonal and +// H * x = ||x||_2 * e_n. +template <typename Scalar> +void ComputeHouseholderVector(const Eigen::Matrix<Scalar, Eigen::Dynamic, 1>& x, + Eigen::Matrix<Scalar, Eigen::Dynamic, 1>* v, + Scalar* beta) { + CHECK_NOTNULL(beta); + CHECK_NOTNULL(v); + CHECK_GT(x.rows(), 1); + CHECK_EQ(x.rows(), v->rows()); + + Scalar sigma = x.head(x.rows() - 1).squaredNorm(); + *v = x; + (*v)(v->rows() - 1) = Scalar(1.0); + + *beta = Scalar(0.0); + const Scalar& x_pivot = x(x.rows() - 1); + + if (sigma <= Scalar(std::numeric_limits<double>::epsilon())) { + if (x_pivot < Scalar(0.0)) { + *beta = Scalar(2.0); + } + return; + } + + const Scalar mu = sqrt(x_pivot * x_pivot + sigma); + Scalar v_pivot = Scalar(1.0); + + if (x_pivot <= Scalar(0.0)) { + v_pivot = x_pivot - mu; + } else { + v_pivot = -sigma / (x_pivot + mu); + } + + *beta = Scalar(2.0) * v_pivot * v_pivot / (sigma + v_pivot * v_pivot); + + v->head(v->rows() - 1) /= v_pivot; +} + +} // namespace internal +} // namespace ceres + +#endif // CERES_PUBLIC_HOUSEHOLDER_VECTOR_H_ diff --git a/extern/libmv/third_party/ceres/internal/ceres/implicit_schur_complement.cc b/extern/libmv/third_party/ceres/internal/ceres/implicit_schur_complement.cc index 2da6235f513..d05f03817b7 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/implicit_schur_complement.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/implicit_schur_complement.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/implicit_schur_complement.h b/extern/libmv/third_party/ceres/internal/ceres/implicit_schur_complement.h index c992bdc206e..5d822ebaeef 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/implicit_schur_complement.h +++ b/extern/libmv/third_party/ceres/internal/ceres/implicit_schur_complement.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -97,7 +97,7 @@ class ImplicitSchurComplement : public LinearOperator { // // TODO(sameeragarwal): Get rid of the two bools below and replace // them with enums. - ImplicitSchurComplement(const LinearSolver::Options& options); + explicit ImplicitSchurComplement(const LinearSolver::Options& options); virtual ~ImplicitSchurComplement(); // Initialize the Schur complement for a linear least squares diff --git a/extern/libmv/third_party/ceres/internal/ceres/incomplete_lq_factorization.cc b/extern/libmv/third_party/ceres/internal/ceres/incomplete_lq_factorization.cc deleted file mode 100644 index 6ba38ec8eec..00000000000 --- a/extern/libmv/third_party/ceres/internal/ceres/incomplete_lq_factorization.cc +++ /dev/null @@ -1,239 +0,0 @@ -// Ceres Solver - A fast non-linear least squares minimizer -// Copyright 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) - -#include "ceres/incomplete_lq_factorization.h" - -#include <vector> -#include <utility> -#include <cmath> -#include "ceres/compressed_row_sparse_matrix.h" -#include "ceres/internal/eigen.h" -#include "ceres/internal/port.h" -#include "glog/logging.h" - -namespace ceres { -namespace internal { - -// Normalize a row and return it's norm. -inline double NormalizeRow(const int row, CompressedRowSparseMatrix* matrix) { - const int row_begin = matrix->rows()[row]; - const int row_end = matrix->rows()[row + 1]; - - double* values = matrix->mutable_values(); - double norm = 0.0; - for (int i = row_begin; i < row_end; ++i) { - norm += values[i] * values[i]; - } - - norm = sqrt(norm); - const double inverse_norm = 1.0 / norm; - for (int i = row_begin; i < row_end; ++i) { - values[i] *= inverse_norm; - } - - return norm; -} - -// Compute a(row_a,:) * b(row_b, :)' -inline double RowDotProduct(const CompressedRowSparseMatrix& a, - const int row_a, - const CompressedRowSparseMatrix& b, - const int row_b) { - const int* a_rows = a.rows(); - const int* a_cols = a.cols(); - const double* a_values = a.values(); - - const int* b_rows = b.rows(); - const int* b_cols = b.cols(); - const double* b_values = b.values(); - - const int row_a_end = a_rows[row_a + 1]; - const int row_b_end = b_rows[row_b + 1]; - - int idx_a = a_rows[row_a]; - int idx_b = b_rows[row_b]; - double dot_product = 0.0; - while (idx_a < row_a_end && idx_b < row_b_end) { - if (a_cols[idx_a] == b_cols[idx_b]) { - dot_product += a_values[idx_a++] * b_values[idx_b++]; - } - - while (a_cols[idx_a] < b_cols[idx_b] && idx_a < row_a_end) { - ++idx_a; - } - - while (a_cols[idx_a] > b_cols[idx_b] && idx_b < row_b_end) { - ++idx_b; - } - } - - return dot_product; -} - -struct SecondGreaterThan { - public: - bool operator()(const pair<int, double>& lhs, - const pair<int, double>& rhs) const { - return (fabs(lhs.second) > fabs(rhs.second)); - } -}; - -// In the row vector dense_row(0:num_cols), drop values smaller than -// the max_value * drop_tolerance. Of the remaining non-zero values, -// choose at most level_of_fill values and then add the resulting row -// vector to matrix. - -void DropEntriesAndAddRow(const Vector& dense_row, - const int num_entries, - const int level_of_fill, - const double drop_tolerance, - vector<pair<int, double> >* scratch, - CompressedRowSparseMatrix* matrix) { - int* rows = matrix->mutable_rows(); - int* cols = matrix->mutable_cols(); - double* values = matrix->mutable_values(); - int num_nonzeros = rows[matrix->num_rows()]; - - if (num_entries == 0) { - matrix->set_num_rows(matrix->num_rows() + 1); - rows[matrix->num_rows()] = num_nonzeros; - return; - } - - const double max_value = dense_row.head(num_entries).cwiseAbs().maxCoeff(); - const double threshold = drop_tolerance * max_value; - - int scratch_count = 0; - for (int i = 0; i < num_entries; ++i) { - if (fabs(dense_row[i]) > threshold) { - pair<int, double>& entry = (*scratch)[scratch_count]; - entry.first = i; - entry.second = dense_row[i]; - ++scratch_count; - } - } - - if (scratch_count > level_of_fill) { - nth_element(scratch->begin(), - scratch->begin() + level_of_fill, - scratch->begin() + scratch_count, - SecondGreaterThan()); - scratch_count = level_of_fill; - sort(scratch->begin(), scratch->begin() + scratch_count); - } - - for (int i = 0; i < scratch_count; ++i) { - const pair<int, double>& entry = (*scratch)[i]; - cols[num_nonzeros] = entry.first; - values[num_nonzeros] = entry.second; - ++num_nonzeros; - } - - matrix->set_num_rows(matrix->num_rows() + 1); - rows[matrix->num_rows()] = num_nonzeros; -} - -// Saad's Incomplete LQ factorization algorithm. -CompressedRowSparseMatrix* IncompleteLQFactorization( - const CompressedRowSparseMatrix& matrix, - const int l_level_of_fill, - const double l_drop_tolerance, - const int q_level_of_fill, - const double q_drop_tolerance) { - const int num_rows = matrix.num_rows(); - const int num_cols = matrix.num_cols(); - const int* rows = matrix.rows(); - const int* cols = matrix.cols(); - const double* values = matrix.values(); - - CompressedRowSparseMatrix* l = - new CompressedRowSparseMatrix(num_rows, - num_rows, - l_level_of_fill * num_rows); - l->set_num_rows(0); - - CompressedRowSparseMatrix q(num_rows, num_cols, q_level_of_fill * num_rows); - q.set_num_rows(0); - - int* l_rows = l->mutable_rows(); - int* l_cols = l->mutable_cols(); - double* l_values = l->mutable_values(); - - int* q_rows = q.mutable_rows(); - int* q_cols = q.mutable_cols(); - double* q_values = q.mutable_values(); - - Vector l_i(num_rows); - Vector q_i(num_cols); - vector<pair<int, double> > scratch(num_cols); - for (int i = 0; i < num_rows; ++i) { - // l_i = q * matrix(i,:)'); - l_i.setZero(); - for (int j = 0; j < i; ++j) { - l_i(j) = RowDotProduct(matrix, i, q, j); - } - DropEntriesAndAddRow(l_i, - i, - l_level_of_fill, - l_drop_tolerance, - &scratch, - l); - - // q_i = matrix(i,:) - q(0:i-1,:) * l_i); - q_i.setZero(); - for (int idx = rows[i]; idx < rows[i + 1]; ++idx) { - q_i(cols[idx]) = values[idx]; - } - - for (int j = l_rows[i]; j < l_rows[i + 1]; ++j) { - const int r = l_cols[j]; - const double lij = l_values[j]; - for (int idx = q_rows[r]; idx < q_rows[r + 1]; ++idx) { - q_i(q_cols[idx]) -= lij * q_values[idx]; - } - } - DropEntriesAndAddRow(q_i, - num_cols, - q_level_of_fill, - q_drop_tolerance, - &scratch, - &q); - - // lii = |qi| - l_cols[l->num_nonzeros()] = i; - l_values[l->num_nonzeros()] = NormalizeRow(i, &q); - l_rows[l->num_rows()] += 1; - } - - return l; -} - -} // namespace internal -} // namespace ceres diff --git a/extern/libmv/third_party/ceres/internal/ceres/incomplete_lq_factorization.h b/extern/libmv/third_party/ceres/internal/ceres/incomplete_lq_factorization.h deleted file mode 100644 index e678463cf8d..00000000000 --- a/extern/libmv/third_party/ceres/internal/ceres/incomplete_lq_factorization.h +++ /dev/null @@ -1,90 +0,0 @@ -// Ceres Solver - A fast non-linear least squares minimizer -// Copyright 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) - -#ifndef CERES_INTERNAL_INCOMPLETE_LQ_FACTORIZATION_H_ -#define CERES_INTERNAL_INCOMPLETE_LQ_FACTORIZATION_H_ - -#include <vector> -#include <utility> -#include "ceres/compressed_row_sparse_matrix.h" - -namespace ceres { -namespace internal { - -// Incomplete LQ factorization as described in -// -// Preconditioning techniques for indefinite and nonsymmetric linear -// systems. Yousef Saad, Preprint RIACS-ILQ-TR, RIACS, NASA Ames -// Research Center, Moffett Field, CA, 1987. -// -// An incomplete LQ factorization of a matrix A is a decomposition -// -// A = LQ + E -// -// Where L is a lower triangular matrix, and Q is a near orthonormal -// matrix. The extent of orthonormality depends on E. E is the "drop" -// matrix. Each row of L has a maximum of l_level_of_fill entries, and -// all non-zero entries are within l_drop_tolerance of the largest -// entry. Each row of Q has a maximum of q_level_of_fill entries and -// all non-zero entries are within q_drop_tolerance of the largest -// entry. -// -// E is the error of the incomplete factorization. -// -// The purpose of incomplete factorizations is preconditioning and -// there one only needs the L matrix, therefore this function just -// returns L. -// -// Caller owns the result. -CompressedRowSparseMatrix* IncompleteLQFactorization( - const CompressedRowSparseMatrix& matrix, - const int l_level_of_fill, - const double l_drop_tolerance, - const int q_level_of_fill, - const double q_drop_tolerance); - -// In the row vector dense_row(0:num_cols), drop values smaller than -// the max_value * drop_tolerance. Of the remaining non-zero values, -// choose at most level_of_fill values and then add the resulting row -// vector to matrix. -// -// scratch is used to prevent allocations inside this function. It is -// assumed that scratch is of size matrix->num_cols(). -void DropEntriesAndAddRow(const Vector& dense_row, - const int num_entries, - const int level_of_fill, - const double drop_tolerance, - vector<pair<int, double> >* scratch, - CompressedRowSparseMatrix* matrix); - -} // namespace internal -} // namespace ceres - -#endif // CERES_INTERNAL_INCOMPLETE_LQ_FACTORIZATION_H_ diff --git a/extern/libmv/third_party/ceres/internal/ceres/integral_types.h b/extern/libmv/third_party/ceres/internal/ceres/integral_types.h index d4913f53745..98a746f13ff 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/integral_types.h +++ b/extern/libmv/third_party/ceres/internal/ceres/integral_types.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/iterative_schur_complement_solver.cc b/extern/libmv/third_party/ceres/internal/ceres/iterative_schur_complement_solver.cc index 0cf08fef5f7..9d4e30d69d2 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/iterative_schur_complement_solver.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/iterative_schur_complement_solver.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/iterative_schur_complement_solver.h b/extern/libmv/third_party/ceres/internal/ceres/iterative_schur_complement_solver.h index b056a694478..e90d310de07 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/iterative_schur_complement_solver.h +++ b/extern/libmv/third_party/ceres/internal/ceres/iterative_schur_complement_solver.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/lapack.cc b/extern/libmv/third_party/ceres/internal/ceres/lapack.cc index e124d757024..6fc23f4e658 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/lapack.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/lapack.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -70,7 +70,7 @@ LinearSolverTerminationType LAPACK::SolveInPlaceUsingCholesky( int num_rows, const double* in_lhs, double* rhs_and_solution, - string* message) { + std::string* message) { #ifdef CERES_NO_LAPACK LOG(FATAL) << "Ceres was built without a BLAS library."; return LINEAR_SOLVER_FATAL_ERROR; @@ -110,7 +110,7 @@ LinearSolverTerminationType LAPACK::SolveInPlaceUsingCholesky( *message = "Success"; return LINEAR_SOLVER_SUCCESS; #endif -}; +} int LAPACK::EstimateWorkSizeForQR(int num_rows, int num_cols) { #ifdef CERES_NO_LAPACK @@ -151,7 +151,7 @@ LinearSolverTerminationType LAPACK::SolveInPlaceUsingQR( int work_size, double* work, double* rhs_and_solution, - string* message) { + std::string* message) { #ifdef CERES_NO_LAPACK LOG(FATAL) << "Ceres was built without a LAPACK library."; return LINEAR_SOLVER_FATAL_ERROR; diff --git a/extern/libmv/third_party/ceres/internal/ceres/lapack.h b/extern/libmv/third_party/ceres/internal/ceres/lapack.h index 8933c2c8d83..5bb1a220c26 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/lapack.h +++ b/extern/libmv/third_party/ceres/internal/ceres/lapack.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -58,7 +58,7 @@ class LAPACK { int num_rows, const double* lhs, double* rhs_and_solution, - string* message); + std::string* message); // The SolveUsingQR function requires a buffer for its temporary // computation. This function given the size of the lhs matrix will @@ -91,7 +91,7 @@ class LAPACK { int work_size, double* work, double* rhs_and_solution, - string* message); + std::string* message); }; } // namespace internal diff --git a/extern/libmv/third_party/ceres/internal/ceres/levenberg_marquardt_strategy.cc b/extern/libmv/third_party/ceres/internal/ceres/levenberg_marquardt_strategy.cc index ce3b69a8005..e9833805ef5 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/levenberg_marquardt_strategy.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/levenberg_marquardt_strategy.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -79,7 +79,8 @@ TrustRegionStrategy::Summary LevenbergMarquardtStrategy::ComputeStep( jacobian->SquaredColumnNorm(diagonal_.data()); for (int i = 0; i < num_parameters; ++i) { - diagonal_[i] = min(max(diagonal_[i], min_diagonal_), max_diagonal_); + diagonal_[i] = std::min(std::max(diagonal_[i], min_diagonal_), + max_diagonal_); } } @@ -107,9 +108,12 @@ TrustRegionStrategy::Summary LevenbergMarquardtStrategy::ComputeStep( linear_solver_->Solve(jacobian, residuals, solve_options, step); if (linear_solver_summary.termination_type == LINEAR_SOLVER_FATAL_ERROR) { - LOG(WARNING) << "Linear solver fatal error."; - } else if (linear_solver_summary.termination_type == LINEAR_SOLVER_FAILURE || - !IsArrayValid(num_parameters, step)) { + LOG(WARNING) << "Linear solver fatal error: " + << linear_solver_summary.message; + } else if (linear_solver_summary.termination_type == LINEAR_SOLVER_FAILURE) { + LOG(WARNING) << "Linear solver failure. Failed to compute a step: " + << linear_solver_summary.message; + } else if (!IsArrayValid(num_parameters, step)) { LOG(WARNING) << "Linear solver failure. Failed to compute a finite step."; linear_solver_summary.termination_type = LINEAR_SOLVER_FAILURE; } else { diff --git a/extern/libmv/third_party/ceres/internal/ceres/levenberg_marquardt_strategy.h b/extern/libmv/third_party/ceres/internal/ceres/levenberg_marquardt_strategy.h index 344e3285422..c87a016c8f4 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/levenberg_marquardt_strategy.h +++ b/extern/libmv/third_party/ceres/internal/ceres/levenberg_marquardt_strategy.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/line_search.cc b/extern/libmv/third_party/ceres/internal/ceres/line_search.cc index 7ff11646dd3..9cdcb7b77e5 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/line_search.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/line_search.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -28,20 +28,28 @@ // // Author: sameeragarwal@google.com (Sameer Agarwal) +#include "ceres/line_search.h" + #include <iomanip> #include <iostream> // NOLINT -#include "ceres/line_search.h" - -#include "ceres/fpclassify.h" +#include "glog/logging.h" #include "ceres/evaluator.h" #include "ceres/internal/eigen.h" +#include "ceres/fpclassify.h" +#include "ceres/map_util.h" #include "ceres/polynomial.h" #include "ceres/stringprintf.h" -#include "glog/logging.h" +#include "ceres/wall_time.h" namespace ceres { namespace internal { + +using std::map; +using std::ostream; +using std::string; +using std::vector; + namespace { // Precision used for floating point values in error message output. const int kErrorMessageNumericPrecision = 8; @@ -52,7 +60,7 @@ FunctionSample ValueSample(const double x, const double value) { sample.value = value; sample.value_is_valid = true; return sample; -}; +} FunctionSample ValueAndGradientSample(const double x, const double value, @@ -64,15 +72,15 @@ FunctionSample ValueAndGradientSample(const double x, sample.value_is_valid = true; sample.gradient_is_valid = true; return sample; -}; +} } // namespace -std::ostream& operator<<(std::ostream &os, const FunctionSample& sample); +ostream& operator<<(ostream &os, const FunctionSample& sample); // Convenience stream operator for pushing FunctionSamples into log messages. -std::ostream& operator<<(std::ostream &os, const FunctionSample& sample) { +ostream& operator<<(ostream &os, const FunctionSample& sample) { os << sample.ToDebugString(); return os; } @@ -106,8 +114,9 @@ LineSearchFunction::LineSearchFunction(Evaluator* evaluator) direction_(evaluator->NumEffectiveParameters()), evaluation_point_(evaluator->NumParameters()), scaled_direction_(evaluator->NumEffectiveParameters()), - gradient_(evaluator->NumEffectiveParameters()) { -} + gradient_(evaluator->NumEffectiveParameters()), + initial_evaluator_residual_time_in_seconds(0.0), + initial_evaluator_jacobian_time_in_seconds(0.0) {} void LineSearchFunction::Init(const Vector& position, const Vector& direction) { @@ -125,14 +134,12 @@ bool LineSearchFunction::Evaluate(double x, double* f, double* g) { if (g == NULL) { return (evaluator_->Evaluate(evaluation_point_.data(), - f, NULL, NULL, NULL) && + f, NULL, NULL, NULL) && IsFinite(*f)); } if (!evaluator_->Evaluate(evaluation_point_.data(), - f, - NULL, - gradient_.data(), NULL)) { + f, NULL, gradient_.data(), NULL)) { return false; } @@ -144,6 +151,54 @@ double LineSearchFunction::DirectionInfinityNorm() const { return direction_.lpNorm<Eigen::Infinity>(); } +void LineSearchFunction::ResetTimeStatistics() { + const map<string, double> evaluator_time_statistics = + evaluator_->TimeStatistics(); + initial_evaluator_residual_time_in_seconds = + FindWithDefault(evaluator_time_statistics, "Evaluator::Residual", 0.0); + initial_evaluator_jacobian_time_in_seconds = + FindWithDefault(evaluator_time_statistics, "Evaluator::Jacobian", 0.0); +} + +void LineSearchFunction::TimeStatistics( + double* cost_evaluation_time_in_seconds, + double* gradient_evaluation_time_in_seconds) const { + const map<string, double> evaluator_time_statistics = + evaluator_->TimeStatistics(); + *cost_evaluation_time_in_seconds = + FindWithDefault(evaluator_time_statistics, "Evaluator::Residual", 0.0) - + initial_evaluator_residual_time_in_seconds; + // Strictly speaking this will slightly underestimate the time spent + // evaluating the gradient of the line search univariate cost function as it + // does not count the time spent performing the dot product with the direction + // vector. However, this will typically be small by comparison, and also + // allows direct subtraction of the timing information from the totals for + // the evaluator returned in the solver summary. + *gradient_evaluation_time_in_seconds = + FindWithDefault(evaluator_time_statistics, "Evaluator::Jacobian", 0.0) - + initial_evaluator_jacobian_time_in_seconds; +} + +void LineSearch::Search(double step_size_estimate, + double initial_cost, + double initial_gradient, + Summary* summary) const { + const double start_time = WallTimeInSeconds(); + *CHECK_NOTNULL(summary) = LineSearch::Summary(); + + summary->cost_evaluation_time_in_seconds = 0.0; + summary->gradient_evaluation_time_in_seconds = 0.0; + summary->polynomial_minimization_time_in_seconds = 0.0; + + options().function->ResetTimeStatistics(); + this->DoSearch(step_size_estimate, initial_cost, initial_gradient, summary); + options().function-> + TimeStatistics(&summary->cost_evaluation_time_in_seconds, + &summary->gradient_evaluation_time_in_seconds); + + summary->total_time_in_seconds = WallTimeInSeconds() - start_time; +} + // Returns step_size \in [min_step_size, max_step_size] which minimizes the // polynomial of degree defined by interpolation_type which interpolates all // of the provided samples with valid values. @@ -159,7 +214,7 @@ double LineSearch::InterpolatingPolynomialMinimizingStepSize( max_step_size <= current.x)) { // Either: sample is invalid; or we are using BISECTION and contracting // the step size. - return min(max(current.x * 0.5, min_step_size), max_step_size); + return std::min(std::max(current.x * 0.5, min_step_size), max_step_size); } else if (interpolation_type == BISECTION) { CHECK_GT(max_step_size, current.x); // We are expanding the search (during a Wolfe bracketing phase) using @@ -219,16 +274,15 @@ double LineSearch::InterpolatingPolynomialMinimizingStepSize( ArmijoLineSearch::ArmijoLineSearch(const LineSearch::Options& options) : LineSearch(options) {} -void ArmijoLineSearch::Search(const double step_size_estimate, - const double initial_cost, - const double initial_gradient, - Summary* summary) { - *CHECK_NOTNULL(summary) = LineSearch::Summary(); +void ArmijoLineSearch::DoSearch(const double step_size_estimate, + const double initial_cost, + const double initial_gradient, + Summary* summary) const { CHECK_GE(step_size_estimate, 0.0); CHECK_GT(options().sufficient_decrease, 0.0); CHECK_LT(options().sufficient_decrease, 1.0); CHECK_GT(options().max_num_iterations, 0); - Function* function = options().function; + LineSearchFunction* function = options().function; // Note initial_cost & initial_gradient are evaluated at step_size = 0, // not step_size_estimate, which is our starting guess. @@ -247,8 +301,7 @@ void ArmijoLineSearch::Search(const double step_size_estimate, // gradient at the current query point. const bool interpolation_uses_gradient_at_current_sample = options().interpolation_type == CUBIC; - const double descent_direction_max_norm = - static_cast<const LineSearchFunction*>(function)->DirectionInfinityNorm(); + const double descent_direction_max_norm = function->DirectionInfinityNorm(); ++summary->num_function_evaluations; if (interpolation_uses_gradient_at_current_sample) { @@ -279,6 +332,7 @@ void ArmijoLineSearch::Search(const double step_size_estimate, return; } + const double polynomial_minimization_start_time = WallTimeInSeconds(); const double step_size = this->InterpolatingPolynomialMinimizingStepSize( options().interpolation_type, @@ -287,6 +341,8 @@ void ArmijoLineSearch::Search(const double step_size_estimate, current, (options().max_step_contraction * current.x), (options().min_step_contraction * current.x)); + summary->polynomial_minimization_time_in_seconds += + (WallTimeInSeconds() - polynomial_minimization_start_time); if (step_size * descent_direction_max_norm < options().min_step_size) { summary->error = @@ -320,11 +376,10 @@ void ArmijoLineSearch::Search(const double step_size_estimate, WolfeLineSearch::WolfeLineSearch(const LineSearch::Options& options) : LineSearch(options) {} -void WolfeLineSearch::Search(const double step_size_estimate, - const double initial_cost, - const double initial_gradient, - Summary* summary) { - *CHECK_NOTNULL(summary) = LineSearch::Summary(); +void WolfeLineSearch::DoSearch(const double step_size_estimate, + const double initial_cost, + const double initial_gradient, + Summary* summary) const { // All parameters should have been validated by the Solver, but as // invalid values would produce crazy nonsense, hard check them here. CHECK_GE(step_size_estimate, 0.0); @@ -456,15 +511,15 @@ bool WolfeLineSearch::BracketingPhase( FunctionSample* bracket_low, FunctionSample* bracket_high, bool* do_zoom_search, - Summary* summary) { - Function* function = options().function; + Summary* summary) const { + LineSearchFunction* function = options().function; FunctionSample previous = initial_position; FunctionSample current = ValueAndGradientSample(step_size_estimate, 0.0, 0.0); current.value_is_valid = false; const double descent_direction_max_norm = - static_cast<const LineSearchFunction*>(function)->DirectionInfinityNorm(); + function->DirectionInfinityNorm(); *do_zoom_search = false; *bracket_low = initial_position; @@ -594,6 +649,7 @@ bool WolfeLineSearch::BracketingPhase( const FunctionSample unused_previous; DCHECK(!unused_previous.value_is_valid); // Contracts step size if f(current) is not valid. + const double polynomial_minimization_start_time = WallTimeInSeconds(); const double step_size = this->InterpolatingPolynomialMinimizingStepSize( options().interpolation_type, @@ -602,6 +658,8 @@ bool WolfeLineSearch::BracketingPhase( current, previous.x, max_step_size); + summary->polynomial_minimization_time_in_seconds += + (WallTimeInSeconds() - polynomial_minimization_start_time); if (step_size * descent_direction_max_norm < options().min_step_size) { summary->error = StringPrintf("Line search failed: step_size too small: %.5e " @@ -642,8 +700,8 @@ bool WolfeLineSearch::ZoomPhase(const FunctionSample& initial_position, FunctionSample bracket_low, FunctionSample bracket_high, FunctionSample* solution, - Summary* summary) { - Function* function = options().function; + Summary* summary) const { + LineSearchFunction* function = options().function; CHECK(bracket_low.value_is_valid && bracket_low.gradient_is_valid) << std::scientific << std::setprecision(kErrorMessageNumericPrecision) @@ -697,8 +755,7 @@ bool WolfeLineSearch::ZoomPhase(const FunctionSample& initial_position, } const int num_bracketing_iterations = summary->num_iterations; - const double descent_direction_max_norm = - static_cast<const LineSearchFunction*>(function)->DirectionInfinityNorm(); + const double descent_direction_max_norm = function->DirectionInfinityNorm(); while (true) { // Set solution to bracket_low, as it is our best step size (smallest f()) @@ -741,6 +798,7 @@ bool WolfeLineSearch::ZoomPhase(const FunctionSample& initial_position, // value that will therefore be ignored. const FunctionSample unused_previous; DCHECK(!unused_previous.value_is_valid); + const double polynomial_minimization_start_time = WallTimeInSeconds(); solution->x = this->InterpolatingPolynomialMinimizingStepSize( options().interpolation_type, @@ -749,6 +807,8 @@ bool WolfeLineSearch::ZoomPhase(const FunctionSample& initial_position, upper_bound_step, lower_bound_step.x, upper_bound_step.x); + summary->polynomial_minimization_time_in_seconds += + (WallTimeInSeconds() - polynomial_minimization_start_time); // No check on magnitude of step size being too small here as it is // lower-bounded by the initial bracket start point, which was valid. // diff --git a/extern/libmv/third_party/ceres/internal/ceres/line_search.h b/extern/libmv/third_party/ceres/internal/ceres/line_search.h index 97b9bc68cfe..6a21cbeac11 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/line_search.h +++ b/extern/libmv/third_party/ceres/internal/ceres/line_search.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -44,6 +44,7 @@ namespace internal { class Evaluator; struct FunctionSample; +class LineSearchFunction; // Line search is another name for a one dimensional optimization // algorithm. The name "line search" comes from the fact one @@ -57,7 +58,7 @@ struct FunctionSample; // algorithms, e.g., Armijo, Wolfe etc. class LineSearch { public: - class Function; + struct Summary; struct Options { Options() @@ -147,31 +148,7 @@ class LineSearch { // The one dimensional function that the line search algorithm // minimizes. - Function* function; - }; - - // An object used by the line search to access the function values - // and gradient of the one dimensional function being optimized. - // - // In practice, this object will provide access to the objective - // function value and the directional derivative of the underlying - // optimization problem along a specific search direction. - // - // See LineSearchFunction for an example implementation. - class Function { - public: - virtual ~Function() {} - // Evaluate the line search objective - // - // f(x) = p(position + x * direction) - // - // Where, p is the objective function of the general optimization - // problem. - // - // g is the gradient f'(x) at x. - // - // f must not be null. The gradient is computed only if g is not null. - virtual bool Evaluate(double x, double* f, double* g) = 0; + LineSearchFunction* function; }; // Result of the line search. @@ -181,14 +158,28 @@ class LineSearch { optimal_step_size(0.0), num_function_evaluations(0), num_gradient_evaluations(0), - num_iterations(0) {} + num_iterations(0), + cost_evaluation_time_in_seconds(-1.0), + gradient_evaluation_time_in_seconds(-1.0), + polynomial_minimization_time_in_seconds(-1.0), + total_time_in_seconds(-1.0) {} bool success; double optimal_step_size; int num_function_evaluations; int num_gradient_evaluations; int num_iterations; - string error; + // Cumulative time spent evaluating the value of the cost function across + // all iterations. + double cost_evaluation_time_in_seconds; + // Cumulative time spent evaluating the gradient of the cost function across + // all iterations. + double gradient_evaluation_time_in_seconds; + // Cumulative time spent minimizing the interpolating polynomial to compute + // the next candidate step size across all iterations. + double polynomial_minimization_time_in_seconds; + double total_time_in_seconds; + std::string error; }; explicit LineSearch(const LineSearch::Options& options); @@ -196,7 +187,7 @@ class LineSearch { static LineSearch* Create(const LineSearchType line_search_type, const LineSearch::Options& options, - string* error); + std::string* error); // Perform the line search. // @@ -208,10 +199,10 @@ class LineSearch { // search. // // Summary::success is true if a non-zero step size is found. - virtual void Search(double step_size_estimate, - double initial_cost, - double initial_gradient, - Summary* summary) = 0; + void Search(double step_size_estimate, + double initial_cost, + double initial_gradient, + Summary* summary) const; double InterpolatingPolynomialMinimizingStepSize( const LineSearchInterpolationType& interpolation_type, const FunctionSample& lowerbound_sample, @@ -224,16 +215,41 @@ class LineSearch { const LineSearch::Options& options() const { return options_; } private: + virtual void DoSearch(double step_size_estimate, + double initial_cost, + double initial_gradient, + Summary* summary) const = 0; + + private: LineSearch::Options options_; }; -class LineSearchFunction : public LineSearch::Function { +// An object used by the line search to access the function values +// and gradient of the one dimensional function being optimized. +// +// In practice, this object provides access to the objective +// function value and the directional derivative of the underlying +// optimization problem along a specific search direction. +class LineSearchFunction { public: explicit LineSearchFunction(Evaluator* evaluator); - virtual ~LineSearchFunction() {} void Init(const Vector& position, const Vector& direction); - virtual bool Evaluate(double x, double* f, double* g); + // Evaluate the line search objective + // + // f(x) = p(position + x * direction) + // + // Where, p is the objective function of the general optimization + // problem. + // + // g is the gradient f'(x) at x. + // + // f must not be null. The gradient is computed only if g is not null. + bool Evaluate(double x, double* f, double* g); double DirectionInfinityNorm() const; + // Resets to now, the start point for the results from TimeStatistics(). + void ResetTimeStatistics(); + void TimeStatistics(double* cost_evaluation_time_in_seconds, + double* gradient_evaluation_time_in_seconds) const; private: Evaluator* evaluator_; @@ -246,6 +262,13 @@ class LineSearchFunction : public LineSearch::Function { // scaled_direction = x * direction_; Vector scaled_direction_; Vector gradient_; + + // We may not exclusively own the evaluator (e.g. in the Trust Region + // minimizer), hence we need to save the initial evaluation durations for the + // value & gradient to accurately determine the duration of the evaluations + // we invoked. These are reset by a call to ResetTimeStatistics(). + double initial_evaluator_residual_time_in_seconds; + double initial_evaluator_jacobian_time_in_seconds; }; // Backtracking and interpolation based Armijo line search. This @@ -257,10 +280,12 @@ class ArmijoLineSearch : public LineSearch { public: explicit ArmijoLineSearch(const LineSearch::Options& options); virtual ~ArmijoLineSearch() {} - virtual void Search(double step_size_estimate, - double initial_cost, - double initial_gradient, - Summary* summary); + + private: + virtual void DoSearch(double step_size_estimate, + double initial_cost, + double initial_gradient, + Summary* summary) const; }; // Bracketing / Zoom Strong Wolfe condition line search. This implementation @@ -274,23 +299,26 @@ class WolfeLineSearch : public LineSearch { public: explicit WolfeLineSearch(const LineSearch::Options& options); virtual ~WolfeLineSearch() {} - virtual void Search(double step_size_estimate, - double initial_cost, - double initial_gradient, - Summary* summary); + // Returns true iff either a valid point, or valid bracket are found. bool BracketingPhase(const FunctionSample& initial_position, const double step_size_estimate, FunctionSample* bracket_low, FunctionSample* bracket_high, bool* perform_zoom_search, - Summary* summary); + Summary* summary) const; // Returns true iff final_line_sample satisfies strong Wolfe conditions. bool ZoomPhase(const FunctionSample& initial_position, FunctionSample bracket_low, FunctionSample bracket_high, FunctionSample* solution, - Summary* summary); + Summary* summary) const; + + private: + virtual void DoSearch(double step_size_estimate, + double initial_cost, + double initial_gradient, + Summary* summary) const; }; } // namespace internal 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 dddcecdb196..1f9d205bff5 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 @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -86,7 +86,7 @@ class NonlinearConjugateGradient : public LineSearchDirection { LOG(WARNING) << "Restarting non-linear conjugate gradients: " << directional_derivative; *search_direction = -current.gradient; - }; + } return true; } diff --git a/extern/libmv/third_party/ceres/internal/ceres/line_search_direction.h b/extern/libmv/third_party/ceres/internal/ceres/line_search_direction.h index c77fdc8e65b..467578d5f7c 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/line_search_direction.h +++ b/extern/libmv/third_party/ceres/internal/ceres/line_search_direction.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/line_search_minimizer.cc b/extern/libmv/third_party/ceres/internal/ceres/line_search_minimizer.cc index ad28ffb137d..62264fb0b64 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/line_search_minimizer.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/line_search_minimizer.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -69,7 +69,7 @@ namespace { bool Evaluate(Evaluator* evaluator, const Vector& x, LineSearchMinimizer::State* state, - string* message) { + std::string* message) { if (!evaluator->Evaluate(x.data(), &(state->cost), NULL, @@ -290,9 +290,9 @@ void LineSearchMinimizer::Minimize(const Minimizer::Options& options, // iteration. const double initial_step_size = (iteration_summary.iteration == 1 || !line_search_status) - ? min(1.0, 1.0 / current_state.gradient_max_norm) - : min(1.0, 2.0 * (current_state.cost - previous_state.cost) / - current_state.directional_derivative); + ? std::min(1.0, 1.0 / current_state.gradient_max_norm) + : std::min(1.0, 2.0 * (current_state.cost - previous_state.cost) / + current_state.directional_derivative); // By definition, we should only ever go forwards along the specified search // direction in a line search, most likely cause for this being violated // would be a numerical failure in the line search direction calculation. @@ -332,6 +332,8 @@ void LineSearchMinimizer::Minimize(const Minimizer::Options& options, iteration_summary.step_solver_time_in_seconds = WallTimeInSeconds() - iteration_start_time; + const double x_norm = x.norm(); + if (!evaluator->Plus(x.data(), delta.data(), x_plus_delta.data())) { summary->termination_type = FAILURE; summary->message = @@ -361,7 +363,6 @@ void LineSearchMinimizer::Minimize(const Minimizer::Options& options, iteration_summary.step_norm = delta.norm(); iteration_summary.step_is_valid = true; iteration_summary.step_is_successful = true; - iteration_summary.step_norm = delta.norm(); iteration_summary.step_size = current_state.step_size; iteration_summary.line_search_function_evaluations = line_search_summary.num_function_evaluations; @@ -375,8 +376,30 @@ void LineSearchMinimizer::Minimize(const Minimizer::Options& options, WallTimeInSeconds() - start_time + summary->preprocessor_time_in_seconds; + summary->line_search_cost_evaluation_time_in_seconds += + line_search_summary.cost_evaluation_time_in_seconds; + summary->line_search_gradient_evaluation_time_in_seconds += + line_search_summary.gradient_evaluation_time_in_seconds; + summary->line_search_polynomial_minimization_time_in_seconds += + line_search_summary.polynomial_minimization_time_in_seconds; + summary->line_search_total_time_in_seconds += + line_search_summary.total_time_in_seconds; ++summary->num_successful_steps; + const double step_size_tolerance = options.parameter_tolerance * + (x_norm + options.parameter_tolerance); + if (iteration_summary.step_norm <= step_size_tolerance) { + summary->message = + StringPrintf("Parameter tolerance reached. " + "Relative step_norm: %e <= %e.", + (iteration_summary.step_norm / + (x_norm + options.parameter_tolerance)), + options.parameter_tolerance); + summary->termination_type = CONVERGENCE; + VLOG_IF(1, is_not_silent) << "Terminating: " << summary->message; + return; + } + if (iteration_summary.gradient_max_norm <= options.gradient_tolerance) { summary->message = StringPrintf("Gradient tolerance reached. " "Gradient max norm: %e <= %e", @@ -389,7 +412,7 @@ void LineSearchMinimizer::Minimize(const Minimizer::Options& options, const double absolute_function_tolerance = options.function_tolerance * previous_state.cost; - if (fabs(iteration_summary.cost_change) < absolute_function_tolerance) { + if (fabs(iteration_summary.cost_change) <= absolute_function_tolerance) { summary->message = StringPrintf("Function tolerance reached. " "|cost_change|/cost: %e <= %e", diff --git a/extern/libmv/third_party/ceres/internal/ceres/line_search_minimizer.h b/extern/libmv/third_party/ceres/internal/ceres/line_search_minimizer.h index f82f13984a8..54b7202e0c3 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/line_search_minimizer.h +++ b/extern/libmv/third_party/ceres/internal/ceres/line_search_minimizer.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/line_search_preprocessor.cc b/extern/libmv/third_party/ceres/internal/ceres/line_search_preprocessor.cc index bf17dee351d..831f5e8d079 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/line_search_preprocessor.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/line_search_preprocessor.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -42,7 +42,7 @@ namespace ceres { namespace internal { namespace { -bool IsProgramValid(const Program& program, string* error) { +bool IsProgramValid(const Program& program, std::string* error) { if (program.IsBoundsConstrained()) { *error = "LINE_SEARCH Minimizer does not support bounds."; return false; diff --git a/extern/libmv/third_party/ceres/internal/ceres/line_search_preprocessor.h b/extern/libmv/third_party/ceres/internal/ceres/line_search_preprocessor.h index 54b968bc29e..132d83a0a9a 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/line_search_preprocessor.h +++ b/extern/libmv/third_party/ceres/internal/ceres/line_search_preprocessor.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/linear_least_squares_problems.cc b/extern/libmv/third_party/ceres/internal/ceres/linear_least_squares_problems.cc index 24ba565daf9..0a69375f7b5 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/linear_least_squares_problems.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/linear_least_squares_problems.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -46,6 +46,8 @@ namespace ceres { namespace internal { +using std::string; + LinearLeastSquaresProblem* CreateLinearLeastSquaresProblemFromId(int id) { switch (id) { case 0: @@ -56,6 +58,8 @@ LinearLeastSquaresProblem* CreateLinearLeastSquaresProblemFromId(int id) { return LinearLeastSquaresProblem2(); case 3: return LinearLeastSquaresProblem3(); + case 4: + return LinearLeastSquaresProblem4(); default: LOG(FATAL) << "Unknown problem id requested " << id; } @@ -97,11 +101,11 @@ LinearLeastSquaresProblem* LinearLeastSquaresProblem0() { int counter = 0; for (int i = 0; i < 3; ++i) { for (int j = 0; j< 2; ++j) { - Ai[counter]=i; - Aj[counter]=j; + Ai[counter] = i; + Aj[counter] = j; ++counter; } - }; + } Ax[0] = 1.; Ax[1] = 2.; @@ -503,6 +507,106 @@ LinearLeastSquaresProblem* LinearLeastSquaresProblem3() { return problem; } +/* + A = [1 2 0 0 0 1 1 + 1 4 0 0 0 5 6 + 0 0 9 0 0 3 1] + + b = [0 + 1 + 2] +*/ +// BlockSparseMatrix version +// +// This problem has the unique property that it has two different +// sized f-blocks, but only one of them occurs in the rows involving +// the one e-block. So performing Schur elimination on this problem +// tests the Schur Eliminator's ability to handle non-e-block rows +// correctly when their structure does not conform to the static +// structure determined by DetectStructure. +// +// NOTE: This problem is too small and rank deficient to be solved without +// the diagonal regularization. +LinearLeastSquaresProblem* LinearLeastSquaresProblem4() { + int num_rows = 3; + int num_cols = 7; + + LinearLeastSquaresProblem* problem = new LinearLeastSquaresProblem; + + problem->b.reset(new double[num_rows]); + problem->D.reset(new double[num_cols]); + problem->num_eliminate_blocks = 1; + + CompressedRowBlockStructure* bs = new CompressedRowBlockStructure; + scoped_array<double> values(new double[num_rows * num_cols]); + + // Column block structure + bs->cols.push_back(Block()); + bs->cols.back().size = 2; + bs->cols.back().position = 0; + + bs->cols.push_back(Block()); + bs->cols.back().size = 3; + bs->cols.back().position = 2; + + bs->cols.push_back(Block()); + bs->cols.back().size = 2; + bs->cols.back().position = 5; + + int nnz = 0; + + // Row 1 & 2 + { + bs->rows.push_back(CompressedRow()); + CompressedRow& row = bs->rows.back(); + row.block.size = 2; + row.block.position = 0; + + row.cells.push_back(Cell(0, nnz)); + values[nnz++] = 1; + values[nnz++] = 2; + values[nnz++] = 1; + values[nnz++] = 4; + + row.cells.push_back(Cell(2, nnz)); + values[nnz++] = 1; + values[nnz++] = 1; + values[nnz++] = 5; + values[nnz++] = 6; + } + + // Row 3 + { + bs->rows.push_back(CompressedRow()); + CompressedRow& row = bs->rows.back(); + row.block.size = 1; + row.block.position = 2; + + row.cells.push_back(Cell(1, nnz)); + values[nnz++] = 9; + values[nnz++] = 0; + values[nnz++] = 0; + + row.cells.push_back(Cell(2, nnz)); + values[nnz++] = 3; + values[nnz++] = 1; + } + + BlockSparseMatrix* A = new BlockSparseMatrix(bs); + memcpy(A->mutable_values(), values.get(), nnz * sizeof(*A->values())); + + for (int i = 0; i < num_cols; ++i) { + problem->D.get()[i] = (i + 1) * 100; + } + + for (int i = 0; i < num_rows; ++i) { + problem->b.get()[i] = i; + } + + problem->A.reset(A); + return problem; +} + namespace { bool DumpLinearLeastSquaresProblemToConsole(const SparseMatrix* A, const double* D, @@ -527,7 +631,7 @@ bool DumpLinearLeastSquaresProblemToConsole(const SparseMatrix* A, LOG(INFO) << "x: \n" << ConstVectorRef(x, A->num_cols()); } return true; -}; +} void WriteArrayToFileOrDie(const string& filename, const double* x, @@ -619,7 +723,7 @@ bool DumpLinearLeastSquaresProblem(const string& filename_base, num_eliminate_blocks); default: LOG(FATAL) << "Unknown DumpFormatType " << dump_format_type; - }; + } return true; } diff --git a/extern/libmv/third_party/ceres/internal/ceres/linear_least_squares_problems.h b/extern/libmv/third_party/ceres/internal/ceres/linear_least_squares_problems.h index fdeed70de62..384efb59a2b 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/linear_least_squares_problems.h +++ b/extern/libmv/third_party/ceres/internal/ceres/linear_least_squares_problems.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -68,10 +68,11 @@ LinearLeastSquaresProblem* LinearLeastSquaresProblem0(); LinearLeastSquaresProblem* LinearLeastSquaresProblem1(); LinearLeastSquaresProblem* LinearLeastSquaresProblem2(); LinearLeastSquaresProblem* LinearLeastSquaresProblem3(); +LinearLeastSquaresProblem* LinearLeastSquaresProblem4(); // Write the linear least squares problem to disk. The exact format // depends on dump_format_type. -bool DumpLinearLeastSquaresProblem(const string& filename_base, +bool DumpLinearLeastSquaresProblem(const std::string& filename_base, DumpFormatType dump_format_type, const SparseMatrix* A, const double* D, diff --git a/extern/libmv/third_party/ceres/internal/ceres/linear_operator.cc b/extern/libmv/third_party/ceres/internal/ceres/linear_operator.cc index 4b59fa13009..9d291bd3465 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/linear_operator.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/linear_operator.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/linear_operator.h b/extern/libmv/third_party/ceres/internal/ceres/linear_operator.h index d5c15cee6a9..6463fb5089a 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/linear_operator.h +++ b/extern/libmv/third_party/ceres/internal/ceres/linear_operator.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/linear_solver.cc b/extern/libmv/third_party/ceres/internal/ceres/linear_solver.cc index e479b751363..38e4625f747 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/linear_solver.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/linear_solver.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: 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 5f59765f074..fb9332ca6e3 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/linear_solver.h +++ b/extern/libmv/third_party/ceres/internal/ceres/linear_solver.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -144,7 +144,7 @@ class LinearSolver { // elimination group must form an independent set in the normal // equations. The first elimination group corresponds to the // num_eliminate_blocks in the Schur type solvers. - vector<int> elimination_groups; + std::vector<int> elimination_groups; // Iterative solvers, e.g. Preconditioned Conjugate Gradients // maintain a cheap estimate of the residual which may become @@ -273,7 +273,7 @@ class LinearSolver { double residual_norm; int num_iterations; LinearSolverTerminationType termination_type; - string message; + std::string message; }; // If the optimization problem is such that there are no remaining @@ -296,12 +296,12 @@ class LinearSolver { // that the base class implementation does not have to worry about // life time issues. Further, these calls are not expected to be // frequent or performance sensitive. - virtual map<string, int> CallStatistics() const { - return map<string, int>(); + virtual std::map<std::string, int> CallStatistics() const { + return std::map<std::string, int>(); } - virtual map<string, double> TimeStatistics() const { - return map<string, double>(); + virtual std::map<std::string, double> TimeStatistics() const { + return std::map<std::string, double>(); } // Factory @@ -331,11 +331,11 @@ class TypedLinearSolver : public LinearSolver { return SolveImpl(down_cast<MatrixType*>(A), b, per_solve_options, x); } - virtual map<string, int> CallStatistics() const { + virtual std::map<std::string, int> CallStatistics() const { return execution_summary_.calls(); } - virtual map<string, double> TimeStatistics() const { + virtual std::map<std::string, double> TimeStatistics() const { return execution_summary_.times(); } diff --git a/extern/libmv/third_party/ceres/internal/ceres/local_parameterization.cc b/extern/libmv/third_party/ceres/internal/ceres/local_parameterization.cc index a4832c57443..82004761ec0 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/local_parameterization.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/local_parameterization.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -30,12 +30,16 @@ #include "ceres/local_parameterization.h" +#include "ceres/householder_vector.h" #include "ceres/internal/eigen.h" +#include "ceres/internal/fixed_array.h" #include "ceres/rotation.h" #include "glog/logging.h" namespace ceres { +using std::vector; + LocalParameterization::~LocalParameterization() { } @@ -180,4 +184,162 @@ bool QuaternionParameterization::ComputeJacobian(const double* x, return true; } +HomogeneousVectorParameterization::HomogeneousVectorParameterization(int size) + : size_(size) { + CHECK_GT(size_, 1) << "The size of the homogeneous vector needs to be " + << "greater than 1."; +} + +bool HomogeneousVectorParameterization::Plus(const double* x_ptr, + const double* delta_ptr, + double* x_plus_delta_ptr) const { + ConstVectorRef x(x_ptr, size_); + ConstVectorRef delta(delta_ptr, size_ - 1); + VectorRef x_plus_delta(x_plus_delta_ptr, size_); + + const double norm_delta = delta.norm(); + + if (norm_delta == 0.0) { + x_plus_delta = x; + return true; + } + + // Map the delta from the minimum representation to the over parameterized + // homogeneous vector. See section A6.9.2 on page 624 of Hartley & Zisserman + // (2nd Edition) for a detailed description. Note there is a typo on Page + // 625, line 4 so check the book errata. + const double norm_delta_div_2 = 0.5 * norm_delta; + const double sin_delta_by_delta = sin(norm_delta_div_2) / + norm_delta_div_2; + + Vector y(size_); + y.head(size_ - 1) = 0.5 * sin_delta_by_delta * delta; + y(size_ - 1) = cos(norm_delta_div_2); + + Vector v(size_); + double beta; + internal::ComputeHouseholderVector<double>(x, &v, &beta); + + // Apply the delta update to remain on the unit sphere. See section A6.9.3 + // on page 625 of Hartley & Zisserman (2nd Edition) for a detailed + // description. + x_plus_delta = x.norm() * (y - v * (beta * (v.transpose() * y))); + + return true; +} + +bool HomogeneousVectorParameterization::ComputeJacobian( + const double* x_ptr, double* jacobian_ptr) const { + ConstVectorRef x(x_ptr, size_); + MatrixRef jacobian(jacobian_ptr, size_, size_ - 1); + + Vector v(size_); + double beta; + internal::ComputeHouseholderVector<double>(x, &v, &beta); + + // The Jacobian is equal to J = 0.5 * H.leftCols(size_ - 1) where H is the + // Householder matrix (H = I - beta * v * v'). + for (int i = 0; i < size_ - 1; ++i) { + jacobian.col(i) = -0.5 * beta * v(i) * v; + jacobian.col(i)(i) += 0.5; + } + jacobian *= x.norm(); + + return true; +} + +ProductParameterization::ProductParameterization( + LocalParameterization* local_param1, + LocalParameterization* local_param2) { + local_params_.push_back(local_param1); + local_params_.push_back(local_param2); + Init(); +} + +ProductParameterization::ProductParameterization( + LocalParameterization* local_param1, + LocalParameterization* local_param2, + LocalParameterization* local_param3) { + local_params_.push_back(local_param1); + local_params_.push_back(local_param2); + local_params_.push_back(local_param3); + Init(); +} + +ProductParameterization::ProductParameterization( + LocalParameterization* local_param1, + LocalParameterization* local_param2, + LocalParameterization* local_param3, + LocalParameterization* local_param4) { + local_params_.push_back(local_param1); + local_params_.push_back(local_param2); + local_params_.push_back(local_param3); + local_params_.push_back(local_param4); + Init(); +} + +ProductParameterization::~ProductParameterization() { + for (int i = 0; i < local_params_.size(); ++i) { + delete local_params_[i]; + } +} + +void ProductParameterization::Init() { + global_size_ = 0; + local_size_ = 0; + buffer_size_ = 0; + for (int i = 0; i < local_params_.size(); ++i) { + const LocalParameterization* param = local_params_[i]; + buffer_size_ = std::max(buffer_size_, + param->LocalSize() * param->GlobalSize()); + global_size_ += param->GlobalSize(); + local_size_ += param->LocalSize(); + } +} + +bool ProductParameterization::Plus(const double* x, + const double* delta, + double* x_plus_delta) const { + int x_cursor = 0; + int delta_cursor = 0; + for (int i = 0; i < local_params_.size(); ++i) { + const LocalParameterization* param = local_params_[i]; + if (!param->Plus(x + x_cursor, + delta + delta_cursor, + x_plus_delta + x_cursor)) { + return false; + } + delta_cursor += param->LocalSize(); + x_cursor += param->GlobalSize(); + } + + return true; +} + +bool ProductParameterization::ComputeJacobian(const double* x, + double* jacobian_ptr) const { + MatrixRef jacobian(jacobian_ptr, GlobalSize(), LocalSize()); + jacobian.setZero(); + internal::FixedArray<double> buffer(buffer_size_); + + int x_cursor = 0; + int delta_cursor = 0; + for (int i = 0; i < local_params_.size(); ++i) { + const LocalParameterization* param = local_params_[i]; + const int local_size = param->LocalSize(); + const int global_size = param->GlobalSize(); + + if (!param->ComputeJacobian(x + x_cursor, buffer.get())) { + return false; + } + + jacobian.block(x_cursor, delta_cursor, global_size, local_size) + = MatrixRef(buffer.get(), global_size, local_size); + delta_cursor += local_size; + x_cursor += global_size; + } + + return true; +} + } // namespace ceres diff --git a/extern/libmv/third_party/ceres/internal/ceres/loss_function.cc b/extern/libmv/third_party/ceres/internal/ceres/loss_function.cc index 62b545be12f..eb5026784dd 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/loss_function.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/loss_function.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -114,6 +114,22 @@ void TolerantLoss::Evaluate(double s, double rho[3]) const { } } +void TukeyLoss::Evaluate(double s, double* rho) const { + if (s <= a_squared_) { + // Inlier region. + const double value = 1.0 - s / a_squared_; + const double value_sq = value * value; + rho[0] = a_squared_ / 6.0 * (1.0 - value_sq * value); + rho[1] = 0.5 * value_sq; + rho[2] = -1.0 / a_squared_ * value; + } else { + // Outlier region. + rho[0] = a_squared_ / 6.0; + rho[1] = 0.0; + rho[2] = 0.0; + } +} + ComposedLoss::ComposedLoss(const LossFunction* f, Ownership ownership_f, const LossFunction* g, Ownership ownership_g) : f_(CHECK_NOTNULL(f)), diff --git a/extern/libmv/third_party/ceres/internal/ceres/low_rank_inverse_hessian.cc b/extern/libmv/third_party/ceres/internal/ceres/low_rank_inverse_hessian.cc index 4816e3c20f0..1c6c9925f1c 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/low_rank_inverse_hessian.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/low_rank_inverse_hessian.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -37,6 +37,8 @@ namespace ceres { namespace internal { +using std::list; + // The (L)BFGS algorithm explicitly requires that the secant equation: // // B_{k+1} * s_k = y_k @@ -126,7 +128,7 @@ void LowRankInverseHessian::RightMultiply(const double* x_ptr, const int num_corrections = indices_.size(); Vector alpha(num_corrections); - for (std::list<int>::const_reverse_iterator it = indices_.rbegin(); + for (list<int>::const_reverse_iterator it = indices_.rbegin(); it != indices_.rend(); ++it) { const double alpha_i = delta_x_history_.col(*it).dot(search_direction) / @@ -173,7 +175,7 @@ void LowRankInverseHessian::RightMultiply(const double* x_ptr, << "approximation."; } - for (std::list<int>::const_iterator it = indices_.begin(); + for (list<int>::const_iterator it = indices_.begin(); it != indices_.end(); ++it) { const double beta = delta_gradient_history_.col(*it).dot(search_direction) / diff --git a/extern/libmv/third_party/ceres/internal/ceres/low_rank_inverse_hessian.h b/extern/libmv/third_party/ceres/internal/ceres/low_rank_inverse_hessian.h index 19ab7606aa0..2c768c2ca53 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/low_rank_inverse_hessian.h +++ b/extern/libmv/third_party/ceres/internal/ceres/low_rank_inverse_hessian.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/map_util.h b/extern/libmv/third_party/ceres/internal/ceres/map_util.h index 929c6b36982..61c531f297c 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/map_util.h +++ b/extern/libmv/third_party/ceres/internal/ceres/map_util.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -87,8 +87,8 @@ bool InsertIfNotPresent( Collection * const collection, const typename Collection::value_type::first_type& key, const typename Collection::value_type::second_type& value) { - pair<typename Collection::iterator, bool> ret = - collection->insert(typename Collection::value_type(key, value)); + std::pair<typename Collection::iterator, bool> ret = + collection->insert(typename Collection::value_type(key, value)); return ret.second; } diff --git a/extern/libmv/third_party/ceres/internal/ceres/minimizer.cc b/extern/libmv/third_party/ceres/internal/ceres/minimizer.cc index 558921b8441..f5960336f12 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/minimizer.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/minimizer.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -68,7 +68,8 @@ bool Minimizer::RunCallbacks(const Minimizer::Options& options, return true; case SOLVER_TERMINATE_SUCCESSFULLY: summary->termination_type = USER_SUCCESS; - summary->message = "User callback returned SOLVER_TERMINATE_SUCCESSFULLY."; + summary->message = + "User callback returned SOLVER_TERMINATE_SUCCESSFULLY."; VLOG_IF(1, is_not_silent) << "Terminating: " << summary->message; return false; case SOLVER_ABORT: diff --git a/extern/libmv/third_party/ceres/internal/ceres/minimizer.h b/extern/libmv/third_party/ceres/internal/ceres/minimizer.h index dabf07e583a..b59372806e7 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/minimizer.h +++ b/extern/libmv/third_party/ceres/internal/ceres/minimizer.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -132,9 +132,9 @@ class Minimizer { bool jacobi_scaling; bool use_nonmonotonic_steps; int max_consecutive_nonmonotonic_steps; - vector<int> trust_region_minimizer_iterations_to_dump; + std::vector<int> trust_region_minimizer_iterations_to_dump; DumpFormatType trust_region_problem_dump_format_type; - string trust_region_problem_dump_directory; + std::string trust_region_problem_dump_directory; int max_num_consecutive_invalid_steps; double min_trust_region_radius; LineSearchDirectionType line_search_direction_type; @@ -163,7 +163,7 @@ class Minimizer { // of each iteration. // // The Options struct does not own these pointers. - vector<IterationCallback*> callbacks; + std::vector<IterationCallback*> callbacks; // Object responsible for evaluating the cost, residuals and // Jacobian matrix. diff --git a/extern/libmv/third_party/ceres/internal/ceres/mutex.h b/extern/libmv/third_party/ceres/internal/ceres/mutex.h index 97e2cd360c2..2ce97772755 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/mutex.h +++ b/extern/libmv/third_party/ceres/internal/ceres/mutex.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/normal_prior.cc b/extern/libmv/third_party/ceres/internal/ceres/normal_prior.cc index 392d728fb32..b3666cd702f 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/normal_prior.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/normal_prior.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/parameter_block.h b/extern/libmv/third_party/ceres/internal/ceres/parameter_block.h index 7bc823d4ec6..cb7140d9582 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/parameter_block.h +++ b/extern/libmv/third_party/ceres/internal/ceres/parameter_block.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -193,7 +193,7 @@ class ParameterBlock { } upper_bounds_[index] = upper_bound; - }; + } void SetLowerBound(int index, double lower_bound) { CHECK_LT(index, size_); @@ -237,10 +237,11 @@ class ParameterBlock { return true; } - string ToString() const { - return StringPrintf("{ user_state=%p, state=%p, size=%d, " + std::string ToString() const { + return StringPrintf("{ this=%p, user_state=%p, state=%p, size=%d, " "constant=%d, index=%d, state_offset=%d, " "delta_offset=%d }", + this, user_state_, state_, size_, diff --git a/extern/libmv/third_party/ceres/internal/ceres/parameter_block_ordering.cc b/extern/libmv/third_party/ceres/internal/ceres/parameter_block_ordering.cc index 1525de90d60..efba339977c 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/parameter_block_ordering.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/parameter_block_ordering.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -43,6 +43,10 @@ namespace ceres { namespace internal { +using std::map; +using std::set; +using std::vector; + int ComputeStableSchurOrdering(const Program& program, vector<ParameterBlock*>* ordering) { CHECK_NOTNULL(ordering)->clear(); diff --git a/extern/libmv/third_party/ceres/internal/ceres/parameter_block_ordering.h b/extern/libmv/third_party/ceres/internal/ceres/parameter_block_ordering.h index 5de99511138..f996929f6b3 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/parameter_block_ordering.h +++ b/extern/libmv/third_party/ceres/internal/ceres/parameter_block_ordering.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -56,13 +56,13 @@ class ParameterBlock; // complement of the independent set, // fixed blocks] int ComputeSchurOrdering(const Program& program, - vector<ParameterBlock* >* ordering); + std::vector<ParameterBlock* >* ordering); // Same as above, except that ties while computing the independent set // ordering are resolved in favour of the order in which the parameter // blocks occur in the program. int ComputeStableSchurOrdering(const Program& program, - vector<ParameterBlock* >* ordering); + std::vector<ParameterBlock* >* ordering); // Use an approximate independent set ordering to decompose the // parameter blocks of a problem in a sequence of independent @@ -81,7 +81,7 @@ Graph<ParameterBlock*>* CreateHessianGraph(const Program& program); // Iterate over each of the groups in order of their priority and fill // summary with their sizes. void OrderingToGroupSizes(const ParameterBlockOrdering* ordering, - vector<int>* group_sizes); + std::vector<int>* group_sizes); } // namespace internal } // namespace ceres diff --git a/extern/libmv/third_party/ceres/internal/ceres/partitioned_matrix_view.cc b/extern/libmv/third_party/ceres/internal/ceres/partitioned_matrix_view.cc index d745a9b358d..8054964e039 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/partitioned_matrix_view.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/partitioned_matrix_view.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -89,6 +89,12 @@ PartitionedMatrixViewBase::Create(const LinearSolver::Options& options, } if ((options.row_block_size == 2) && (options.e_block_size == 3) && + (options.f_block_size == 6)) { + return new PartitionedMatrixView<2, 3, 6>( + matrix, options.elimination_groups[0]); + } + if ((options.row_block_size == 2) && + (options.e_block_size == 3) && (options.f_block_size == 9)) { return new PartitionedMatrixView<2, 3, 9>( matrix, options.elimination_groups[0]); diff --git a/extern/libmv/third_party/ceres/internal/ceres/partitioned_matrix_view.h b/extern/libmv/third_party/ceres/internal/ceres/partitioned_matrix_view.h index 661252d404f..6e75060a47e 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/partitioned_matrix_view.h +++ b/extern/libmv/third_party/ceres/internal/ceres/partitioned_matrix_view.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/partitioned_matrix_view_impl.h b/extern/libmv/third_party/ceres/internal/ceres/partitioned_matrix_view_impl.h index ae7f776e6b1..86fb278fa27 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/partitioned_matrix_view_impl.h +++ b/extern/libmv/third_party/ceres/internal/ceres/partitioned_matrix_view_impl.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -61,7 +61,7 @@ PartitionedMatrixView( // explicit_schur_complement_solver.h num_row_blocks_e_ = 0; for (int r = 0; r < bs->rows.size(); ++r) { - const vector<Cell>& cells = bs->rows[r].cells; + const std::vector<Cell>& cells = bs->rows[r].cells; if (cells[0].block_id < num_col_blocks_e_) { ++num_row_blocks_e_; } @@ -131,7 +131,7 @@ RightMultiplyF(const double* x, double* y) const { for (int r = 0; r < num_row_blocks_e_; ++r) { const int row_block_pos = bs->rows[r].block.position; const int row_block_size = bs->rows[r].block.size; - const vector<Cell>& cells = bs->rows[r].cells; + const std::vector<Cell>& cells = bs->rows[r].cells; for (int c = 1; c < cells.size(); ++c) { const int col_block_id = cells[c].block_id; const int col_block_pos = bs->cols[col_block_id].position; @@ -146,7 +146,7 @@ RightMultiplyF(const double* x, double* y) const { for (int r = num_row_blocks_e_; r < bs->rows.size(); ++r) { const int row_block_pos = bs->rows[r].block.position; const int row_block_size = bs->rows[r].block.size; - const vector<Cell>& cells = bs->rows[r].cells; + const std::vector<Cell>& cells = bs->rows[r].cells; for (int c = 0; c < cells.size(); ++c) { const int col_block_id = cells[c].block_id; const int col_block_pos = bs->cols[col_block_id].position; @@ -197,7 +197,7 @@ LeftMultiplyF(const double* x, double* y) const { for (int r = 0; r < num_row_blocks_e_; ++r) { const int row_block_pos = bs->rows[r].block.position; const int row_block_size = bs->rows[r].block.size; - const vector<Cell>& cells = bs->rows[r].cells; + const std::vector<Cell>& cells = bs->rows[r].cells; for (int c = 1; c < cells.size(); ++c) { const int col_block_id = cells[c].block_id; const int col_block_pos = bs->cols[col_block_id].position; @@ -212,7 +212,7 @@ LeftMultiplyF(const double* x, double* y) const { for (int r = num_row_blocks_e_; r < bs->rows.size(); ++r) { const int row_block_pos = bs->rows[r].block.position; const int row_block_size = bs->rows[r].block.size; - const vector<Cell>& cells = bs->rows[r].cells; + const std::vector<Cell>& cells = bs->rows[r].cells; for (int c = 0; c < cells.size(); ++c) { const int col_block_id = cells[c].block_id; const int col_block_pos = bs->cols[col_block_id].position; @@ -339,7 +339,7 @@ UpdateBlockDiagonalFtF(BlockSparseMatrix* block_diagonal) const { const double* values = matrix_.values(); for (int r = 0; r < num_row_blocks_e_; ++r) { const int row_block_size = bs->rows[r].block.size; - const vector<Cell>& cells = bs->rows[r].cells; + const std::vector<Cell>& cells = bs->rows[r].cells; for (int c = 1; c < cells.size(); ++c) { const int col_block_id = cells[c].block_id; const int col_block_size = bs->cols[col_block_id].size; @@ -358,7 +358,7 @@ UpdateBlockDiagonalFtF(BlockSparseMatrix* block_diagonal) const { for (int r = num_row_blocks_e_; r < bs->rows.size(); ++r) { const int row_block_size = bs->rows[r].block.size; - const vector<Cell>& cells = bs->rows[r].cells; + const std::vector<Cell>& cells = bs->rows[r].cells; for (int c = 0; c < cells.size(); ++c) { const int col_block_id = cells[c].block_id; const int col_block_size = bs->cols[col_block_id].size; diff --git a/extern/libmv/third_party/ceres/internal/ceres/polynomial.cc b/extern/libmv/third_party/ceres/internal/ceres/polynomial.cc index 75f43de409a..13bf8edeee6 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/polynomial.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/polynomial.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -42,6 +42,10 @@ namespace ceres { namespace internal { + +using std::string; +using std::vector; + namespace { // Balancing function as described by B. N. Parlett and C. Reinsch, diff --git a/extern/libmv/third_party/ceres/internal/ceres/polynomial.h b/extern/libmv/third_party/ceres/internal/ceres/polynomial.h index 80ce77e6ae1..09a64c577f5 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/polynomial.h +++ b/extern/libmv/third_party/ceres/internal/ceres/polynomial.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -32,6 +32,7 @@ #ifndef CERES_INTERNAL_POLYNOMIAL_SOLVER_H_ #define CERES_INTERNAL_POLYNOMIAL_SOLVER_H_ +#include <string> #include <vector> #include "ceres/internal/eigen.h" #include "ceres/internal/port.h" @@ -95,7 +96,7 @@ struct FunctionSample { gradient(0.0), gradient_is_valid(false) { } - string ToDebugString() const; + std::string ToDebugString() const; double x; double value; // value = f(x) @@ -115,7 +116,7 @@ struct FunctionSample { // Of course its possible to sample a polynomial any number of times, // in which case, generally speaking the spurious higher order // coefficients will be zero. -Vector FindInterpolatingPolynomial(const vector<FunctionSample>& samples); +Vector FindInterpolatingPolynomial(const std::vector<FunctionSample>& samples); // Interpolate the function described by samples with a polynomial, // and minimize it on the interval [x_min, x_max]. Depending on the @@ -123,7 +124,7 @@ Vector FindInterpolatingPolynomial(const vector<FunctionSample>& samples); // finding algorithms may fail due to numerical difficulties. But the // function is guaranteed to return its best guess of an answer, by // considering the samples and the end points as possible solutions. -void MinimizeInterpolatingPolynomial(const vector<FunctionSample>& samples, +void MinimizeInterpolatingPolynomial(const std::vector<FunctionSample>& samples, double x_min, double x_max, double* optimal_x, diff --git a/extern/libmv/third_party/ceres/internal/ceres/preconditioner.cc b/extern/libmv/third_party/ceres/internal/ceres/preconditioner.cc index 062347fccc1..82621dae50c 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/preconditioner.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/preconditioner.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/preconditioner.h b/extern/libmv/third_party/ceres/internal/ceres/preconditioner.h index e8d5994269a..a248eae060d 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/preconditioner.h +++ b/extern/libmv/third_party/ceres/internal/ceres/preconditioner.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -80,7 +80,7 @@ class Preconditioner : public LinearOperator { // elimination group must form an independent set in the normal // equations. The first elimination group corresponds to the // num_eliminate_blocks in the Schur type solvers. - vector<int> elimination_groups; + std::vector<int> elimination_groups; // If the block sizes in a BlockSparseMatrix are fixed, then in // some cases the Schur complement based solvers can detect and diff --git a/extern/libmv/third_party/ceres/internal/ceres/preprocessor.cc b/extern/libmv/third_party/ceres/internal/ceres/preprocessor.cc index 318c5e2ebef..4aba6a39ce8 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/preprocessor.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/preprocessor.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/preprocessor.h b/extern/libmv/third_party/ceres/internal/ceres/preprocessor.h index b4ca5b11747..ff53d6f0d3f 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/preprocessor.h +++ b/extern/libmv/third_party/ceres/internal/ceres/preprocessor.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -31,6 +31,9 @@ #ifndef CERES_INTERNAL_PREPROCESSOR_H_ #define CERES_INTERNAL_PREPROCESSOR_H_ +#include <string> +#include <vector> + #include "ceres/coordinate_descent_minimizer.h" #include "ceres/evaluator.h" #include "ceres/internal/eigen.h" @@ -65,7 +68,7 @@ struct PreprocessedProblem; // The output of the Preprocessor is stored in a PreprocessedProblem // object. class Preprocessor { -public: + public: // Factory. static Preprocessor* Create(MinimizerType minimizer_type); virtual ~Preprocessor(); @@ -81,7 +84,7 @@ struct PreprocessedProblem { : fixed_cost(0.0) { } - string error; + std::string error; Solver::Options options; LinearSolver::Options linear_solver_options; Evaluator::Options evaluator_options; @@ -97,7 +100,7 @@ struct PreprocessedProblem { shared_ptr<Evaluator> evaluator; shared_ptr<CoordinateDescentMinimizer> inner_iteration_minimizer; - vector<double*> removed_parameter_blocks; + std::vector<double*> removed_parameter_blocks; Vector reduced_parameters; double fixed_cost; }; diff --git a/extern/libmv/third_party/ceres/internal/ceres/problem.cc b/extern/libmv/third_party/ceres/internal/ceres/problem.cc index bbfaa98769f..03b7d6afa48 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/problem.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/problem.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -37,6 +37,8 @@ namespace ceres { +using std::vector; + Problem::Problem() : problem_impl_(new internal::ProblemImpl) {} Problem::Problem(const Problem::Options& options) : problem_impl_(new internal::ProblemImpl(options)) {} @@ -225,11 +227,11 @@ int Problem::NumResiduals() const { int Problem::ParameterBlockSize(const double* parameter_block) const { return problem_impl_->ParameterBlockSize(parameter_block); -}; +} int Problem::ParameterBlockLocalSize(const double* parameter_block) const { return problem_impl_->ParameterBlockLocalSize(parameter_block); -}; +} bool Problem::HasParameterBlock(const double* values) const { return problem_impl_->HasParameterBlock(values); 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 67cac94d6ac..8547d5d3f77 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/problem_impl.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/problem_impl.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -55,18 +55,12 @@ namespace ceres { namespace internal { -typedef map<double*, internal::ParameterBlock*> ParameterMap; +using std::map; +using std::string; +using std::vector; +typedef std::map<double*, internal::ParameterBlock*> ParameterMap; namespace { -internal::ParameterBlock* FindParameterBlockOrDie( - const ParameterMap& parameter_map, - double* parameter_block) { - ParameterMap::const_iterator it = parameter_map.find(parameter_block); - CHECK(it != parameter_map.end()) - << "Parameter block not found: " << parameter_block; - return it->second; -} - // Returns true if two regions of memory, a and b, with sizes size_a and size_b // respectively, overlap. bool RegionsAlias(const double* a, int size_a, @@ -530,7 +524,12 @@ void ProblemImpl::RemoveResidualBlock(ResidualBlock* residual_block) { void ProblemImpl::RemoveParameterBlock(double* values) { ParameterBlock* parameter_block = - FindParameterBlockOrDie(parameter_block_map_, values); + FindWithDefault(parameter_block_map_, values, NULL); + if (parameter_block == NULL) { + LOG(FATAL) << "Parameter block not found: " << values + << ". You must add the parameter block to the problem before " + << "it can be removed."; + } if (options_.enable_fast_removal) { // Copy the dependent residuals from the parameter block because the set of @@ -562,38 +561,81 @@ void ProblemImpl::RemoveParameterBlock(double* values) { } void ProblemImpl::SetParameterBlockConstant(double* values) { - FindParameterBlockOrDie(parameter_block_map_, values)->SetConstant(); + ParameterBlock* parameter_block = + FindWithDefault(parameter_block_map_, values, NULL); + if (parameter_block == NULL) { + LOG(FATAL) << "Parameter block not found: " << values + << ". You must add the parameter block to the problem before " + << "it can be set constant."; + } + + parameter_block->SetConstant(); } void ProblemImpl::SetParameterBlockVariable(double* values) { - FindParameterBlockOrDie(parameter_block_map_, values)->SetVarying(); + ParameterBlock* parameter_block = + FindWithDefault(parameter_block_map_, values, NULL); + if (parameter_block == NULL) { + LOG(FATAL) << "Parameter block not found: " << values + << ". You must add the parameter block to the problem before " + << "it can be set varying."; + } + + parameter_block->SetVarying(); } void ProblemImpl::SetParameterization( double* values, LocalParameterization* local_parameterization) { - FindParameterBlockOrDie(parameter_block_map_, values) - ->SetParameterization(local_parameterization); + ParameterBlock* parameter_block = + FindWithDefault(parameter_block_map_, values, NULL); + if (parameter_block == NULL) { + LOG(FATAL) << "Parameter block not found: " << values + << ". You must add the parameter block to the problem before " + << "you can set its local parameterization."; + } + + parameter_block->SetParameterization(local_parameterization); } const LocalParameterization* ProblemImpl::GetParameterization( double* values) const { - return FindParameterBlockOrDie(parameter_block_map_, values) - ->local_parameterization(); + ParameterBlock* parameter_block = + FindWithDefault(parameter_block_map_, values, NULL); + if (parameter_block == NULL) { + LOG(FATAL) << "Parameter block not found: " << values + << ". You must add the parameter block to the problem before " + << "you can get its local parameterization."; + } + + return parameter_block->local_parameterization(); } void ProblemImpl::SetParameterLowerBound(double* values, int index, double lower_bound) { - FindParameterBlockOrDie(parameter_block_map_, values) - ->SetLowerBound(index, lower_bound); + ParameterBlock* parameter_block = + FindWithDefault(parameter_block_map_, values, NULL); + if (parameter_block == NULL) { + LOG(FATAL) << "Parameter block not found: " << values + << ". You must add the parameter block to the problem before " + << "you can set a lower bound on one of its components."; + } + + parameter_block->SetLowerBound(index, lower_bound); } void ProblemImpl::SetParameterUpperBound(double* values, int index, double upper_bound) { - FindParameterBlockOrDie(parameter_block_map_, values) - ->SetUpperBound(index, upper_bound); + ParameterBlock* parameter_block = + FindWithDefault(parameter_block_map_, values, NULL); + if (parameter_block == NULL) { + LOG(FATAL) << "Parameter block not found: " << values + << ". You must add the parameter block to the problem before " + << "you can set an upper bound on one of its components."; + } + parameter_block->SetUpperBound(index, upper_bound); } bool ProblemImpl::Evaluate(const Problem::EvaluateOptions& evaluate_options, @@ -635,9 +677,14 @@ bool ProblemImpl::Evaluate(const Problem::EvaluateOptions& evaluate_options, // 1. Convert double* into ParameterBlock* parameter_blocks.resize(parameter_block_ptrs.size()); for (int i = 0; i < parameter_block_ptrs.size(); ++i) { - parameter_blocks[i] = - FindParameterBlockOrDie(parameter_block_map_, - parameter_block_ptrs[i]); + parameter_blocks[i] = FindWithDefault(parameter_block_map_, + parameter_block_ptrs[i], + NULL); + if (parameter_blocks[i] == NULL) { + LOG(FATAL) << "No known parameter block for " + << "Problem::Evaluate::Options.parameter_blocks[" << i << "]" + << " = " << parameter_block_ptrs[i]; + } } // 2. The user may have only supplied a subset of parameter @@ -684,7 +731,15 @@ bool ProblemImpl::Evaluate(const Problem::EvaluateOptions& evaluate_options, // the Evaluator decides the storage for the Jacobian based on the // type of linear solver being used. evaluator_options.linear_solver_type = SPARSE_NORMAL_CHOLESKY; +#ifndef CERES_USE_OPENMP + LOG_IF(WARNING, evaluate_options.num_threads > 1) + << "OpenMP support is not compiled into this binary; " + << "only evaluate_options.num_threads = 1 is supported. Switching " + << "to single threaded mode."; + evaluator_options.num_threads = 1; +#else evaluator_options.num_threads = evaluate_options.num_threads; +#endif // CERES_USE_OPENMP string error; scoped_ptr<Evaluator> evaluator( @@ -781,15 +836,29 @@ int ProblemImpl::NumResiduals() const { return program_->NumResiduals(); } -int ProblemImpl::ParameterBlockSize(const double* parameter_block) const { - return FindParameterBlockOrDie(parameter_block_map_, - const_cast<double*>(parameter_block))->Size(); -}; +int ProblemImpl::ParameterBlockSize(const double* values) const { + ParameterBlock* parameter_block = + FindWithDefault(parameter_block_map_, const_cast<double*>(values), NULL); + if (parameter_block == NULL) { + LOG(FATAL) << "Parameter block not found: " << values + << ". You must add the parameter block to the problem before " + << "you can get its size."; + } -int ProblemImpl::ParameterBlockLocalSize(const double* parameter_block) const { - return FindParameterBlockOrDie( - parameter_block_map_, const_cast<double*>(parameter_block))->LocalSize(); -}; + return parameter_block->Size(); +} + +int ProblemImpl::ParameterBlockLocalSize(const double* values) const { + ParameterBlock* parameter_block = + FindWithDefault(parameter_block_map_, const_cast<double*>(values), NULL); + if (parameter_block == NULL) { + LOG(FATAL) << "Parameter block not found: " << values + << ". You must add the parameter block to the problem before " + << "you can get its local size."; + } + + return parameter_block->LocalSize(); +} bool ProblemImpl::HasParameterBlock(const double* parameter_block) const { return (parameter_block_map_.find(const_cast<double*>(parameter_block)) != @@ -837,8 +906,12 @@ void ProblemImpl::GetResidualBlocksForParameterBlock( const double* values, vector<ResidualBlockId>* residual_blocks) const { ParameterBlock* parameter_block = - FindParameterBlockOrDie(parameter_block_map_, - const_cast<double*>(values)); + FindWithDefault(parameter_block_map_, const_cast<double*>(values), NULL); + if (parameter_block == NULL) { + LOG(FATAL) << "Parameter block not found: " << values + << ". You must add the parameter block to the problem before " + << "you can get the residual blocks that depend on it."; + } if (options_.enable_fast_removal) { // In this case the residual blocks that depend on the parameter block are diff --git a/extern/libmv/third_party/ceres/internal/ceres/problem_impl.h b/extern/libmv/third_party/ceres/internal/ceres/problem_impl.h index 3d84de83c5a..f42bde6c793 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/problem_impl.h +++ b/extern/libmv/third_party/ceres/internal/ceres/problem_impl.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -63,7 +63,7 @@ class ResidualBlock; class ProblemImpl { public: - typedef map<double*, ParameterBlock*> ParameterMap; + typedef std::map<double*, ParameterBlock*> ParameterMap; typedef HashSet<ResidualBlock*> ResidualBlockSet; ProblemImpl(); @@ -72,9 +72,10 @@ class ProblemImpl { ~ProblemImpl(); // See the public problem.h file for description of these methods. - ResidualBlockId AddResidualBlock(CostFunction* cost_function, - LossFunction* loss_function, - const vector<double*>& parameter_blocks); + ResidualBlockId AddResidualBlock( + CostFunction* cost_function, + LossFunction* loss_function, + const std::vector<double*>& parameter_blocks); ResidualBlockId AddResidualBlock(CostFunction* cost_function, LossFunction* loss_function, double* x0); @@ -136,8 +137,8 @@ class ProblemImpl { bool Evaluate(const Problem::EvaluateOptions& options, double* cost, - vector<double>* residuals, - vector<double>* gradient, + std::vector<double>* residuals, + std::vector<double>* gradient, CRSMatrix* jacobian); int NumParameterBlocks() const; @@ -150,12 +151,12 @@ class ProblemImpl { bool HasParameterBlock(const double* parameter_block) const; - void GetParameterBlocks(vector<double*>* parameter_blocks) const; - void GetResidualBlocks(vector<ResidualBlockId>* residual_blocks) const; + void GetParameterBlocks(std::vector<double*>* parameter_blocks) const; + void GetResidualBlocks(std::vector<ResidualBlockId>* residual_blocks) const; void GetParameterBlocksForResidualBlock( const ResidualBlockId residual_block, - vector<double*>* parameter_blocks) const; + std::vector<double*>* parameter_blocks) const; const CostFunction* GetCostFunctionForResidualBlock( const ResidualBlockId residual_block) const; @@ -164,7 +165,7 @@ class ProblemImpl { void GetResidualBlocksForParameterBlock( const double* values, - vector<ResidualBlockId>* residual_blocks) const; + std::vector<ResidualBlockId>* residual_blocks) const; const Program& program() const { return *program_; } Program* mutable_program() { return program_.get(); } @@ -182,15 +183,15 @@ class ProblemImpl { bool InternalEvaluate(Program* program, double* cost, - vector<double>* residuals, - vector<double>* gradient, + std::vector<double>* residuals, + std::vector<double>* gradient, CRSMatrix* jacobian); // Delete the arguments in question. These differ from the Remove* functions // in that they do not clean up references to the block to delete; they // merely delete them. template<typename Block> - void DeleteBlockInVector(vector<Block*>* mutable_blocks, + void DeleteBlockInVector(std::vector<Block*>* mutable_blocks, Block* block_to_remove); void DeleteBlock(ResidualBlock* residual_block); void DeleteBlock(ParameterBlock* parameter_block); @@ -198,7 +199,7 @@ class ProblemImpl { const Problem::Options options_; // The mapping from user pointers to parameter blocks. - map<double*, ParameterBlock*> parameter_block_map_; + std::map<double*, ParameterBlock*> parameter_block_map_; // Iff enable_fast_removal is enabled, contains the current residual blocks. ResidualBlockSet residual_block_set_; @@ -212,9 +213,9 @@ class ProblemImpl { // residual or parameter blocks, buffer them until destruction. // // TODO(keir): See if it makes sense to use sets instead. - vector<CostFunction*> cost_functions_to_delete_; - vector<LossFunction*> loss_functions_to_delete_; - vector<LocalParameterization*> local_parameterizations_to_delete_; + std::vector<CostFunction*> cost_functions_to_delete_; + std::vector<LossFunction*> loss_functions_to_delete_; + std::vector<LocalParameterization*> local_parameterizations_to_delete_; CERES_DISALLOW_COPY_AND_ASSIGN(ProblemImpl); }; diff --git a/extern/libmv/third_party/ceres/internal/ceres/program.cc b/extern/libmv/third_party/ceres/internal/ceres/program.cc index 1d0a1573e3b..8e97f072113 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/program.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/program.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -50,6 +50,11 @@ namespace ceres { namespace internal { +using std::max; +using std::set; +using std::string; +using std::vector; + Program::Program() {} Program::Program(const Program& program) @@ -261,9 +266,10 @@ bool Program::IsFeasible(string* message) const { return true; } -Program* Program::CreateReducedProgram(vector<double*>* removed_parameter_blocks, - double* fixed_cost, - string* error) const { +Program* Program::CreateReducedProgram( + vector<double*>* removed_parameter_blocks, + double* fixed_cost, + string* error) const { CHECK_NOTNULL(removed_parameter_blocks); CHECK_NOTNULL(fixed_cost); CHECK_NOTNULL(error); @@ -342,7 +348,8 @@ bool Program::RemoveFixedBlocks(vector<double*>* removed_parameter_blocks, for (int i = 0; i < parameter_blocks_.size(); ++i) { ParameterBlock* parameter_block = parameter_blocks_[i]; if (parameter_block->index() == -1) { - removed_parameter_blocks->push_back(parameter_block->mutable_user_state()); + removed_parameter_blocks->push_back( + parameter_block->mutable_user_state()); } else { parameter_blocks_[num_active_parameter_blocks++] = parameter_block; } @@ -360,7 +367,8 @@ bool Program::RemoveFixedBlocks(vector<double*>* removed_parameter_blocks, return true; } -bool Program::IsParameterBlockSetIndependent(const set<double*>& independent_set) const { +bool Program::IsParameterBlockSetIndependent( + const set<double*>& independent_set) const { // Loop over each residual block and ensure that no two parameter // blocks in the same residual block are part of // parameter_block_ptrs as that would violate the assumption that it @@ -495,8 +503,7 @@ int Program::MaxParametersPerResidualBlock() const { int Program::MaxResidualsPerResidualBlock() const { int max_residuals = 0; for (int i = 0; i < residual_blocks_.size(); ++i) { - max_residuals = max(max_residuals, - residual_blocks_[i]->NumResiduals()); + max_residuals = max(max_residuals, residual_blocks_[i]->NumResiduals()); } return max_residuals; } diff --git a/extern/libmv/third_party/ceres/internal/ceres/program.h b/extern/libmv/third_party/ceres/internal/ceres/program.h index c7b22c4d244..38c958fe34a 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/program.h +++ b/extern/libmv/third_party/ceres/internal/ceres/program.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -60,10 +60,10 @@ class Program { explicit Program(const Program& program); // The ordered parameter and residual blocks for the program. - const vector<ParameterBlock*>& parameter_blocks() const; - const vector<ResidualBlock*>& residual_blocks() const; - vector<ParameterBlock*>* mutable_parameter_blocks(); - vector<ResidualBlock*>* mutable_residual_blocks(); + const std::vector<ParameterBlock*>& parameter_blocks() const; + const std::vector<ResidualBlock*>& residual_blocks() const; + std::vector<ParameterBlock*>* mutable_parameter_blocks(); + std::vector<ResidualBlock*>* mutable_residual_blocks(); // Serialize to/from the program and update states. // @@ -105,7 +105,7 @@ class Program { // offsets) are correct. bool IsValid() const; - bool ParameterBlocksAreFinite(string* message) const; + bool ParameterBlocksAreFinite(std::string* message) const; // Returns true if the program has any non-constant parameter blocks // which have non-trivial bounds constraints. @@ -114,13 +114,14 @@ class Program { // Returns false, if the program has any constant parameter blocks // which are not feasible, or any variable parameter blocks which // have a lower bound greater than or equal to the upper bound. - bool IsFeasible(string* message) const; + bool IsFeasible(std::string* message) const; // Loop over each residual block and ensure that no two parameter // blocks in the same residual block are part of // parameter_blocks as that would violate the assumption that it // is an independent set in the Hessian matrix. - bool IsParameterBlockSetIndependent(const set<double*>& independent_set) const; + bool IsParameterBlockSetIndependent( + const std::set<double*>& independent_set) const; // Create a TripletSparseMatrix which contains the zero-one // structure corresponding to the block sparsity of the transpose of @@ -142,9 +143,9 @@ class Program { // If there was a problem, then the function will return a NULL // pointer and error will contain a human readable description of // the problem. - Program* CreateReducedProgram(vector<double*>* removed_parameter_blocks, + Program* CreateReducedProgram(std::vector<double*>* removed_parameter_blocks, double* fixed_cost, - string* error) const; + std::string* error) const; // See problem.h for what these do. int NumParameterBlocks() const; @@ -160,7 +161,7 @@ class Program { // A human-readable dump of the parameter blocks for debugging. // TODO(keir): If necessary, also dump the residual blocks. - string ToString() const; + std::string ToString() const; private: // Remove constant parameter blocks and residual blocks with no @@ -174,13 +175,13 @@ class Program { // // If there was a problem, then the function will return false and // error will contain a human readable description of the problem. - bool RemoveFixedBlocks(vector<double*>* removed_parameter_blocks, + bool RemoveFixedBlocks(std::vector<double*>* removed_parameter_blocks, double* fixed_cost, - string* message); + std::string* message); // The Program does not own the ParameterBlock or ResidualBlock objects. - vector<ParameterBlock*> parameter_blocks_; - vector<ResidualBlock*> residual_blocks_; + std::vector<ParameterBlock*> parameter_blocks_; + std::vector<ResidualBlock*> residual_blocks_; friend class ProblemImpl; }; 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 672c233b379..74a812adeef 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/program_evaluator.h +++ b/extern/libmv/third_party/ceres/internal/ceres/program_evaluator.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -116,9 +116,13 @@ class ProgramEvaluator : public Evaluator { evaluate_preparers_( jacobian_writer_.CreateEvaluatePreparers(options.num_threads)) { #ifndef CERES_USE_OPENMP - CHECK_EQ(1, options_.num_threads) - << "OpenMP support is not compiled into this binary; " - << "only options.num_threads=1 is supported."; + if (options_.num_threads > 1) { + LOG(WARNING) + << "OpenMP support is not compiled into this binary; " + << "only options.num_threads = 1 is supported. Switching " + << "to single threaded mode."; + options_.num_threads = 1; + } #endif BuildResidualLayout(*program, &residual_layout_); @@ -297,11 +301,11 @@ class ProgramEvaluator : public Evaluator { return program_->NumResiduals(); } - virtual map<string, int> CallStatistics() const { + virtual std::map<std::string, int> CallStatistics() const { return execution_summary_.calls(); } - virtual map<string, double> TimeStatistics() const { + virtual std::map<std::string, double> TimeStatistics() const { return execution_summary_.times(); } @@ -332,8 +336,9 @@ class ProgramEvaluator : public Evaluator { }; static void BuildResidualLayout(const Program& program, - vector<int>* residual_layout) { - const vector<ResidualBlock*>& residual_blocks = program.residual_blocks(); + std::vector<int>* residual_layout) { + const std::vector<ResidualBlock*>& residual_blocks = + program.residual_blocks(); residual_layout->resize(program.NumResidualBlocks()); int residual_pos = 0; for (int i = 0; i < residual_blocks.size(); ++i) { @@ -369,7 +374,7 @@ class ProgramEvaluator : public Evaluator { JacobianWriter jacobian_writer_; scoped_array<EvaluatePreparer> evaluate_preparers_; scoped_array<EvaluateScratch> evaluate_scratch_; - vector<int> residual_layout_; + std::vector<int> residual_layout_; ::ceres::internal::ExecutionSummary execution_summary_; }; diff --git a/extern/libmv/third_party/ceres/internal/ceres/random.h b/extern/libmv/third_party/ceres/internal/ceres/random.h index 352c0032b5a..2a025600609 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/random.h +++ b/extern/libmv/third_party/ceres/internal/ceres/random.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/reorder_program.cc b/extern/libmv/third_party/ceres/internal/ceres/reorder_program.cc index aa3d4cec396..d0e8f32b3b7 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/reorder_program.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/reorder_program.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -56,6 +56,12 @@ namespace ceres { namespace internal { + +using std::map; +using std::set; +using std::string; +using std::vector; + namespace { // Find the minimum index of any parameter block to the given @@ -87,7 +93,7 @@ Eigen::SparseMatrix<int> CreateBlockJacobian( const int* rows = block_jacobian_transpose.rows(); const int* cols = block_jacobian_transpose.cols(); int num_nonzeros = block_jacobian_transpose.num_nonzeros(); - std::vector<Triplet> triplets; + vector<Triplet> triplets; triplets.reserve(num_nonzeros); for (int i = 0; i < num_nonzeros; ++i) { triplets.push_back(Triplet(cols[i], rows[i], 1)); @@ -126,6 +132,11 @@ void OrderingForSparseNormalCholeskyUsingSuiteSparse( parameter_block_ordering.GroupId( parameter_blocks[i]->mutable_user_state())); } + + // Renumber the entries of constraints to be contiguous integers + // as CAMD requires that the group ids be in the range [0, + // parameter_blocks.size() - 1]. + MapValuesToContiguousRange(constraints.size(), &constraints[0]); ss.ConstrainedApproximateMinimumDegreeOrdering(block_jacobian_transpose, &constraints[0], ordering); @@ -217,9 +228,7 @@ bool ApplyOrdering(const ProblemImpl::ParameterMap& parameter_map, program->mutable_parameter_blocks(); parameter_blocks->clear(); - const map<int, set<double*> >& groups = - ordering.group_to_elements(); - + const map<int, set<double*> >& groups = ordering.group_to_elements(); for (map<int, set<double*> >::const_iterator group_it = groups.begin(); group_it != groups.end(); ++group_it) { @@ -344,8 +353,8 @@ void MaybeReorderSchurComplementColumnsUsingSuiteSparse( parameter_blocks[i]->mutable_user_state())); } - // Renumber the entries of constraints to be contiguous integers - // as camd requires that the group ids be in the range [0, + // Renumber the entries of constraints to be contiguous integers as + // CAMD requires that the group ids be in the range [0, // parameter_blocks.size() - 1]. MapValuesToContiguousRange(constraints.size(), &constraints[0]); @@ -531,6 +540,15 @@ bool ReorderProgramForSparseNormalCholesky( const ParameterBlockOrdering& parameter_block_ordering, Program* program, string* error) { + if (parameter_block_ordering.NumElements() != program->NumParameterBlocks()) { + *error = StringPrintf( + "The program has %d parameter blocks, but the parameter block " + "ordering has %d parameter blocks.", + program->NumParameterBlocks(), + parameter_block_ordering.NumElements()); + return false; + } + // Compute a block sparse presentation of J'. scoped_ptr<TripletSparseMatrix> tsm_block_jacobian_transpose( program->CreateJacobianBlockSparsityTranspose()); diff --git a/extern/libmv/third_party/ceres/internal/ceres/reorder_program.h b/extern/libmv/third_party/ceres/internal/ceres/reorder_program.h index 0474c1fb912..36e5d1637a9 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/reorder_program.h +++ b/extern/libmv/third_party/ceres/internal/ceres/reorder_program.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -46,14 +46,14 @@ class Program; bool ApplyOrdering(const ProblemImpl::ParameterMap& parameter_map, const ParameterBlockOrdering& ordering, Program* program, - string* error); + std::string* error); // Reorder the residuals for program, if necessary, so that the residuals // involving each E block occur together. This is a necessary condition for the // Schur eliminator, which works on these "row blocks" in the jacobian. bool LexicographicallyOrderResidualBlocks(int size_of_first_elimination_group, Program* program, - string* error); + std::string* error); // Schur type solvers require that all parameter blocks eliminated // by the Schur eliminator occur before others and the residuals be @@ -77,7 +77,7 @@ bool ReorderProgramForSchurTypeLinearSolver( const ProblemImpl::ParameterMap& parameter_map, ParameterBlockOrdering* parameter_block_ordering, Program* program, - string* error); + std::string* error); // Sparse cholesky factorization routines when doing the sparse // cholesky factorization of the Jacobian matrix, reorders its @@ -93,7 +93,7 @@ bool ReorderProgramForSparseNormalCholesky( SparseLinearAlgebraLibraryType sparse_linear_algebra_library_type, const ParameterBlockOrdering& parameter_block_ordering, Program* program, - string* error); + std::string* error); } // namespace internal } // namespace ceres 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 621082ac0ea..9a123cf132e 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/residual_block.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/residual_block.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -49,10 +49,11 @@ using Eigen::Dynamic; namespace ceres { namespace internal { -ResidualBlock::ResidualBlock(const CostFunction* cost_function, - const LossFunction* loss_function, - const vector<ParameterBlock*>& parameter_blocks, - int index) +ResidualBlock::ResidualBlock( + const CostFunction* cost_function, + const LossFunction* loss_function, + const std::vector<ParameterBlock*>& parameter_blocks, + int index) : cost_function_(cost_function), loss_function_(loss_function), parameter_blocks_( @@ -116,7 +117,7 @@ bool ResidualBlock::Evaluate(const bool apply_loss_function, cost, residuals, eval_jacobians)) { - string message = + std::string message = "\n\n" "Error in evaluating the ResidualBlock.\n\n" "There are two possible reasons. Either the CostFunction did not evaluate and fill all \n" // NOLINT 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 9c3671bb0a4..05e6d1f81e5 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/residual_block.h +++ b/extern/libmv/third_party/ceres/internal/ceres/residual_block.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -71,7 +71,7 @@ class ResidualBlock { // residual_blocks array. ResidualBlock(const CostFunction* cost_function, const LossFunction* loss_function, - const vector<ParameterBlock*>& parameter_blocks, + const std::vector<ParameterBlock*>& parameter_blocks, int index); // Evaluates the residual term, storing the scalar cost in *cost, the residual @@ -127,7 +127,7 @@ class ResidualBlock { int index() const { return index_; } void set_index(int index) { index_ = index; } - string ToString() { + std::string ToString() { return StringPrintf("{residual block; index=%d}", index_); } diff --git a/extern/libmv/third_party/ceres/internal/ceres/residual_block_utils.cc b/extern/libmv/third_party/ceres/internal/ceres/residual_block_utils.cc index d2564a7692e..dd2bd73a6ac 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/residual_block_utils.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/residual_block_utils.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -44,6 +44,8 @@ namespace ceres { namespace internal { +using std::string; + void InvalidateEvaluation(const ResidualBlock& block, double* cost, double* residuals, diff --git a/extern/libmv/third_party/ceres/internal/ceres/residual_block_utils.h b/extern/libmv/third_party/ceres/internal/ceres/residual_block_utils.h index 7051c2112fd..627337f743c 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/residual_block_utils.h +++ b/extern/libmv/third_party/ceres/internal/ceres/residual_block_utils.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -68,11 +68,11 @@ bool IsEvaluationValid(const ResidualBlock& block, // Create a string representation of the Residual block containing the // value of the parameters, residuals and jacobians if present. // Useful for debugging output. -string EvaluationToString(const ResidualBlock& block, - double const* const* parameters, - double* cost, - double* residuals, - double** jacobians); +std::string EvaluationToString(const ResidualBlock& block, + double const* const* parameters, + double* cost, + double* residuals, + double** jacobians); } // namespace internal } // namespace ceres diff --git a/extern/libmv/third_party/ceres/internal/ceres/schur_complement_solver.cc b/extern/libmv/third_party/ceres/internal/ceres/schur_complement_solver.cc index 33f812b8c96..2491060dcdc 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/schur_complement_solver.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/schur_complement_solver.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -57,10 +57,16 @@ namespace ceres { namespace internal { + +using std::make_pair; +using std::pair; +using std::set; +using std::vector; + namespace { class BlockRandomAccessSparseMatrixAdapter : public LinearOperator { - public: + public: explicit BlockRandomAccessSparseMatrixAdapter( const BlockRandomAccessSparseMatrix& m) : m_(m) { @@ -86,7 +92,7 @@ class BlockRandomAccessSparseMatrixAdapter : public LinearOperator { }; class BlockRandomAccessDiagonalMatrixAdapter : public LinearOperator { - public: + public: explicit BlockRandomAccessDiagonalMatrixAdapter( const BlockRandomAccessDiagonalMatrix& m) : m_(m) { @@ -130,7 +136,7 @@ LinearSolver::Summary SchurComplementSolver::SolveImpl( eliminator_.reset(CHECK_NOTNULL(SchurEliminatorBase::Create(options_))); eliminator_->Init(options_.elimination_groups[0], A->block_structure()); }; - fill(x, x + A->num_cols(), 0.0); + std::fill(x, x + A->num_cols(), 0.0); event_logger.AddEvent("Setup"); eliminator_->Eliminate(A, b, per_solve_options.D, lhs_.get(), rhs_.get()); diff --git a/extern/libmv/third_party/ceres/internal/ceres/schur_complement_solver.h b/extern/libmv/third_party/ceres/internal/ceres/schur_complement_solver.h index 93d23e3d012..714dafc5b0c 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/schur_complement_solver.h +++ b/extern/libmv/third_party/ceres/internal/ceres/schur_complement_solver.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -188,7 +188,7 @@ class SparseSchurComplementSolver : public SchurComplementSolver { double* solution); // Size of the blocks in the Schur complement. - vector<int> blocks_; + std::vector<int> blocks_; SuiteSparse ss_; // Symbolic factorization of the reduced linear system. Precomputed 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 4d9b175b139..ec0e2a020e5 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/schur_eliminator.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/schur_eliminator.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -82,6 +82,11 @@ SchurEliminatorBase::Create(const LinearSolver::Options& options) { } if ((options.row_block_size == 2) && (options.e_block_size == 3) && + (options.f_block_size == 6)) { + return new SchurEliminator<2, 3, 6>(options); + } + if ((options.row_block_size == 2) && + (options.e_block_size == 3) && (options.f_block_size == 9)) { return new SchurEliminator<2, 3, 9>(options); } 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 8fe8b9c88b7..761b58adc7f 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/schur_eliminator.h +++ b/extern/libmv/third_party/ceres/internal/ceres/schur_eliminator.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -263,7 +263,7 @@ class SchurEliminator : public SchurEliminatorBase { // buffer_layout[z1] = 0 // buffer_layout[z5] = y1 * z1 // buffer_layout[z2] = y1 * z1 + y1 * z5 - typedef map<int, int> BufferLayoutType; + typedef std::map<int, int> BufferLayoutType; struct Chunk { Chunk() : size(0) {} int size; @@ -315,11 +315,11 @@ class SchurEliminator : public SchurEliminatorBase { // position of each f block in the row/col of the reduced linear // system. Thus lhs_row_layout_[i] is the row/col position of the // i^th f block. - vector<int> lhs_row_layout_; + std::vector<int> lhs_row_layout_; // Combinatorial structure of the chunks in A. For more information // see the documentation of the Chunk object above. - vector<Chunk> chunks_; + std::vector<Chunk> chunks_; // TODO(sameeragarwal): The following two arrays contain per-thread // storage. They should be refactored into a per thread struct. @@ -346,7 +346,7 @@ class SchurEliminator : public SchurEliminatorBase { // Locks for the blocks in the right hand side of the reduced linear // system. - vector<Mutex*> rhs_locks_; + std::vector<Mutex*> rhs_locks_; }; } // namespace internal diff --git a/extern/libmv/third_party/ceres/internal/ceres/schur_eliminator_impl.h b/extern/libmv/third_party/ceres/internal/ceres/schur_eliminator_impl.h index 305d94e8cc7..f2535880f15 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/schur_eliminator_impl.h +++ b/extern/libmv/third_party/ceres/internal/ceres/schur_eliminator_impl.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -139,7 +139,7 @@ Init(int num_eliminate_blocks, const CompressedRowBlockStructure* bs) { } } - buffer_size_ = max(buffer_size, buffer_size_); + buffer_size_ = std::max(buffer_size, buffer_size_); ++chunk.size; } @@ -194,7 +194,7 @@ Eliminate(const BlockSparseMatrix* A, &row_stride, &col_stride); if (cell_info != NULL) { const int block_size = bs->cols[i].size; - typename EigenTypes<kFBlockSize>::ConstVectorRef + typename EigenTypes<Eigen::Dynamic>::ConstVectorRef diag(D + bs->cols[i].position, block_size); CeresMutexLock l(&cell_info->m); @@ -205,20 +205,19 @@ Eliminate(const BlockSparseMatrix* A, } } - // Eliminate y blocks one chunk at a time. For each chunk,x3 - // compute the entries of the normal equations and the gradient - // vector block corresponding to the y block and then apply - // Gaussian elimination to them. The matrix ete stores the normal - // matrix corresponding to the block being eliminated and array - // buffer_ contains the non-zero blocks in the row corresponding - // to this y block in the normal equations. This computation is - // done in ChunkDiagonalBlockAndGradient. UpdateRhs then applies - // gaussian elimination to the rhs of the normal equations, - // updating the rhs of the reduced linear system by modifying rhs - // blocks for all the z blocks that share a row block/residual - // term with the y block. EliminateRowOuterProduct does the - // corresponding operation for the lhs of the reduced linear - // system. + // Eliminate y blocks one chunk at a time. For each chunk, compute + // the entries of the normal equations and the gradient vector block + // corresponding to the y block and then apply Gaussian elimination + // to them. The matrix ete stores the normal matrix corresponding to + // the block being eliminated and array buffer_ contains the + // non-zero blocks in the row corresponding to this y block in the + // normal equations. This computation is done in + // ChunkDiagonalBlockAndGradient. UpdateRhs then applies gaussian + // elimination to the rhs of the normal equations, updating the rhs + // of the reduced linear system by modifying rhs blocks for all the + // z blocks that share a row block/residual term with the y + // block. EliminateRowOuterProduct does the corresponding operation + // for the lhs of the reduced linear system. #pragma omp parallel for num_threads(num_threads_) schedule(dynamic) for (int i = 0; i < chunks_.size(); ++i) { #ifdef CERES_USE_OPENMP @@ -594,8 +593,8 @@ template <int kRowBlockSize, int kEBlockSize, int kFBlockSize> void SchurEliminator<kRowBlockSize, kEBlockSize, kFBlockSize>:: NoEBlockRowOuterProduct(const BlockSparseMatrix* A, - int row_block_index, - BlockRandomAccessMatrix* lhs) { + int row_block_index, + BlockRandomAccessMatrix* lhs) { const CompressedRowBlockStructure* bs = A->block_structure(); const CompressedRow& row = bs->rows[row_block_index]; const double* values = A->values(); diff --git a/extern/libmv/third_party/ceres/internal/ceres/schur_jacobi_preconditioner.cc b/extern/libmv/third_party/ceres/internal/ceres/schur_jacobi_preconditioner.cc index cbdb7086102..3e6cc90f63c 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/schur_jacobi_preconditioner.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/schur_jacobi_preconditioner.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -54,7 +54,7 @@ SchurJacobiPreconditioner::SchurJacobiPreconditioner( << "Jacobian should have atleast 1 f_block for " << "SCHUR_JACOBI preconditioner."; - vector<int> blocks(num_blocks); + std::vector<int> blocks(num_blocks); for (int i = 0; i < num_blocks; ++i) { blocks[i] = bs.cols[i + options_.elimination_groups[0]].size; } diff --git a/extern/libmv/third_party/ceres/internal/ceres/schur_jacobi_preconditioner.h b/extern/libmv/third_party/ceres/internal/ceres/schur_jacobi_preconditioner.h index 8b528e25075..5398f3ff35d 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/schur_jacobi_preconditioner.h +++ b/extern/libmv/third_party/ceres/internal/ceres/schur_jacobi_preconditioner.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/scratch_evaluate_preparer.cc b/extern/libmv/third_party/ceres/internal/ceres/scratch_evaluate_preparer.cc index 6f0ceefd87d..f01ef11c26f 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/scratch_evaluate_preparer.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/scratch_evaluate_preparer.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/scratch_evaluate_preparer.h b/extern/libmv/third_party/ceres/internal/ceres/scratch_evaluate_preparer.h index 6b127081976..fa9ebd0e50e 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/scratch_evaluate_preparer.h +++ b/extern/libmv/third_party/ceres/internal/ceres/scratch_evaluate_preparer.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/single_linkage_clustering.cc b/extern/libmv/third_party/ceres/internal/ceres/single_linkage_clustering.cc index f0f7e0e1e06..490fcd87cad 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/single_linkage_clustering.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/single_linkage_clustering.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/single_linkage_clustering.h b/extern/libmv/third_party/ceres/internal/ceres/single_linkage_clustering.h index 79c4da114c2..fb02f01de45 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/single_linkage_clustering.h +++ b/extern/libmv/third_party/ceres/internal/ceres/single_linkage_clustering.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/small_blas.h b/extern/libmv/third_party/ceres/internal/ceres/small_blas.h index 5639664b925..264ac53047d 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/small_blas.h +++ b/extern/libmv/third_party/ceres/internal/ceres/small_blas.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -73,7 +73,7 @@ namespace internal { DCHECK((kColB == Eigen::Dynamic) || (kColB == num_col_b)); \ const int NUM_ROW_A = (kRowA != Eigen::Dynamic ? kRowA : num_row_a); \ const int NUM_COL_A = (kColA != Eigen::Dynamic ? kColA : num_col_a); \ - const int NUM_ROW_B = (kColB != Eigen::Dynamic ? kRowB : num_row_b); \ + const int NUM_ROW_B = (kRowB != Eigen::Dynamic ? kRowB : num_row_b); \ const int NUM_COL_B = (kColB != Eigen::Dynamic ? kColB : num_col_b); #define CERES_GEMM_EIGEN_HEADER \ diff --git a/extern/libmv/third_party/ceres/internal/ceres/solver.cc b/extern/libmv/third_party/ceres/internal/ceres/solver.cc index 3512e156f9e..9f3228bb0be 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/solver.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/solver.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -49,6 +49,10 @@ namespace ceres { namespace { +using std::map; +using std::string; +using std::vector; + #define OPTION_OP(x, y, OP) \ if (!(options.x OP y)) { \ std::stringstream ss; \ @@ -150,15 +154,11 @@ bool TrustRegionOptionsAreValid(const Solver::Options& options, string* error) { *error = "Can't use DENSE_NORMAL_CHOLESKY with LAPACK because " "LAPACK was not enabled when Ceres was built."; return false; - } - - if (options.linear_solver_type == DENSE_QR) { + } else if (options.linear_solver_type == DENSE_QR) { *error = "Can't use DENSE_QR with LAPACK because " "LAPACK was not enabled when Ceres was built."; return false; - } - - if (options.linear_solver_type == DENSE_SCHUR) { + } else if (options.linear_solver_type == DENSE_SCHUR) { *error = "Can't use DENSE_SCHUR with LAPACK because " "LAPACK was not enabled when Ceres was built."; return false; @@ -172,21 +172,15 @@ bool TrustRegionOptionsAreValid(const Solver::Options& options, string* error) { *error = "Can't use SPARSE_NORMAL_CHOLESKY with SUITESPARSE because " "SuiteSparse was not enabled when Ceres was built."; return false; - } - - if (options.linear_solver_type == SPARSE_SCHUR) { + } else if (options.linear_solver_type == SPARSE_SCHUR) { *error = "Can't use SPARSE_SCHUR with SUITESPARSE because " "SuiteSparse was not enabled when Ceres was built."; return false; - } - - if (options.preconditioner_type == CLUSTER_JACOBI) { + } else if (options.preconditioner_type == CLUSTER_JACOBI) { *error = "CLUSTER_JACOBI preconditioner not supported. " "SuiteSparse was not enabled when Ceres was built."; return false; - } - - if (options.preconditioner_type == CLUSTER_TRIDIAGONAL) { + } else if (options.preconditioner_type == CLUSTER_TRIDIAGONAL) { *error = "CLUSTER_TRIDIAGONAL preconditioner not supported. " "SuiteSparse was not enabled when Ceres was built."; return false; @@ -200,9 +194,7 @@ bool TrustRegionOptionsAreValid(const Solver::Options& options, string* error) { *error = "Can't use SPARSE_NORMAL_CHOLESKY with CX_SPARSE because " "CXSparse was not enabled when Ceres was built."; return false; - } - - if (options.linear_solver_type == SPARSE_SCHUR) { + } else if (options.linear_solver_type == SPARSE_SCHUR) { *error = "Can't use SPARSE_SCHUR with CX_SPARSE because " "CXSparse was not enabled when Ceres was built."; return false; @@ -217,9 +209,7 @@ bool TrustRegionOptionsAreValid(const Solver::Options& options, string* error) { "Eigen's sparse linear algebra was not enabled when Ceres was " "built."; return false; - } - - if (options.linear_solver_type == SPARSE_SCHUR) { + } else if (options.linear_solver_type == SPARSE_SCHUR) { *error = "Can't use SPARSE_SCHUR with EIGEN_SPARSE because " "Eigen's sparse linear algebra was not enabled when Ceres was " "built."; @@ -228,6 +218,18 @@ bool TrustRegionOptionsAreValid(const Solver::Options& options, string* error) { } #endif + if (options.sparse_linear_algebra_library_type == NO_SPARSE) { + if (options.linear_solver_type == SPARSE_NORMAL_CHOLESKY) { + *error = "Can't use SPARSE_NORMAL_CHOLESKY as " + "sparse_linear_algebra_library_type is NO_SPARSE."; + return false; + } else if (options.linear_solver_type == SPARSE_SCHUR) { + *error = "Can't use SPARSE_SCHUR as " + "sparse_linear_algebra_library_type is NO_SPARSE."; + return false; + } + } + if (options.trust_region_strategy_type == DOGLEG) { if (options.linear_solver_type == ITERATIVE_SCHUR || options.linear_solver_type == CGNR) { @@ -349,6 +351,10 @@ void PreSolveSummarize(const Solver::Options& options, summary->dense_linear_algebra_library_type = options.dense_linear_algebra_library_type; // NOLINT summary->dogleg_type = options.dogleg_type; summary->inner_iteration_time_in_seconds = 0.0; + summary->line_search_cost_evaluation_time_in_seconds = 0.0; + summary->line_search_gradient_evaluation_time_in_seconds = 0.0; + summary->line_search_polynomial_minimization_time_in_seconds = 0.0; + summary->line_search_total_time_in_seconds = 0.0; summary->inner_iterations_given = options.use_inner_iterations; summary->line_search_direction_type = options.line_search_direction_type; // NOLINT summary->line_search_interpolation_type = options.line_search_interpolation_type; // NOLINT @@ -446,11 +452,16 @@ bool Solver::Options::IsValid(string* error) const { return false; } - if (minimizer_type == TRUST_REGION) { - return TrustRegionOptionsAreValid(*this, error); + if (minimizer_type == TRUST_REGION && + !TrustRegionOptionsAreValid(*this, error)) { + return false; } - CHECK_EQ(minimizer_type, LINE_SEARCH); + // We do not know if the problem is bounds constrained or not, if it + // is then the trust region solver will also use the line search + // solver to do a projection onto the box constraints, so make sure + // that the line search options are checked independent of what + // minimizer algorithm is being used. return LineSearchOptionsAreValid(*this, error); } @@ -553,6 +564,10 @@ Solver::Summary::Summary() residual_evaluation_time_in_seconds(-1.0), jacobian_evaluation_time_in_seconds(-1.0), inner_iteration_time_in_seconds(-1.0), + line_search_cost_evaluation_time_in_seconds(-1.0), + line_search_gradient_evaluation_time_in_seconds(-1.0), + line_search_polynomial_minimization_time_in_seconds(-1.0), + line_search_total_time_in_seconds(-1.0), num_parameter_blocks(-1), num_parameters(-1), num_effective_parameters(-1), @@ -563,6 +578,7 @@ Solver::Summary::Summary() num_effective_parameters_reduced(-1), num_residual_blocks_reduced(-1), num_residuals_reduced(-1), + is_constrained(false), num_threads_given(-1), num_threads_used(-1), num_linear_solver_threads_given(-1), @@ -597,7 +613,7 @@ string Solver::Summary::BriefReport() const { initial_cost, final_cost, TerminationTypeToString(termination_type)); -}; +} string Solver::Summary::FullReport() const { using internal::VersionString; @@ -768,38 +784,55 @@ string Solver::Summary::FullReport() const { num_inner_iteration_steps); } + const bool print_line_search_timing_information = + minimizer_type == LINE_SEARCH || + (minimizer_type == TRUST_REGION && is_constrained); + StringAppendF(&report, "\nTime (in seconds):\n"); - StringAppendF(&report, "Preprocessor %25.3f\n", + StringAppendF(&report, "Preprocessor %25.4f\n", preprocessor_time_in_seconds); - StringAppendF(&report, "\n Residual evaluation %23.3f\n", + StringAppendF(&report, "\n Residual evaluation %23.4f\n", residual_evaluation_time_in_seconds); - StringAppendF(&report, " Jacobian evaluation %23.3f\n", + if (print_line_search_timing_information) { + StringAppendF(&report, " Line search cost evaluation %10.4f\n", + line_search_cost_evaluation_time_in_seconds); + } + StringAppendF(&report, " Jacobian evaluation %23.4f\n", jacobian_evaluation_time_in_seconds); + if (print_line_search_timing_information) { + StringAppendF(&report, " Line search gradient evaluation %6.4f\n", + line_search_gradient_evaluation_time_in_seconds); + } if (minimizer_type == TRUST_REGION) { - StringAppendF(&report, " Linear solver %23.3f\n", + StringAppendF(&report, " Linear solver %23.4f\n", linear_solver_time_in_seconds); } if (inner_iterations_used) { - StringAppendF(&report, " Inner iterations %23.3f\n", + StringAppendF(&report, " Inner iterations %23.4f\n", inner_iteration_time_in_seconds); } - StringAppendF(&report, "Minimizer %25.3f\n\n", + if (print_line_search_timing_information) { + StringAppendF(&report, " Line search polynomial minimization %.4f\n", + line_search_polynomial_minimization_time_in_seconds); + } + + StringAppendF(&report, "Minimizer %25.4f\n\n", minimizer_time_in_seconds); - StringAppendF(&report, "Postprocessor %24.3f\n", + StringAppendF(&report, "Postprocessor %24.4f\n", postprocessor_time_in_seconds); - StringAppendF(&report, "Total %25.3f\n\n", + StringAppendF(&report, "Total %25.4f\n\n", total_time_in_seconds); StringAppendF(&report, "Termination: %25s (%s)\n", TerminationTypeToString(termination_type), message.c_str()); return report; -}; +} bool Solver::Summary::IsSolutionUsable() const { return internal::IsSolutionUsable(*this); diff --git a/extern/libmv/third_party/ceres/internal/ceres/solver_utils.cc b/extern/libmv/third_party/ceres/internal/ceres/solver_utils.cc index bd304e7ac5d..7f4ff7eb940 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/solver_utils.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/solver_utils.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -30,14 +30,22 @@ #include <string> +#include "Eigen/Core" #include "ceres/internal/port.h" +#include "ceres/solver_utils.h" #include "ceres/version.h" namespace ceres { namespace internal { -string VersionString() { - string value = string(CERES_VERSION_STRING); +#define CERES_EIGEN_VERSION \ + CERES_TO_STRING(EIGEN_WORLD_VERSION) "." \ + CERES_TO_STRING(EIGEN_MAJOR_VERSION) "." \ + CERES_TO_STRING(EIGEN_MINOR_VERSION) + +std::string VersionString() { + std::string value = std::string(CERES_VERSION_STRING); + value += "-eigen-(" + std::string(CERES_EIGEN_VERSION) + ")"; #ifdef CERES_NO_LAPACK value += "-no_lapack"; @@ -46,11 +54,11 @@ string VersionString() { #endif #ifndef CERES_NO_SUITESPARSE - value += "-suitesparse"; + value += "-suitesparse-(" + std::string(CERES_SUITESPARSE_VERSION) + ")"; #endif #ifndef CERES_NO_CXSPARSE - value += "-cxsparse"; + value += "-cxsparse-(" + std::string(CERES_CXSPARSE_VERSION) + ")"; #endif #ifdef CERES_USE_EIGEN_SPARSE diff --git a/extern/libmv/third_party/ceres/internal/ceres/solver_utils.h b/extern/libmv/third_party/ceres/internal/ceres/solver_utils.h index 41c8a6e1292..85fbf3776ab 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/solver_utils.h +++ b/extern/libmv/third_party/ceres/internal/ceres/solver_utils.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -31,6 +31,9 @@ #include <algorithm> #include <string> +#include "ceres/iteration_callback.h" +#include "ceres/types.h" + namespace ceres { namespace internal { @@ -48,11 +51,11 @@ void SetSummaryFinalCost(SummaryType* summary) { // iteration because the minimizer maybe making non-monotonic steps. for (int i = 0; i < summary->iterations.size(); ++i) { const IterationSummary& iteration_summary = summary->iterations[i]; - summary->final_cost = min(iteration_summary.cost, summary->final_cost); + summary->final_cost = std::min(iteration_summary.cost, summary->final_cost); } } -string VersionString(); +std::string VersionString(); } // namespace internal } // namespace ceres diff --git a/extern/libmv/third_party/ceres/internal/ceres/sparse_matrix.cc b/extern/libmv/third_party/ceres/internal/ceres/sparse_matrix.cc index 55336fd3130..f95ff3220bd 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/sparse_matrix.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/sparse_matrix.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/sparse_matrix.h b/extern/libmv/third_party/ceres/internal/ceres/sparse_matrix.h index f3b96712a70..b3af1d06440 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/sparse_matrix.h +++ b/extern/libmv/third_party/ceres/internal/ceres/sparse_matrix.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/sparse_normal_cholesky_solver.cc b/extern/libmv/third_party/ceres/internal/ceres/sparse_normal_cholesky_solver.cc index 94f7e5803c4..ed00879b47a 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/sparse_normal_cholesky_solver.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/sparse_normal_cholesky_solver.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -57,9 +57,9 @@ namespace { // A templated factorized and solve function, which allows us to use // the same code independent of whether a AMD or a Natural ordering is // used. -template <typename SimplicialCholeskySolver> +template <typename SimplicialCholeskySolver, typename SparseMatrixType> LinearSolver::Summary SimplicialLDLTSolve( - Eigen::MappedSparseMatrix<double, Eigen::ColMajor>& lhs, + const SparseMatrixType& lhs, const bool do_symbolic_analysis, SimplicialCholeskySolver* solver, double* rhs_and_solution, @@ -103,6 +103,53 @@ LinearSolver::Summary SimplicialLDLTSolve( #endif // CERES_USE_EIGEN_SPARSE +#ifndef CERES_NO_CXSPARSE +LinearSolver::Summary ComputeNormalEquationsAndSolveUsingCXSparse( + CompressedRowSparseMatrix* A, + double * rhs_and_solution, + EventLogger* event_logger) { + LinearSolver::Summary summary; + summary.num_iterations = 1; + summary.termination_type = LINEAR_SOLVER_SUCCESS; + summary.message = "Success."; + + CXSparse cxsparse; + + // Wrap the augmented Jacobian in a compressed sparse column matrix. + cs_di a_transpose = cxsparse.CreateSparseMatrixTransposeView(A); + + // Compute the normal equations. J'J delta = J'f and solve them + // using a sparse Cholesky factorization. Notice that when compared + // to SuiteSparse we have to explicitly compute the transpose of Jt, + // and then the normal equations before they can be + // factorized. CHOLMOD/SuiteSparse on the other hand can just work + // off of Jt to compute the Cholesky factorization of the normal + // equations. + cs_di* a = cxsparse.TransposeMatrix(&a_transpose); + cs_di* lhs = cxsparse.MatrixMatrixMultiply(&a_transpose, a); + cxsparse.Free(a); + event_logger->AddEvent("NormalEquations"); + + cs_dis* factor = cxsparse.AnalyzeCholesky(lhs); + event_logger->AddEvent("Analysis"); + + if (factor == NULL) { + summary.termination_type = LINEAR_SOLVER_FATAL_ERROR; + summary.message = "CXSparse::AnalyzeCholesky failed."; + } else if (!cxsparse.SolveCholesky(lhs, factor, rhs_and_solution)) { + summary.termination_type = LINEAR_SOLVER_FAILURE; + summary.message = "CXSparse::SolveCholesky failed."; + } + event_logger->AddEvent("Solve"); + + cxsparse.Free(lhs); + cxsparse.Free(factor); + event_logger->AddEvent("TearDown"); + return summary; +} + +#endif // CERES_NO_CXSPARSE + } // namespace SparseNormalCholeskySolver::SparseNormalCholeskySolver( @@ -155,13 +202,13 @@ LinearSolver::Summary SparseNormalCholeskySolver::SolveImpl( LinearSolver::Summary summary; switch (options_.sparse_linear_algebra_library_type) { case SUITE_SPARSE: - summary = SolveImplUsingSuiteSparse(A, per_solve_options, x); + summary = SolveImplUsingSuiteSparse(A, x); break; case CX_SPARSE: - summary = SolveImplUsingCXSparse(A, per_solve_options, x); + summary = SolveImplUsingCXSparse(A, x); break; case EIGEN_SPARSE: - summary = SolveImplUsingEigen(A, per_solve_options, x); + summary = SolveImplUsingEigen(A, x); break; default: LOG(FATAL) << "Unknown sparse linear algebra library : " @@ -177,7 +224,6 @@ LinearSolver::Summary SparseNormalCholeskySolver::SolveImpl( LinearSolver::Summary SparseNormalCholeskySolver::SolveImplUsingEigen( CompressedRowSparseMatrix* A, - const LinearSolver::PerSolveOptions& per_solve_options, double * rhs_and_solution) { #ifndef CERES_USE_EIGEN_SPARSE @@ -200,9 +246,28 @@ LinearSolver::Summary SparseNormalCholeskySolver::SolveImplUsingEigen( // before they can be factorized. CHOLMOD/SuiteSparse on the other // hand can just work off of Jt to compute the Cholesky // factorization of the normal equations. - // - // TODO(sameeragarwal): See note about how this maybe a bad idea for - // dynamic sparsity. + + if (options_.dynamic_sparsity) { + // In the case where the problem has dynamic sparsity, it is not + // worth using the ComputeOuterProduct routine, as the setup cost + // is not amortized over multiple calls to Solve. + Eigen::MappedSparseMatrix<double, Eigen::RowMajor> a( + A->num_rows(), + A->num_cols(), + A->num_nonzeros(), + A->mutable_rows(), + A->mutable_cols(), + A->mutable_values()); + + Eigen::SparseMatrix<double> lhs = a.transpose() * a; + Eigen::SimplicialLDLT<Eigen::SparseMatrix<double> > solver; + return SimplicialLDLTSolve(lhs, + true, + &solver, + rhs_and_solution, + &event_logger); + } + if (outer_product_.get() == NULL) { outer_product_.reset( CompressedRowSparseMatrix::CreateOuterProductMatrixAndProgram( @@ -217,7 +282,7 @@ LinearSolver::Summary SparseNormalCholeskySolver::SolveImplUsingEigen( // outer_product_ is a compressed row sparse matrix and in lower // triangular form, when mapped to a compressed column sparse // matrix, it becomes an upper triangular matrix. - Eigen::MappedSparseMatrix<double, Eigen::ColMajor> AtA( + Eigen::MappedSparseMatrix<double, Eigen::ColMajor> lhs( outer_product_->num_rows(), outer_product_->num_rows(), outer_product_->num_nonzeros(), @@ -225,27 +290,19 @@ LinearSolver::Summary SparseNormalCholeskySolver::SolveImplUsingEigen( outer_product_->mutable_cols(), outer_product_->mutable_values()); - // Dynamic sparsity means that we cannot depend on a static analysis - // of sparsity structure of the jacobian, so we compute a new - // symbolic factorization every time. - if (options_.dynamic_sparsity) { - amd_ldlt_.reset(NULL); - } - bool do_symbolic_analysis = false; - // If using post ordering or dynamic sparsity, or an old version of - // Eigen, we cannot depend on a preordered jacobian, so we work with - // a SimplicialLDLT decomposition with AMD ordering. + // If using post ordering or an old version of Eigen, we cannot + // depend on a preordered jacobian, so we work with a SimplicialLDLT + // decomposition with AMD ordering. if (options_.use_postordering || - options_.dynamic_sparsity || !EIGEN_VERSION_AT_LEAST(3, 2, 2)) { if (amd_ldlt_.get() == NULL) { amd_ldlt_.reset(new SimplicialLDLTWithAMDOrdering); do_symbolic_analysis = true; } - return SimplicialLDLTSolve(AtA, + return SimplicialLDLTSolve(lhs, do_symbolic_analysis, amd_ldlt_.get(), rhs_and_solution, @@ -259,7 +316,7 @@ LinearSolver::Summary SparseNormalCholeskySolver::SolveImplUsingEigen( do_symbolic_analysis = true; } - return SimplicialLDLTSolve(AtA, + return SimplicialLDLTSolve(lhs, do_symbolic_analysis, natural_ldlt_.get(), rhs_and_solution, @@ -269,11 +326,8 @@ LinearSolver::Summary SparseNormalCholeskySolver::SolveImplUsingEigen( #endif // EIGEN_USE_EIGEN_SPARSE } - - LinearSolver::Summary SparseNormalCholeskySolver::SolveImplUsingCXSparse( CompressedRowSparseMatrix* A, - const LinearSolver::PerSolveOptions& per_solve_options, double * rhs_and_solution) { #ifdef CERES_NO_CXSPARSE @@ -290,6 +344,11 @@ LinearSolver::Summary SparseNormalCholeskySolver::SolveImplUsingCXSparse( #else EventLogger event_logger("SparseNormalCholeskySolver::CXSparse::Solve"); + if (options_.dynamic_sparsity) { + return ComputeNormalEquationsAndSolveUsingCXSparse(A, + rhs_and_solution, + &event_logger); + } LinearSolver::Summary summary; summary.num_iterations = 1; @@ -302,10 +361,6 @@ LinearSolver::Summary SparseNormalCholeskySolver::SolveImplUsingCXSparse( // before they can be factorized. CHOLMOD/SuiteSparse on the other // hand can just work off of Jt to compute the Cholesky // factorization of the normal equations. - // - // TODO(sameeragarwal): If dynamic sparsity is enabled, then this is - // not a good idea performance wise, since the jacobian has far too - // many entries and the program will go crazy with memory. if (outer_product_.get() == NULL) { outer_product_.reset( CompressedRowSparseMatrix::CreateOuterProductMatrixAndProgram( @@ -314,27 +369,19 @@ LinearSolver::Summary SparseNormalCholeskySolver::SolveImplUsingCXSparse( CompressedRowSparseMatrix::ComputeOuterProduct( *A, pattern_, outer_product_.get()); - cs_di AtA_view = + cs_di lhs = cxsparse_.CreateSparseMatrixTransposeView(outer_product_.get()); - cs_di* AtA = &AtA_view; event_logger.AddEvent("Setup"); // Compute symbolic factorization if not available. - if (options_.dynamic_sparsity) { - FreeFactorization(); - } if (cxsparse_factor_ == NULL) { if (options_.use_postordering) { - cxsparse_factor_ = cxsparse_.BlockAnalyzeCholesky(AtA, + cxsparse_factor_ = cxsparse_.BlockAnalyzeCholesky(&lhs, A->col_blocks(), A->col_blocks()); } else { - if (options_.dynamic_sparsity) { - cxsparse_factor_ = cxsparse_.AnalyzeCholesky(AtA); - } else { - cxsparse_factor_ = cxsparse_.AnalyzeCholeskyWithNaturalOrdering(AtA); - } + cxsparse_factor_ = cxsparse_.AnalyzeCholeskyWithNaturalOrdering(&lhs); } } event_logger.AddEvent("Analysis"); @@ -343,7 +390,7 @@ LinearSolver::Summary SparseNormalCholeskySolver::SolveImplUsingCXSparse( summary.termination_type = LINEAR_SOLVER_FATAL_ERROR; summary.message = "CXSparse failure. Unable to find symbolic factorization."; - } else if (!cxsparse_.SolveCholesky(AtA, + } else if (!cxsparse_.SolveCholesky(&lhs, cxsparse_factor_, rhs_and_solution)) { summary.termination_type = LINEAR_SOLVER_FAILURE; @@ -357,7 +404,6 @@ LinearSolver::Summary SparseNormalCholeskySolver::SolveImplUsingCXSparse( LinearSolver::Summary SparseNormalCholeskySolver::SolveImplUsingSuiteSparse( CompressedRowSparseMatrix* A, - const LinearSolver::PerSolveOptions& per_solve_options, double * rhs_and_solution) { #ifdef CERES_NO_SUITESPARSE @@ -385,6 +431,7 @@ LinearSolver::Summary SparseNormalCholeskySolver::SolveImplUsingSuiteSparse( if (options_.dynamic_sparsity) { FreeFactorization(); } + if (factor_ == NULL) { if (options_.use_postordering) { factor_ = ss_.BlockAnalyzeCholesky(&lhs, diff --git a/extern/libmv/third_party/ceres/internal/ceres/sparse_normal_cholesky_solver.h b/extern/libmv/third_party/ceres/internal/ceres/sparse_normal_cholesky_solver.h index 12c05245075..2a93bc56d29 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/sparse_normal_cholesky_solver.h +++ b/extern/libmv/third_party/ceres/internal/ceres/sparse_normal_cholesky_solver.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -69,19 +69,15 @@ class SparseNormalCholeskySolver : public CompressedRowSparseMatrixSolver { LinearSolver::Summary SolveImplUsingSuiteSparse( CompressedRowSparseMatrix* A, - const LinearSolver::PerSolveOptions& options, double* rhs_and_solution); - // Crashes if CSparse is not installed. + LinearSolver::Summary SolveImplUsingCXSparse( CompressedRowSparseMatrix* A, - const LinearSolver::PerSolveOptions& options, double* rhs_and_solution); - // Crashes if CERES_USE_EIGEN_SPARSE is not defined. LinearSolver::Summary SolveImplUsingEigen( CompressedRowSparseMatrix* A, - const LinearSolver::PerSolveOptions& options, double* rhs_and_solution); void FreeFactorization(); @@ -120,7 +116,7 @@ class SparseNormalCholeskySolver : public CompressedRowSparseMatrixSolver { #endif scoped_ptr<CompressedRowSparseMatrix> outer_product_; - vector<int> pattern_; + std::vector<int> pattern_; const LinearSolver::Options options_; CERES_DISALLOW_COPY_AND_ASSIGN(SparseNormalCholeskySolver); }; diff --git a/extern/libmv/third_party/ceres/internal/ceres/split.cc b/extern/libmv/third_party/ceres/internal/ceres/split.cc index 3edbc281340..296c09a6440 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/split.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/split.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -30,12 +30,17 @@ #include "ceres/split.h" +#include <iterator> #include <string> #include <vector> -#include <iterator> + #include "ceres/internal/port.h" namespace ceres { +namespace internal { + +using std::string; +using std::vector; // If we know how much to allocate for a vector of strings, we can allocate the // vector<string> only once and directly to the right size. This saves in @@ -110,8 +115,9 @@ void SplitStringUsing(const string& full, const char* delim, vector<string>* result) { result->reserve(result->size() + CalculateReserveForVector(full, delim)); - back_insert_iterator< vector<string> > it(*result); + std::back_insert_iterator<vector<string> > it(*result); SplitStringToIteratorUsing(full, delim, it); } +} // namespace internal } // namespace ceres diff --git a/extern/libmv/third_party/ceres/internal/ceres/split.h b/extern/libmv/third_party/ceres/internal/ceres/split.h index 2334d26037f..94b773dee4d 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/split.h +++ b/extern/libmv/third_party/ceres/internal/ceres/split.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2011 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -36,13 +36,15 @@ #include "ceres/internal/port.h" namespace ceres { +namespace internal { // Split a string using one or more character delimiters, presented as a // nul-terminated c string. Append the components to 'result'. If there are // consecutive delimiters, this function skips over all of them. -void SplitStringUsing(const string& full, const char* delim, - vector<string>* res); +void SplitStringUsing(const std::string& full, const char* delim, + std::vector<std::string>* res); +} // namespace internal } // namespace ceres #endif // CERES_INTERNAL_SPLIT_H_ diff --git a/extern/libmv/third_party/ceres/internal/ceres/stl_util.h b/extern/libmv/third_party/ceres/internal/ceres/stl_util.h index 08f15ec8398..0595a4cf2e9 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/stl_util.h +++ b/extern/libmv/third_party/ceres/internal/ceres/stl_util.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/stringprintf.cc b/extern/libmv/third_party/ceres/internal/ceres/stringprintf.cc index 0f85f05e056..d1d8b5fe8ab 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/stringprintf.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/stringprintf.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -41,6 +41,8 @@ namespace ceres { namespace internal { +using std::string; + #ifdef _MSC_VER enum { IS_COMPILER_MSVC = 1 }; #if _MSC_VER < 1800 diff --git a/extern/libmv/third_party/ceres/internal/ceres/stringprintf.h b/extern/libmv/third_party/ceres/internal/ceres/stringprintf.h index cd1be142aed..feeb9c23430 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/stringprintf.h +++ b/extern/libmv/third_party/ceres/internal/ceres/stringprintf.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -63,23 +63,23 @@ namespace internal { #endif // Return a C++ string. -extern string StringPrintf(const char* format, ...) +extern std::string StringPrintf(const char* format, ...) // Tell the compiler to do printf format string checking. CERES_PRINTF_ATTRIBUTE(1, 2); // Store result into a supplied string and return it. -extern const string& SStringPrintf(string* dst, const char* format, ...) +extern const std::string& SStringPrintf(std::string* dst, const char* format, ...) // Tell the compiler to do printf format string checking. CERES_PRINTF_ATTRIBUTE(2, 3); // Append result to a supplied string. -extern void StringAppendF(string* dst, const char* format, ...) +extern void StringAppendF(std::string* dst, const char* format, ...) // Tell the compiler to do printf format string checking. CERES_PRINTF_ATTRIBUTE(2, 3); // Lower-level routine that takes a va_list and appends to a specified string. // All other routines are just convenience wrappers around it. -extern void StringAppendV(string* dst, const char* format, va_list ap); +extern void StringAppendV(std::string* dst, const char* format, va_list ap); #undef CERES_PRINTF_ATTRIBUTE diff --git a/extern/libmv/third_party/ceres/internal/ceres/suitesparse.cc b/extern/libmv/third_party/ceres/internal/ceres/suitesparse.cc index 1df7566e00a..200daa2d8bf 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/suitesparse.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/suitesparse.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -44,6 +44,9 @@ namespace ceres { namespace internal { +using std::string; +using std::vector; + SuiteSparse::SuiteSparse() { cholmod_start(&cc_); } diff --git a/extern/libmv/third_party/ceres/internal/ceres/suitesparse.h b/extern/libmv/third_party/ceres/internal/ceres/suitesparse.h index baab8998b29..380d76e003a 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/suitesparse.h +++ b/extern/libmv/third_party/ceres/internal/ceres/suitesparse.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -42,7 +42,6 @@ #include <string> #include <vector> -#include "ceres/internal/port.h" #include "ceres/linear_solver.h" #include "cholmod.h" #include "glog/logging.h" @@ -144,12 +143,12 @@ class SuiteSparse { // message contains an explanation of the failures if any. // // Caller owns the result. - cholmod_factor* AnalyzeCholesky(cholmod_sparse* A, string* message); + cholmod_factor* AnalyzeCholesky(cholmod_sparse* A, std::string* message); cholmod_factor* BlockAnalyzeCholesky(cholmod_sparse* A, - const vector<int>& row_blocks, - const vector<int>& col_blocks, - string* message); + const std::vector<int>& row_blocks, + const std::vector<int>& col_blocks, + std::string* message); // If A is symmetric, then compute the symbolic Cholesky // factorization of A(ordering, ordering). If A is unsymmetric, then @@ -162,9 +161,10 @@ class SuiteSparse { // message contains an explanation of the failures if any. // // Caller owns the result. - cholmod_factor* AnalyzeCholeskyWithUserOrdering(cholmod_sparse* A, - const vector<int>& ordering, - string* message); + cholmod_factor* AnalyzeCholeskyWithUserOrdering( + cholmod_sparse* A, + const std::vector<int>& ordering, + std::string* message); // Perform a symbolic factorization of A without re-ordering A. No // postordering of the elimination tree is performed. This ensures @@ -173,7 +173,7 @@ class SuiteSparse { // // message contains an explanation of the failures if any. cholmod_factor* AnalyzeCholeskyWithNaturalOrdering(cholmod_sparse* A, - string* message); + std::string* message); // Use the symbolic factorization in L, to find the numerical // factorization for the matrix A or AA^T. Return true if @@ -183,14 +183,14 @@ class SuiteSparse { // message contains an explanation of the failures if any. LinearSolverTerminationType Cholesky(cholmod_sparse* A, cholmod_factor* L, - string* message); + std::string* message); // Given a Cholesky factorization of a matrix A = LL^T, solve the // linear system Ax = b, and return the result. If the Solve fails // NULL is returned. Caller owns the result. // // message contains an explanation of the failures if any. - cholmod_dense* Solve(cholmod_factor* L, cholmod_dense* b, string* message); + cholmod_dense* Solve(cholmod_factor* L, cholmod_dense* b, std::string* message); // By virtue of the modeling layer in Ceres being block oriented, // all the matrices used by Ceres are also block oriented. When @@ -215,9 +215,9 @@ class SuiteSparse { // A. If this is the case, only the first sum(col_blocks) are used // to compute the ordering. bool BlockAMDOrdering(const cholmod_sparse* A, - const vector<int>& row_blocks, - const vector<int>& col_blocks, - vector<int>* ordering); + const std::vector<int>& row_blocks, + const std::vector<int>& col_blocks, + std::vector<int>* ordering); // Find a fill reducing approximate minimum degree // ordering. ordering is expected to be large enough to hold the @@ -236,7 +236,7 @@ class SuiteSparse { // being conservative and choosing the next minor version where // things are stable. static bool IsConstrainedApproximateMinimumDegreeOrderingAvailable() { - return (SUITESPARSE_VERSION>4001); + return (SUITESPARSE_VERSION > 4001); } // Find a fill reducing approximate minimum degree @@ -260,15 +260,15 @@ class SuiteSparse { void Free(cholmod_dense* m) { cholmod_free_dense(&m, &cc_); } void Free(cholmod_factor* m) { cholmod_free_factor(&m, &cc_); } - void Print(cholmod_sparse* m, const string& name) { + void Print(cholmod_sparse* m, const std::string& name) { cholmod_print_sparse(m, const_cast<char*>(name.c_str()), &cc_); } - void Print(cholmod_dense* m, const string& name) { + void Print(cholmod_dense* m, const std::string& name) { cholmod_print_dense(m, const_cast<char*>(name.c_str()), &cc_); } - void Print(cholmod_triplet* m, const string& name) { + void Print(cholmod_triplet* m, const std::string& name) { cholmod_print_triplet(m, const_cast<char*>(name.c_str()), &cc_); } @@ -298,7 +298,7 @@ class SuiteSparse { return false; } - void Free(void*) {}; + void Free(void* arg) {} }; #endif // CERES_NO_SUITESPARSE diff --git a/extern/libmv/third_party/ceres/internal/ceres/triplet_sparse_matrix.cc b/extern/libmv/third_party/ceres/internal/ceres/triplet_sparse_matrix.cc index 824b123bc28..8df405ca115 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/triplet_sparse_matrix.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/triplet_sparse_matrix.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -128,7 +128,7 @@ void TripletSparseMatrix::Reserve(int new_max_num_nonzeros) { } void TripletSparseMatrix::SetZero() { - fill(values_.get(), values_.get() + max_num_nonzeros_, 0.0); + std::fill(values_.get(), values_.get() + max_num_nonzeros_, 0.0); num_nonzeros_ = 0; } @@ -136,7 +136,7 @@ void TripletSparseMatrix::set_num_nonzeros(int num_nonzeros) { CHECK_GE(num_nonzeros, 0); CHECK_LE(num_nonzeros, max_num_nonzeros_); num_nonzeros_ = num_nonzeros; -}; +} void TripletSparseMatrix::AllocateMemory() { rows_.reset(new int[max_num_nonzeros_]); diff --git a/extern/libmv/third_party/ceres/internal/ceres/triplet_sparse_matrix.h b/extern/libmv/third_party/ceres/internal/ceres/triplet_sparse_matrix.h index 4d7cde7fe9c..f3f5370df6f 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/triplet_sparse_matrix.h +++ b/extern/libmv/third_party/ceres/internal/ceres/triplet_sparse_matrix.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/trust_region_minimizer.cc b/extern/libmv/third_party/ceres/internal/ceres/trust_region_minimizer.cc index 926bced6226..d654d0867f1 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/trust_region_minimizer.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/trust_region_minimizer.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -31,8 +31,8 @@ #include "ceres/trust_region_minimizer.h" #include <algorithm> -#include <cstdlib> #include <cmath> +#include <cstdlib> #include <cstring> #include <limits> #include <string> @@ -85,22 +85,14 @@ LineSearch::Summary DoLineSearch(const Minimizer::Options& options, options.max_line_search_step_expansion; line_search_options.function = &line_search_function; - string message; - scoped_ptr<LineSearch> - line_search(CHECK_NOTNULL( - LineSearch::Create(ceres::ARMIJO, - line_search_options, - &message))); + std::string message; + scoped_ptr<LineSearch> line_search( + CHECK_NOTNULL(LineSearch::Create(ceres::ARMIJO, + line_search_options, + &message))); LineSearch::Summary summary; line_search_function.Init(x, delta); - // Try the trust region step. line_search->Search(1.0, cost, gradient.dot(delta), &summary); - if (!summary.success) { - // If that was not successful, try the negative gradient as a - // search direction. - line_search_function.Init(x, -gradient); - line_search->Search(1.0, cost, -gradient.squaredNorm(), &summary); - } return summary; } @@ -148,6 +140,7 @@ void TrustRegionMinimizer::Minimize(const Minimizer::Options& options, summary->termination_type = NO_CONVERGENCE; summary->num_successful_steps = 0; summary->num_unsuccessful_steps = 0; + summary->is_constrained = options.is_constrained; const int num_parameters = evaluator->NumParameters(); const int num_effective_parameters = evaluator->NumEffectiveParameters(); @@ -231,6 +224,15 @@ void TrustRegionMinimizer::Minimize(const Minimizer::Options& options, options_.gradient_tolerance); summary->termination_type = CONVERGENCE; VLOG_IF(1, is_not_silent) << "Terminating: " << summary->message; + + // Ensure that there is an iteration summary object for iteration + // 0 in Summary::iterations. + iteration_summary.iteration_time_in_seconds = + WallTimeInSeconds() - iteration_start_time; + iteration_summary.cumulative_time_in_seconds = + WallTimeInSeconds() - start_time + + summary->preprocessor_time_in_seconds; + summary->iterations.push_back(iteration_summary); return; } @@ -390,6 +392,16 @@ void TrustRegionMinimizer::Minimize(const Minimizer::Options& options, if (use_line_search) { const LineSearch::Summary line_search_summary = DoLineSearch(options, x, gradient, cost, delta, evaluator); + + summary->line_search_cost_evaluation_time_in_seconds += + line_search_summary.cost_evaluation_time_in_seconds; + summary->line_search_gradient_evaluation_time_in_seconds += + line_search_summary.gradient_evaluation_time_in_seconds; + summary->line_search_polynomial_minimization_time_in_seconds += + line_search_summary.polynomial_minimization_time_in_seconds; + summary->line_search_total_time_in_seconds += + line_search_summary.total_time_in_seconds; + if (line_search_summary.success) { delta *= line_search_summary.optimal_step_size; } @@ -398,17 +410,19 @@ void TrustRegionMinimizer::Minimize(const Minimizer::Options& options, double new_cost = std::numeric_limits<double>::max(); if (evaluator->Plus(x.data(), delta.data(), x_plus_delta.data())) { if (!evaluator->Evaluate(x_plus_delta.data(), - &new_cost, - NULL, - NULL, - NULL)) { - LOG(WARNING) << "Step failed to evaluate. " - << "Treating it as a step with infinite cost"; - new_cost = numeric_limits<double>::max(); + &new_cost, + NULL, + NULL, + NULL)) { + LOG_IF(WARNING, is_not_silent) + << "Step failed to evaluate. " + << "Treating it as a step with infinite cost"; + new_cost = std::numeric_limits<double>::max(); } } else { - LOG(WARNING) << "x_plus_delta = Plus(x, delta) failed. " - << "Treating it as a step with infinite cost"; + LOG_IF(WARNING, is_not_silent) + << "x_plus_delta = Plus(x, delta) failed. " + << "Treating it as a step with infinite cost"; } if (new_cost < std::numeric_limits<double>::max()) { @@ -475,7 +489,7 @@ void TrustRegionMinimizer::Minimize(const Minimizer::Options& options, iteration_summary.cost_change = cost - new_cost; const double absolute_function_tolerance = options_.function_tolerance * cost; - if (fabs(iteration_summary.cost_change) < absolute_function_tolerance) { + if (fabs(iteration_summary.cost_change) <= absolute_function_tolerance) { summary->message = StringPrintf("Function tolerance reached. " "|cost_change|/cost: %e <= %e", @@ -507,7 +521,7 @@ void TrustRegionMinimizer::Minimize(const Minimizer::Options& options, // reference iteration, allowing for non-monotonic steps. iteration_summary.relative_decrease = options.use_nonmonotonic_steps - ? max(relative_decrease, historical_relative_decrease) + ? std::max(relative_decrease, historical_relative_decrease) : relative_decrease; // Normally, the quality of a trust region step is measured by @@ -598,19 +612,9 @@ void TrustRegionMinimizer::Minimize(const Minimizer::Options& options, } iteration_summary.gradient_max_norm = - (x - projected_gradient_step).lpNorm<Eigen::Infinity>(); + (x - projected_gradient_step).lpNorm<Eigen::Infinity>(); iteration_summary.gradient_norm = (x - projected_gradient_step).norm(); - if (iteration_summary.gradient_max_norm <= options.gradient_tolerance) { - summary->message = StringPrintf("Gradient tolerance reached. " - "Gradient max norm: %e <= %e", - iteration_summary.gradient_max_norm, - options_.gradient_tolerance); - summary->termination_type = CONVERGENCE; - VLOG_IF(1, is_not_silent) << "Terminating: " << summary->message; - return; - } - if (options_.jacobi_scaling) { jacobian->ScaleColumns(scale.data()); } @@ -668,20 +672,42 @@ void TrustRegionMinimizer::Minimize(const Minimizer::Options& options, iteration_summary.cost = cost + summary->fixed_cost; iteration_summary.trust_region_radius = strategy->Radius(); - if (iteration_summary.trust_region_radius < - options_.min_trust_region_radius) { - summary->message = "Termination. Minimum trust region radius reached."; - summary->termination_type = CONVERGENCE; - VLOG_IF(1, is_not_silent) << summary->message; - return; - } - iteration_summary.iteration_time_in_seconds = WallTimeInSeconds() - iteration_start_time; iteration_summary.cumulative_time_in_seconds = WallTimeInSeconds() - start_time + summary->preprocessor_time_in_seconds; summary->iterations.push_back(iteration_summary); + + // If the step was successful, check for the gradient norm + // collapsing to zero, and if the step is unsuccessful then check + // if the trust region radius has collapsed to zero. + // + // For correctness (Number of IterationSummary objects, correct + // final cost, and state update) these convergence tests need to + // be performed at the end of the iteration. + if (iteration_summary.step_is_successful) { + // Gradient norm can only go down in successful steps. + if (iteration_summary.gradient_max_norm <= options.gradient_tolerance) { + summary->message = StringPrintf("Gradient tolerance reached. " + "Gradient max norm: %e <= %e", + iteration_summary.gradient_max_norm, + options_.gradient_tolerance); + summary->termination_type = CONVERGENCE; + VLOG_IF(1, is_not_silent) << "Terminating: " << summary->message; + return; + } + } else { + // Trust region radius can only go down if the step if + // unsuccessful. + if (iteration_summary.trust_region_radius < + options_.min_trust_region_radius) { + summary->message = "Termination. Minimum trust region radius reached."; + summary->termination_type = CONVERGENCE; + VLOG_IF(1, is_not_silent) << summary->message; + return; + } + } } } diff --git a/extern/libmv/third_party/ceres/internal/ceres/trust_region_minimizer.h b/extern/libmv/third_party/ceres/internal/ceres/trust_region_minimizer.h index 9a022843233..ed52c2642d1 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/trust_region_minimizer.h +++ b/extern/libmv/third_party/ceres/internal/ceres/trust_region_minimizer.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/trust_region_preprocessor.cc b/extern/libmv/third_party/ceres/internal/ceres/trust_region_preprocessor.cc index 22ea1ec8c80..4020e4ca115 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/trust_region_preprocessor.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/trust_region_preprocessor.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -48,12 +48,16 @@ namespace ceres { namespace internal { + +using std::vector; + namespace { ParameterBlockOrdering* CreateDefaultLinearSolverOrdering( const Program& program) { ParameterBlockOrdering* ordering = new ParameterBlockOrdering; - const vector<ParameterBlock*>& parameter_blocks = program.parameter_blocks(); + const vector<ParameterBlock*>& parameter_blocks = + program.parameter_blocks(); for (int i = 0; i < parameter_blocks.size(); ++i) { ordering->AddElementToGroup( const_cast<double*>(parameter_blocks[i]->user_state()), 0); @@ -63,7 +67,7 @@ ParameterBlockOrdering* CreateDefaultLinearSolverOrdering( // Check if all the user supplied values in the parameter blocks are // sane or not, and if the program is feasible or not. -bool IsProgramValid(const Program& program, string* error) { +bool IsProgramValid(const Program& program, std::string* error) { return (program.ParameterBlocksAreFinite(error) && program.IsFeasible(error)); } @@ -80,7 +84,7 @@ void AlternateLinearSolverAndPreconditionerForSchurTypeLinearSolver( options->linear_solver_type = LinearSolver::LinearSolverForZeroEBlocks( linear_solver_type_given); - string message; + std::string message; if (linear_solver_type_given == ITERATIVE_SCHUR) { options->preconditioner_type = Preconditioner::PreconditionerForZeroEBlocks( preconditioner_type_given); diff --git a/extern/libmv/third_party/ceres/internal/ceres/trust_region_preprocessor.h b/extern/libmv/third_party/ceres/internal/ceres/trust_region_preprocessor.h index ba70ff92e73..a6631ab3d40 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/trust_region_preprocessor.h +++ b/extern/libmv/third_party/ceres/internal/ceres/trust_region_preprocessor.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2014 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/trust_region_strategy.cc b/extern/libmv/third_party/ceres/internal/ceres/trust_region_strategy.cc index c68269d0449..2db6a6c899b 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/trust_region_strategy.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/trust_region_strategy.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012, 2013 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: diff --git a/extern/libmv/third_party/ceres/internal/ceres/trust_region_strategy.h b/extern/libmv/third_party/ceres/internal/ceres/trust_region_strategy.h index 998514fbfa5..9560e67459a 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/trust_region_strategy.h +++ b/extern/libmv/third_party/ceres/internal/ceres/trust_region_strategy.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -98,7 +98,7 @@ class TrustRegionStrategy { // name starting with dump_filename_base. If dump_format_type is // CONSOLE then dump_filename_base will be ignored and the linear // system will be written to the standard error. - string dump_filename_base; + std::string dump_filename_base; DumpFormatType dump_format_type; }; diff --git a/extern/libmv/third_party/ceres/internal/ceres/types.cc b/extern/libmv/third_party/ceres/internal/ceres/types.cc index 47102616ee8..f86fb78eb8c 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/types.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/types.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -36,6 +36,8 @@ namespace ceres { +using std::string; + #define CASESTR(x) case x: return #x #define STRENUM(x) if (value == #x) { *type = x; return true;} @@ -97,6 +99,7 @@ const char* SparseLinearAlgebraLibraryTypeToString( CASESTR(SUITE_SPARSE); CASESTR(CX_SPARSE); CASESTR(EIGEN_SPARSE); + CASESTR(NO_SPARSE); default: return "UNKNOWN"; } @@ -109,6 +112,7 @@ bool StringToSparseLinearAlgebraLibraryType( STRENUM(SUITE_SPARSE); STRENUM(CX_SPARSE); STRENUM(EIGEN_SPARSE); + STRENUM(NO_SPARSE); return false; } @@ -280,6 +284,27 @@ bool StringToCovarianceAlgorithmType( return false; } +const char* NumericDiffMethodTypeToString( + NumericDiffMethodType type) { + switch (type) { + CASESTR(CENTRAL); + CASESTR(FORWARD); + CASESTR(RIDDERS); + default: + return "UNKNOWN"; + } +} + +bool StringToNumericDiffMethodType( + string value, + NumericDiffMethodType* type) { + UpperCase(&value); + STRENUM(CENTRAL); + STRENUM(FORWARD); + STRENUM(RIDDERS); + return false; +} + const char* VisibilityClusteringTypeToString( VisibilityClusteringType type) { switch (type) { @@ -338,6 +363,14 @@ bool IsSparseLinearAlgebraLibraryTypeAvailable( #endif } + if (type == EIGEN_SPARSE) { +#ifdef CERES_USE_EIGEN_SPARSE + return true; +#else + return false; +#endif + } + LOG(WARNING) << "Unknown sparse linear algebra library " << type; return false; } diff --git a/extern/libmv/third_party/ceres/internal/ceres/visibility.cc b/extern/libmv/third_party/ceres/internal/ceres/visibility.cc index da8beedc663..55b5322aee6 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/visibility.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/visibility.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -49,6 +49,12 @@ namespace ceres { namespace internal { +using std::make_pair; +using std::max; +using std::pair; +using std::set; +using std::vector; + void ComputeVisibility(const CompressedRowBlockStructure& block_structure, const int num_eliminate_blocks, vector< set<int> >* visibility) { diff --git a/extern/libmv/third_party/ceres/internal/ceres/visibility.h b/extern/libmv/third_party/ceres/internal/ceres/visibility.h index 322efe9bea4..142eb2838a1 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/visibility.h +++ b/extern/libmv/third_party/ceres/internal/ceres/visibility.h @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -59,7 +59,7 @@ struct CompressedRowBlockStructure; // points and f_blocks correspond to cameras. void ComputeVisibility(const CompressedRowBlockStructure& block_structure, int num_eliminate_blocks, - vector<set<int> >* visibility); + std::vector<std::set<int> >* visibility); // Given f_block visibility as computed by the ComputeVisibility // function above, construct and return a graph whose vertices are @@ -75,7 +75,7 @@ void ComputeVisibility(const CompressedRowBlockStructure& block_structure, // Caller acquires ownership of the returned WeightedGraph pointer // (heap-allocated). WeightedGraph<int>* CreateSchurComplementGraph( - const vector<set<int> >& visibility); + const std::vector<std::set<int> >& visibility); } // namespace internal } // namespace ceres diff --git a/extern/libmv/third_party/ceres/internal/ceres/visibility_based_preconditioner.cc b/extern/libmv/third_party/ceres/internal/ceres/visibility_based_preconditioner.cc index c7ed0493d8c..b0000cdb1fd 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/visibility_based_preconditioner.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/visibility_based_preconditioner.cc @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -58,6 +58,12 @@ namespace ceres { namespace internal { +using std::make_pair; +using std::pair; +using std::set; +using std::swap; +using std::vector; + // TODO(sameeragarwal): Currently these are magic weights for the // preconditioner construction. Move these higher up into the Options // struct and provide some guidelines for choosing them. @@ -399,7 +405,7 @@ bool VisibilityBasedPreconditioner::UpdateImpl(const BlockSparseMatrix& A, // matrix. Scaling these off-diagonal entries by 1/2 forces this // matrix to be positive definite. void VisibilityBasedPreconditioner::ScaleOffDiagonalCells() { - for (set< pair<int, int> >::const_iterator it = block_pairs_.begin(); + for (set<pair<int, int> >::const_iterator it = block_pairs_.begin(); it != block_pairs_.end(); ++it) { const int block1 = it->first; @@ -439,7 +445,7 @@ LinearSolverTerminationType VisibilityBasedPreconditioner::Factorize() { lhs->stype = 1; // TODO(sameeragarwal): Refactor to pipe this up and out. - string status; + std::string status; // Symbolic factorization is computed if we don't already have one handy. if (factor_ == NULL) { @@ -464,7 +470,7 @@ void VisibilityBasedPreconditioner::RightMultiply(const double* x, const int num_rows = m_->num_rows(); memcpy(CHECK_NOTNULL(tmp_rhs_)->x, x, m_->num_rows() * sizeof(*x)); // TODO(sameeragarwal): Better error handling. - string status; + std::string status; cholmod_dense* solution = CHECK_NOTNULL(ss->Solve(factor_, tmp_rhs_, &status)); memcpy(y, solution->x, sizeof(*y) * num_rows); @@ -484,7 +490,7 @@ bool VisibilityBasedPreconditioner::IsBlockPairInPreconditioner( int cluster1 = cluster_membership_[block1]; int cluster2 = cluster_membership_[block2]; if (cluster1 > cluster2) { - std::swap(cluster1, cluster2); + swap(cluster1, cluster2); } return (cluster_pairs_.count(make_pair(cluster1, cluster2)) > 0); } 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 2f6922dce54..a627c13523c 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 @@ -1,6 +1,6 @@ // 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/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -151,15 +151,16 @@ class VisibilityBasedPreconditioner : public BlockSparseMatrixPreconditioner { LinearSolverTerminationType Factorize(); void ScaleOffDiagonalCells(); - void ClusterCameras(const vector< set<int> >& visibility); + void ClusterCameras(const std::vector<std::set<int> >& visibility); void FlattenMembershipMap(const HashMap<int, int>& membership_map, - vector<int>* membership_vector) const; - void ComputeClusterVisibility(const vector<set<int> >& visibility, - vector<set<int> >* cluster_visibility) const; + std::vector<int>* membership_vector) const; + void ComputeClusterVisibility( + const std::vector<std::set<int> >& visibility, + std::vector<std::set<int> >* cluster_visibility) const; WeightedGraph<int>* CreateClusterGraph( - const vector<set<int> >& visibility) const; + const std::vector<std::set<int> >& visibility) const; void ForestToClusterPairs(const WeightedGraph<int>& forest, - HashSet<pair<int, int> >* cluster_pairs) const; + HashSet<std::pair<int, int> >* cluster_pairs) const; void ComputeBlockPairsInPreconditioner(const CompressedRowBlockStructure& bs); bool IsBlockPairInPreconditioner(int block1, int block2) const; bool IsBlockPairOffDiagonal(int block1, int block2) const; @@ -171,19 +172,19 @@ class VisibilityBasedPreconditioner : public BlockSparseMatrixPreconditioner { int num_clusters_; // Sizes of the blocks in the schur complement. - vector<int> block_size_; + std::vector<int> block_size_; // Mapping from cameras to clusters. - vector<int> cluster_membership_; + std::vector<int> cluster_membership_; // Non-zero camera pairs from the schur complement matrix that are // present in the preconditioner, sorted by row (first element of // each pair), then column (second). - set<pair<int, int> > block_pairs_; + std::set<std::pair<int, int> > block_pairs_; // Set of cluster pairs (including self pairs (i,i)) in the // preconditioner. - HashSet<pair<int, int> > cluster_pairs_; + HashSet<std::pair<int, int> > cluster_pairs_; scoped_ptr<SchurEliminatorBase> eliminator_; // Preconditioner matrix. diff --git a/extern/libmv/third_party/ceres/internal/ceres/wall_time.cc b/extern/libmv/third_party/ceres/internal/ceres/wall_time.cc index 85c4417552d..c353973cc3e 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/wall_time.cc +++ b/extern/libmv/third_party/ceres/internal/ceres/wall_time.cc @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -59,7 +59,7 @@ double WallTimeInSeconds() { #endif } -EventLogger::EventLogger(const string& logger_name) +EventLogger::EventLogger(const std::string& logger_name) : start_time_(WallTimeInSeconds()), last_event_time_(start_time_), events_("") { @@ -75,7 +75,7 @@ EventLogger::~EventLogger() { } } -void EventLogger::AddEvent(const string& event_name) { +void EventLogger::AddEvent(const std::string& event_name) { if (!VLOG_IS_ON(3)) { return; } diff --git a/extern/libmv/third_party/ceres/internal/ceres/wall_time.h b/extern/libmv/third_party/ceres/internal/ceres/wall_time.h index 37f5568a125..966aa67cab6 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/wall_time.h +++ b/extern/libmv/third_party/ceres/internal/ceres/wall_time.h @@ -1,6 +1,6 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2012 Google Inc. All rights reserved. -// http://code.google.com/p/ceres-solver/ +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -72,14 +72,14 @@ double WallTimeInSeconds(); // Total: time3 time1 + time2 + time3; class EventLogger { public: - explicit EventLogger(const string& logger_name); + explicit EventLogger(const std::string& logger_name); ~EventLogger(); - void AddEvent(const string& event_name); + void AddEvent(const std::string& event_name); private: const double start_time_; double last_event_time_; - string events_; + std::string events_; }; } // namespace internal |