From 7c4e8a454e7254bc5647a0a0f955dc2b6b10e1c5 Mon Sep 17 00:00:00 2001 From: Keir Mierle Date: Fri, 30 Mar 2018 16:16:59 -0700 Subject: [PATCH] Replace scoped_ptr with C++11's unique_ptr Change-Id: Ib5a504c491e3a79af52a95accf009df473470c6b --- cmake/config.h.in | 3 - docs/source/numerical_derivatives.rst | 2 +- include/ceres/autodiff_cost_function.h | 4 +- .../ceres/autodiff_local_parameterization.h | 4 +- include/ceres/conditioned_cost_function.h | 4 +- include/ceres/cost_function_to_functor.h | 1 - include/ceres/covariance.h | 4 +- .../ceres/dynamic_autodiff_cost_function.h | 4 +- .../ceres/dynamic_cost_function_to_functor.h | 4 +- .../dynamic_numeric_diff_cost_function.h | 4 +- include/ceres/gradient_checker.h | 6 +- include/ceres/gradient_problem.h | 8 +- include/ceres/internal/numeric_diff.h | 1 - include/ceres/internal/port.h | 6 - include/ceres/internal/scoped_ptr.h | 310 ------------------ include/ceres/local_parameterization.h | 1 - include/ceres/loss_function.h | 8 +- include/ceres/numeric_diff_cost_function.h | 4 +- include/ceres/problem.h | 4 +- internal/ceres/autodiff_cost_function_test.cc | 3 +- internal/ceres/block_jacobi_preconditioner.h | 4 +- .../ceres/block_jacobi_preconditioner_test.cc | 8 +- internal/ceres/block_jacobian_writer.cc | 1 - .../ceres/block_random_access_dense_matrix.cc | 1 - .../ceres/block_random_access_dense_matrix.h | 6 +- .../block_random_access_diagonal_matrix.cc | 2 +- .../block_random_access_diagonal_matrix.h | 9 +- ...lock_random_access_diagonal_matrix_test.cc | 3 +- .../block_random_access_sparse_matrix.cc | 3 +- .../ceres/block_random_access_sparse_matrix.h | 7 +- .../block_random_access_sparse_matrix_test.cc | 4 +- internal/ceres/block_sparse_matrix.h | 6 +- internal/ceres/block_sparse_matrix_test.cc | 18 +- internal/ceres/cgnr_linear_operator.h | 4 +- internal/ceres/cgnr_solver.cc | 3 +- internal/ceres/cgnr_solver.h | 4 +- .../compressed_row_sparse_matrix_test.cc | 32 +- .../ceres/conjugate_gradients_solver_test.cc | 6 +- .../ceres/coordinate_descent_minimizer.cc | 6 +- .../ceres/cost_function_to_functor_test.cc | 26 +- internal/ceres/covariance_impl.cc | 7 +- internal/ceres/covariance_impl.h | 4 +- internal/ceres/covariance_test.cc | 4 +- internal/ceres/cubic_interpolation_test.cc | 6 +- internal/ceres/dense_linear_solver_test.cc | 6 +- .../ceres/dense_normal_cholesky_solver.cc | 1 - internal/ceres/dense_qr_solver.cc | 2 - internal/ceres/dense_sparse_matrix.h | 3 +- internal/ceres/dense_sparse_matrix_test.cc | 8 +- internal/ceres/dogleg_strategy_test.cc | 16 +- .../dynamic_autodiff_cost_function_test.cc | 6 +- ...namic_compressed_row_sparse_matrix_test.cc | 8 +- ...dynamic_numeric_diff_cost_function_test.cc | 4 +- .../dynamic_sparse_normal_cholesky_solver.cc | 4 +- ...amic_sparse_normal_cholesky_solver_test.cc | 12 +- internal/ceres/evaluation_callback_test.cc | 4 +- internal/ceres/evaluator_test.cc | 14 +- .../ceres/gradient_checking_cost_function.cc | 1 - .../gradient_checking_cost_function_test.cc | 11 +- internal/ceres/gradient_problem_solver.cc | 8 +- internal/ceres/graph_algorithms_test.cc | 9 +- internal/ceres/graph_test.cc | 1 - internal/ceres/implicit_schur_complement.cc | 1 - internal/ceres/implicit_schur_complement.h | 8 +- .../ceres/implicit_schur_complement_test.cc | 12 +- internal/ceres/inner_product_computer.h | 4 +- internal/ceres/inner_product_computer_test.cc | 10 +- .../iterative_schur_complement_solver.cc | 1 - .../ceres/iterative_schur_complement_solver.h | 6 +- .../iterative_schur_complement_solver_test.cc | 12 +- .../levenberg_marquardt_strategy_test.cc | 4 +- internal/ceres/line_search_minimizer.cc | 6 +- .../ceres/linear_least_squares_problems.cc | 9 +- .../ceres/linear_least_squares_problems.h | 15 +- internal/ceres/local_parameterization_test.cc | 10 +- internal/ceres/normal_prior.cc | 1 - .../ceres/numeric_diff_cost_function_test.cc | 41 +-- internal/ceres/parameter_block.h | 10 +- internal/ceres/parameter_block_ordering.cc | 9 +- .../ceres/parameter_block_ordering_test.cc | 15 +- .../ceres/partitioned_matrix_view_test.cc | 12 +- internal/ceres/preprocessor.h | 11 +- internal/ceres/problem_impl.cc | 6 +- internal/ceres/problem_impl.h | 4 +- internal/ceres/problem_test.cc | 4 +- internal/ceres/program.cc | 6 +- internal/ceres/program_evaluator.h | 14 +- internal/ceres/program_test.cc | 22 +- internal/ceres/reorder_program.cc | 7 +- internal/ceres/residual_block.h | 4 +- internal/ceres/residual_block_utils_test.cc | 4 +- internal/ceres/schur_complement_solver.cc | 8 +- internal/ceres/schur_complement_solver.h | 12 +- .../ceres/schur_complement_solver_test.cc | 14 +- internal/ceres/schur_eliminator.h | 7 +- internal/ceres/schur_eliminator_impl.h | 2 +- internal/ceres/schur_eliminator_test.cc | 12 +- internal/ceres/schur_jacobi_preconditioner.cc | 2 +- internal/ceres/schur_jacobi_preconditioner.h | 9 +- internal/ceres/scratch_evaluate_preparer.h | 4 +- internal/ceres/solver.cc | 10 +- internal/ceres/solver_test.cc | 4 +- internal/ceres/sparse_cholesky.h | 2 +- internal/ceres/sparse_cholesky_test.cc | 12 +- .../ceres/sparse_normal_cholesky_solver.cc | 4 +- .../ceres/sparse_normal_cholesky_solver.h | 4 +- .../sparse_normal_cholesky_solver_test.cc | 12 +- internal/ceres/subset_preconditioner.cc | 4 +- internal/ceres/subset_preconditioner.h | 6 +- internal/ceres/subset_preconditioner_test.cc | 12 +- .../tiny_solver_cost_function_adapter_test.cc | 4 +- internal/ceres/triplet_sparse_matrix.cc | 2 +- internal/ceres/triplet_sparse_matrix.h | 8 +- internal/ceres/triplet_sparse_matrix_test.cc | 6 +- internal/ceres/trust_region_minimizer.cc | 3 +- internal/ceres/trust_region_minimizer.h | 4 +- .../ceres/visibility_based_preconditioner.cc | 11 +- .../ceres/visibility_based_preconditioner.h | 9 +- .../visibility_based_preconditioner_test.cc | 16 +- internal/ceres/visibility_test.cc | 7 +- 120 files changed, 427 insertions(+), 728 deletions(-) delete mode 100644 include/ceres/internal/scoped_ptr.h diff --git a/cmake/config.h.in b/cmake/config.h.in index c71205069..32c4a524a 100644 --- a/cmake/config.h.in +++ b/cmake/config.h.in @@ -69,9 +69,6 @@ // If defined Ceres was compiled with C++11 thread support. @CERES_USE_CXX11_THREADS@ -// If defined, the memory header is in , otherwise . -@CERES_TR1_MEMORY_HEADER@ - // If defined, Ceres was built as a shared library. @CERES_USING_SHARED_LIBRARY@ diff --git a/docs/source/numerical_derivatives.rst b/docs/source/numerical_derivatives.rst index c52c0394c..9edc00834 100644 --- a/docs/source/numerical_derivatives.rst +++ b/docs/source/numerical_derivatives.rst @@ -125,7 +125,7 @@ like the following: } private: - scoped_ptr functor_; + std::unique_ptr functor_; }; diff --git a/include/ceres/autodiff_cost_function.h b/include/ceres/autodiff_cost_function.h index 490fb3dd0..a106e3e44 100644 --- a/include/ceres/autodiff_cost_function.h +++ b/include/ceres/autodiff_cost_function.h @@ -129,8 +129,8 @@ #ifndef CERES_PUBLIC_AUTODIFF_COST_FUNCTION_H_ #define CERES_PUBLIC_AUTODIFF_COST_FUNCTION_H_ +#include #include "ceres/internal/autodiff.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/sized_cost_function.h" #include "ceres/types.h" #include "glog/logging.h" @@ -219,7 +219,7 @@ class AutoDiffCostFunction : public SizedCostFunction functor_; + std::unique_ptr functor_; }; } // namespace ceres diff --git a/include/ceres/autodiff_local_parameterization.h b/include/ceres/autodiff_local_parameterization.h index 27397e20d..257e9372d 100644 --- a/include/ceres/autodiff_local_parameterization.h +++ b/include/ceres/autodiff_local_parameterization.h @@ -33,9 +33,9 @@ #ifndef CERES_PUBLIC_AUTODIFF_LOCAL_PARAMETERIZATION_H_ #define CERES_PUBLIC_AUTODIFF_LOCAL_PARAMETERIZATION_H_ +#include #include "ceres/local_parameterization.h" #include "ceres/internal/autodiff.h" -#include "ceres/internal/scoped_ptr.h" namespace ceres { @@ -146,7 +146,7 @@ class AutoDiffLocalParameterization : public LocalParameterization { virtual int LocalSize() const { return kLocalSize; } private: - internal::scoped_ptr functor_; + std::unique_ptr functor_; }; } // namespace ceres diff --git a/include/ceres/conditioned_cost_function.h b/include/ceres/conditioned_cost_function.h index 29597d935..e5f5fc45f 100644 --- a/include/ceres/conditioned_cost_function.h +++ b/include/ceres/conditioned_cost_function.h @@ -36,8 +36,8 @@ #include +#include #include "ceres/cost_function.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/types.h" #include "ceres/internal/disable_warnings.h" @@ -87,7 +87,7 @@ class CERES_EXPORT ConditionedCostFunction : public CostFunction { double** jacobians) const; private: - internal::scoped_ptr wrapped_cost_function_; + std::unique_ptr wrapped_cost_function_; std::vector conditioners_; Ownership ownership_; }; diff --git a/include/ceres/cost_function_to_functor.h b/include/ceres/cost_function_to_functor.h index d2dc94725..8e3054338 100644 --- a/include/ceres/cost_function_to_functor.h +++ b/include/ceres/cost_function_to_functor.h @@ -94,7 +94,6 @@ #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" namespace ceres { diff --git a/include/ceres/covariance.h b/include/ceres/covariance.h index 685e9f095..971175ce5 100644 --- a/include/ceres/covariance.h +++ b/include/ceres/covariance.h @@ -31,11 +31,11 @@ #ifndef CERES_PUBLIC_COVARIANCE_H_ #define CERES_PUBLIC_COVARIANCE_H_ +#include #include #include #include "ceres/internal/disable_warnings.h" #include "ceres/internal/port.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/types.h" namespace ceres { @@ -457,7 +457,7 @@ class CERES_EXPORT Covariance { double* covariance_matrix); private: - internal::scoped_ptr impl_; + std::unique_ptr impl_; }; } // namespace ceres diff --git a/include/ceres/dynamic_autodiff_cost_function.h b/include/ceres/dynamic_autodiff_cost_function.h index 4a31236c4..f1eb0d3d6 100644 --- a/include/ceres/dynamic_autodiff_cost_function.h +++ b/include/ceres/dynamic_autodiff_cost_function.h @@ -36,8 +36,8 @@ #include #include +#include #include "ceres/dynamic_cost_function.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/jet.h" #include "glog/logging.h" @@ -244,7 +244,7 @@ class DynamicAutoDiffCostFunction : public DynamicCostFunction { } private: - internal::scoped_ptr functor_; + std::unique_ptr functor_; }; } // namespace ceres diff --git a/include/ceres/dynamic_cost_function_to_functor.h b/include/ceres/dynamic_cost_function_to_functor.h index 10bc99aaa..f6ff88874 100644 --- a/include/ceres/dynamic_cost_function_to_functor.h +++ b/include/ceres/dynamic_cost_function_to_functor.h @@ -32,13 +32,13 @@ #ifndef CERES_PUBLIC_DYNAMIC_COST_FUNCTION_TO_FUNCTOR_H_ #define CERES_PUBLIC_DYNAMIC_COST_FUNCTION_TO_FUNCTOR_H_ +#include #include #include #include "ceres/dynamic_cost_function.h" #include "ceres/internal/fixed_array.h" #include "ceres/internal/port.h" -#include "ceres/internal/scoped_ptr.h" namespace ceres { @@ -182,7 +182,7 @@ class DynamicCostFunctionToFunctor { } private: - internal::scoped_ptr cost_function_; + std::unique_ptr cost_function_; }; } // namespace ceres diff --git a/include/ceres/dynamic_numeric_diff_cost_function.h b/include/ceres/dynamic_numeric_diff_cost_function.h index a011ac3ca..4c2766f57 100644 --- a/include/ceres/dynamic_numeric_diff_cost_function.h +++ b/include/ceres/dynamic_numeric_diff_cost_function.h @@ -35,11 +35,11 @@ #define CERES_PUBLIC_DYNAMIC_NUMERIC_DIFF_COST_FUNCTION_H_ #include +#include #include #include #include "ceres/dynamic_cost_function.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/internal/eigen.h" #include "ceres/internal/numeric_diff.h" #include "ceres/numeric_diff_options.h" @@ -170,7 +170,7 @@ class DynamicNumericDiffCostFunction : public DynamicCostFunction { return functor->Evaluate(parameters, residuals, NULL); } - internal::scoped_ptr functor_; + std::unique_ptr functor_; Ownership ownership_; NumericDiffOptions options_; }; diff --git a/include/ceres/gradient_checker.h b/include/ceres/gradient_checker.h index c8ac729fd..48f7bc414 100644 --- a/include/ceres/gradient_checker.h +++ b/include/ceres/gradient_checker.h @@ -34,15 +34,15 @@ #ifndef CERES_PUBLIC_GRADIENT_CHECKER_H_ #define CERES_PUBLIC_GRADIENT_CHECKER_H_ -#include +#include #include +#include #include "ceres/cost_function.h" #include "ceres/dynamic_numeric_diff_cost_function.h" #include "ceres/internal/eigen.h" #include "ceres/internal/fixed_array.h" #include "ceres/internal/macros.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/local_parameterization.h" #include "glog/logging.h" @@ -141,7 +141,7 @@ class CERES_EXPORT GradientChecker { std::vector local_parameterizations_; const CostFunction* function_; - internal::scoped_ptr finite_diff_cost_function_; + std::unique_ptr finite_diff_cost_function_; }; } // namespace ceres diff --git a/include/ceres/gradient_problem.h b/include/ceres/gradient_problem.h index 1226a4cd8..2a08c5d2e 100644 --- a/include/ceres/gradient_problem.h +++ b/include/ceres/gradient_problem.h @@ -31,9 +31,9 @@ #ifndef CERES_PUBLIC_GRADIENT_PROBLEM_H_ #define CERES_PUBLIC_GRADIENT_PROBLEM_H_ +#include #include "ceres/internal/macros.h" #include "ceres/internal/port.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/local_parameterization.h" namespace ceres { @@ -105,9 +105,9 @@ class CERES_EXPORT GradientProblem { bool Plus(const double* x, const double* delta, double* x_plus_delta) const; private: - internal::scoped_ptr function_; - internal::scoped_ptr parameterization_; - internal::scoped_array scratch_; + std::unique_ptr function_; + std::unique_ptr parameterization_; + std::unique_ptr scratch_; }; // A FirstOrderFunction object implements the evaluation of a function diff --git a/include/ceres/internal/numeric_diff.h b/include/ceres/internal/numeric_diff.h index 11e8275b1..ab1abc0c6 100644 --- a/include/ceres/internal/numeric_diff.h +++ b/include/ceres/internal/numeric_diff.h @@ -41,7 +41,6 @@ #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" diff --git a/include/ceres/internal/port.h b/include/ceres/internal/port.h index f0f706c64..9aa041ae7 100644 --- a/include/ceres/internal/port.h +++ b/include/ceres/internal/port.h @@ -56,12 +56,6 @@ # error One of CERES_USE_OPENMP, CERES_USE_TBB,CERES_USE_CXX11_THREADS or CERES_NO_THREADS must be defined. #endif -#if defined(CERES_TR1_MEMORY_HEADER) -#include -#else -#include -#endif - namespace ceres { // We allocate some Eigen objects on the stack and other places they diff --git a/include/ceres/internal/scoped_ptr.h b/include/ceres/internal/scoped_ptr.h deleted file mode 100644 index fa0ac25a0..000000000 --- a/include/ceres/internal/scoped_ptr.h +++ /dev/null @@ -1,310 +0,0 @@ -// 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: jorg@google.com (Jorg Brown) -// -// This is an implementation designed to match the anticipated future TR2 -// implementation of the scoped_ptr class, and its closely-related brethren, -// scoped_array, scoped_ptr_malloc, and make_scoped_ptr. - -#ifndef CERES_PUBLIC_INTERNAL_SCOPED_PTR_H_ -#define CERES_PUBLIC_INTERNAL_SCOPED_PTR_H_ - -#include -#include -#include -#include - -namespace ceres { -namespace internal { - -template class scoped_ptr; -template class scoped_ptr_malloc; -template class scoped_array; - -template -scoped_ptr make_scoped_ptr(C *); - -// A scoped_ptr is like a T*, except that the destructor of -// scoped_ptr automatically deletes the pointer it holds (if -// any). That is, scoped_ptr owns the T object that it points -// to. Like a T*, a scoped_ptr may hold either NULL or a pointer to -// a T object. Also like T*, scoped_ptr is thread-compatible, and -// once you dereference it, you get the threadsafety guarantees of T. -// -// The size of a scoped_ptr is small: sizeof(scoped_ptr) == sizeof(C*) -template -class scoped_ptr { - public: - // The element type - typedef C element_type; - - // Constructor. Defaults to intializing with NULL. - // There is no way to create an uninitialized scoped_ptr. - // The input parameter must be allocated with new. - explicit scoped_ptr(C* p = NULL) : ptr_(p) { } - - // Destructor. If there is a C object, delete it. - // We don't need to test ptr_ == NULL because C++ does that for us. - ~scoped_ptr() { - enum { type_must_be_complete = sizeof(C) }; - delete ptr_; - } - - // Reset. Deletes the current owned object, if any. - // Then takes ownership of a new object, if given. - // this->reset(this->get()) works. - void reset(C* p = NULL) { - if (p != ptr_) { - enum { type_must_be_complete = sizeof(C) }; - delete ptr_; - ptr_ = p; - } - } - - // Accessors to get the owned object. - // operator* and operator-> will assert() if there is no current object. - C& operator*() const { - assert(ptr_ != NULL); - return *ptr_; - } - C* operator->() const { - assert(ptr_ != NULL); - return ptr_; - } - C* get() const { return ptr_; } - - // Comparison operators. - // These return whether a scoped_ptr and a raw pointer refer to - // the same object, not just to two different but equal objects. - bool operator==(const C* p) const { return ptr_ == p; } - bool operator!=(const C* p) const { return ptr_ != p; } - - // Swap two scoped pointers. - void swap(scoped_ptr& p2) { - C* tmp = ptr_; - ptr_ = p2.ptr_; - p2.ptr_ = tmp; - } - - // Release a pointer. - // The return value is the current pointer held by this object. - // If this object holds a NULL pointer, the return value is NULL. - // After this operation, this object will hold a NULL pointer, - // and will not own the object any more. - C* release() { - C* retVal = ptr_; - ptr_ = NULL; - return retVal; - } - - private: - C* ptr_; - - // google3 friend class that can access copy ctor (although if it actually - // calls a copy ctor, there will be a problem) see below - friend scoped_ptr make_scoped_ptr(C *p); - - // Forbid comparison of scoped_ptr types. If C2 != C, it totally doesn't - // make sense, and if C2 == C, it still doesn't make sense because you should - // never have the same object owned by two different scoped_ptrs. - template bool operator==(scoped_ptr const& p2) const; - template bool operator!=(scoped_ptr const& p2) const; - - // Disallow evil constructors - scoped_ptr(const scoped_ptr&); - void operator=(const scoped_ptr&); -}; - -// Free functions -template -inline void swap(scoped_ptr& p1, scoped_ptr& p2) { - p1.swap(p2); -} - -template -inline bool operator==(const C* p1, const scoped_ptr& p2) { - return p1 == p2.get(); -} - -template -inline bool operator==(const C* p1, const scoped_ptr& p2) { - return p1 == p2.get(); -} - -template -inline bool operator!=(const C* p1, const scoped_ptr& p2) { - return p1 != p2.get(); -} - -template -inline bool operator!=(const C* p1, const scoped_ptr& p2) { - return p1 != p2.get(); -} - -template -scoped_ptr make_scoped_ptr(C *p) { - // This does nothing but to return a scoped_ptr of the type that the passed - // pointer is of. (This eliminates the need to specify the name of T when - // making a scoped_ptr that is used anonymously/temporarily.) From an - // access control point of view, we construct an unnamed scoped_ptr here - // which we return and thus copy-construct. Hence, we need to have access - // to scoped_ptr::scoped_ptr(scoped_ptr const &). However, it is guaranteed - // that we never actually call the copy constructor, which is a good thing - // as we would call the temporary's object destructor (and thus delete p) - // if we actually did copy some object, here. - return scoped_ptr(p); -} - -// scoped_array is like scoped_ptr, except that the caller must allocate -// with new [] and the destructor deletes objects with delete []. -// -// As with scoped_ptr, a scoped_array either points to an object -// or is NULL. A scoped_array owns the object that it points to. -// scoped_array is thread-compatible, and once you index into it, -// the returned objects have only the threadsafety guarantees of T. -// -// Size: sizeof(scoped_array) == sizeof(C*) -template -class scoped_array { - public: - // The element type - typedef C element_type; - - // Constructor. Defaults to intializing with NULL. - // There is no way to create an uninitialized scoped_array. - // The input parameter must be allocated with new []. - explicit scoped_array(C* p = NULL) : array_(p) { } - - // Destructor. If there is a C object, delete it. - // We don't need to test ptr_ == NULL because C++ does that for us. - ~scoped_array() { - enum { type_must_be_complete = sizeof(C) }; - delete[] array_; - } - - // Reset. Deletes the current owned object, if any. - // Then takes ownership of a new object, if given. - // this->reset(this->get()) works. - void reset(C* p = NULL) { - if (p != array_) { - enum { type_must_be_complete = sizeof(C) }; - delete[] array_; - array_ = p; - } - } - - // Get one element of the current object. - // Will assert() if there is no current object, or index i is negative. - C& operator[](std::ptrdiff_t i) const { - assert(i >= 0); - assert(array_ != NULL); - return array_[i]; - } - - // Get a pointer to the zeroth element of the current object. - // If there is no current object, return NULL. - C* get() const { - return array_; - } - - // Comparison operators. - // These return whether a scoped_array and a raw pointer refer to - // the same array, not just to two different but equal arrays. - bool operator==(const C* p) const { return array_ == p; } - bool operator!=(const C* p) const { return array_ != p; } - - // Swap two scoped arrays. - void swap(scoped_array& p2) { - C* tmp = array_; - array_ = p2.array_; - p2.array_ = tmp; - } - - // Release an array. - // The return value is the current pointer held by this object. - // If this object holds a NULL pointer, the return value is NULL. - // After this operation, this object will hold a NULL pointer, - // and will not own the object any more. - C* release() { - C* retVal = array_; - array_ = NULL; - return retVal; - } - - private: - C* array_; - - // Forbid comparison of different scoped_array types. - template bool operator==(scoped_array const& p2) const; - template bool operator!=(scoped_array const& p2) const; - - // Disallow evil constructors - scoped_array(const scoped_array&); - void operator=(const scoped_array&); -}; - -// Free functions -template -inline void swap(scoped_array& p1, scoped_array& p2) { - p1.swap(p2); -} - -template -inline bool operator==(const C* p1, const scoped_array& p2) { - return p1 == p2.get(); -} - -template -inline bool operator==(const C* p1, const scoped_array& p2) { - return p1 == p2.get(); -} - -template -inline bool operator!=(const C* p1, const scoped_array& p2) { - return p1 != p2.get(); -} - -template -inline bool operator!=(const C* p1, const scoped_array& p2) { - return p1 != p2.get(); -} - -// This class wraps the c library function free() in a class that can be -// passed as a template argument to scoped_ptr_malloc below. -class ScopedPtrMallocFree { - public: - inline void operator()(void* x) const { - free(x); - } -}; - -} // namespace internal -} // namespace ceres - -#endif // CERES_PUBLIC_INTERNAL_SCOPED_PTR_H_ diff --git a/include/ceres/local_parameterization.h b/include/ceres/local_parameterization.h index 8a4ca562c..fd13c0eae 100644 --- a/include/ceres/local_parameterization.h +++ b/include/ceres/local_parameterization.h @@ -34,7 +34,6 @@ #include #include "ceres/internal/port.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/internal/disable_warnings.h" namespace ceres { diff --git a/include/ceres/loss_function.h b/include/ceres/loss_function.h index 0512c1351..1f057e62b 100644 --- a/include/ceres/loss_function.h +++ b/include/ceres/loss_function.h @@ -75,9 +75,9 @@ #ifndef CERES_PUBLIC_LOSS_FUNCTION_H_ #define CERES_PUBLIC_LOSS_FUNCTION_H_ +#include #include "glog/logging.h" #include "ceres/internal/macros.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/types.h" #include "ceres/internal/disable_warnings.h" @@ -303,7 +303,7 @@ class CERES_EXPORT ComposedLoss : public LossFunction { virtual void Evaluate(double, double*) const; private: - internal::scoped_ptr f_, g_; + std::unique_ptr f_, g_; const Ownership ownership_f_, ownership_g_; }; @@ -340,7 +340,7 @@ class CERES_EXPORT ScaledLoss : public LossFunction { virtual void Evaluate(double, double*) const; private: - internal::scoped_ptr rho_; + std::unique_ptr rho_; const double a_; const Ownership ownership_; CERES_DISALLOW_COPY_AND_ASSIGN(ScaledLoss); @@ -416,7 +416,7 @@ class CERES_EXPORT LossFunctionWrapper : public LossFunction { } private: - internal::scoped_ptr rho_; + std::unique_ptr rho_; Ownership ownership_; CERES_DISALLOW_COPY_AND_ASSIGN(LossFunctionWrapper); }; diff --git a/include/ceres/numeric_diff_cost_function.h b/include/ceres/numeric_diff_cost_function.h index 5dfaeab62..7cab26746 100644 --- a/include/ceres/numeric_diff_cost_function.h +++ b/include/ceres/numeric_diff_cost_function.h @@ -161,10 +161,10 @@ #ifndef CERES_PUBLIC_NUMERIC_DIFF_COST_FUNCTION_H_ #define CERES_PUBLIC_NUMERIC_DIFF_COST_FUNCTION_H_ +#include #include "Eigen/Dense" #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" @@ -309,7 +309,7 @@ class NumericDiffCostFunction } private: - internal::scoped_ptr functor_; + std::unique_ptr functor_; Ownership ownership_; NumericDiffOptions options_; }; diff --git a/include/ceres/problem.h b/include/ceres/problem.h index e941fff8e..344685d29 100644 --- a/include/ceres/problem.h +++ b/include/ceres/problem.h @@ -36,6 +36,7 @@ #include #include +#include #include #include @@ -43,7 +44,6 @@ #include "ceres/internal/disable_warnings.h" #include "ceres/internal/macros.h" #include "ceres/internal/port.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/types.h" #include "glog/logging.h" @@ -485,7 +485,7 @@ class CERES_EXPORT Problem { private: friend class Solver; friend class Covariance; - internal::scoped_ptr problem_impl_; + std::unique_ptr problem_impl_; CERES_DISALLOW_COPY_AND_ASSIGN(Problem); }; diff --git a/internal/ceres/autodiff_cost_function_test.cc b/internal/ceres/autodiff_cost_function_test.cc index d14fb8289..1192808bb 100644 --- a/internal/ceres/autodiff_cost_function_test.cc +++ b/internal/ceres/autodiff_cost_function_test.cc @@ -31,6 +31,7 @@ #include "ceres/autodiff_cost_function.h" #include +#include #include "gtest/gtest.h" #include "ceres/cost_function.h" @@ -158,7 +159,7 @@ TEST(AutoDiffCostFunction, PartiallyFilledResidualShouldFailEvaluation) { double* parameters[] = {¶meter}; double* jacobians[] = {jacobian}; - scoped_ptr cost_function( + std::unique_ptr cost_function( new AutoDiffCostFunction( new OnlyFillsOneOutputFunctor)); InvalidateArray(2, jacobian); diff --git a/internal/ceres/block_jacobi_preconditioner.h b/internal/ceres/block_jacobi_preconditioner.h index 0541db50c..a67879aa6 100644 --- a/internal/ceres/block_jacobi_preconditioner.h +++ b/internal/ceres/block_jacobi_preconditioner.h @@ -31,8 +31,8 @@ #ifndef CERES_INTERNAL_BLOCK_JACOBI_PRECONDITIONER_H_ #define CERES_INTERNAL_BLOCK_JACOBI_PRECONDITIONER_H_ +#include #include "ceres/block_random_access_diagonal_matrix.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/preconditioner.h" namespace ceres { @@ -66,7 +66,7 @@ class BlockJacobiPreconditioner : public BlockSparseMatrixPreconditioner { private: virtual bool UpdateImpl(const BlockSparseMatrix& A, const double* D); - scoped_ptr m_; + std::unique_ptr m_; }; } // namespace internal diff --git a/internal/ceres/block_jacobi_preconditioner_test.cc b/internal/ceres/block_jacobi_preconditioner_test.cc index 0fb9dc693..80e5fbacb 100644 --- a/internal/ceres/block_jacobi_preconditioner_test.cc +++ b/internal/ceres/block_jacobi_preconditioner_test.cc @@ -30,11 +30,11 @@ #include "ceres/block_jacobi_preconditioner.h" +#include #include #include "ceres/block_random_access_diagonal_matrix.h" #include "ceres/linear_least_squares_problems.h" #include "ceres/block_sparse_matrix.h" -#include "ceres/internal/scoped_ptr.h" #include "gtest/gtest.h" #include "Eigen/Dense" @@ -45,7 +45,7 @@ namespace internal { class BlockJacobiPreconditionerTest : public ::testing::Test { protected: void SetUpFromProblemId(int problem_id) { - scoped_ptr problem( + std::unique_ptr problem( CreateLinearLeastSquaresProblemFromId(problem_id)); CHECK_NOTNULL(problem.get()); @@ -88,8 +88,8 @@ class BlockJacobiPreconditionerTest : public ::testing::Test { } } - scoped_ptr A; - scoped_array D; + std::unique_ptr A; + std::unique_ptr D; Matrix dense_ata; }; diff --git a/internal/ceres/block_jacobian_writer.cc b/internal/ceres/block_jacobian_writer.cc index 7a3fee4fb..5714ada84 100644 --- a/internal/ceres/block_jacobian_writer.cc +++ b/internal/ceres/block_jacobian_writer.cc @@ -37,7 +37,6 @@ #include "ceres/residual_block.h" #include "ceres/internal/eigen.h" #include "ceres/internal/port.h" -#include "ceres/internal/scoped_ptr.h" namespace ceres { namespace internal { diff --git a/internal/ceres/block_random_access_dense_matrix.cc b/internal/ceres/block_random_access_dense_matrix.cc index 61748ef6f..f567aa581 100644 --- a/internal/ceres/block_random_access_dense_matrix.cc +++ b/internal/ceres/block_random_access_dense_matrix.cc @@ -32,7 +32,6 @@ #include #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "glog/logging.h" namespace ceres { diff --git a/internal/ceres/block_random_access_dense_matrix.h b/internal/ceres/block_random_access_dense_matrix.h index 896890825..161dab24d 100644 --- a/internal/ceres/block_random_access_dense_matrix.h +++ b/internal/ceres/block_random_access_dense_matrix.h @@ -33,11 +33,11 @@ #include "ceres/block_random_access_matrix.h" +#include #include #include "ceres/internal/macros.h" #include "ceres/internal/port.h" -#include "ceres/internal/scoped_ptr.h" namespace ceres { namespace internal { @@ -86,8 +86,8 @@ class BlockRandomAccessDenseMatrix : public BlockRandomAccessMatrix { private: int num_rows_; std::vector block_layout_; - scoped_array values_; - scoped_array cell_infos_; + std::unique_ptr values_; + std::unique_ptr cell_infos_; CERES_DISALLOW_COPY_AND_ASSIGN(BlockRandomAccessDenseMatrix); }; diff --git a/internal/ceres/block_random_access_diagonal_matrix.cc b/internal/ceres/block_random_access_diagonal_matrix.cc index 052690d18..9866e7536 100644 --- a/internal/ceres/block_random_access_diagonal_matrix.cc +++ b/internal/ceres/block_random_access_diagonal_matrix.cc @@ -34,9 +34,9 @@ #include #include #include + #include "Eigen/Dense" #include "ceres/internal/port.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/stl_util.h" #include "ceres/triplet_sparse_matrix.h" #include "ceres/types.h" diff --git a/internal/ceres/block_random_access_diagonal_matrix.h b/internal/ceres/block_random_access_diagonal_matrix.h index 62e17e81a..fd43eb00d 100644 --- a/internal/ceres/block_random_access_diagonal_matrix.h +++ b/internal/ceres/block_random_access_diagonal_matrix.h @@ -31,15 +31,16 @@ #ifndef CERES_INTERNAL_BLOCK_RANDOM_ACCESS_DIAGONAL_MATRIX_H_ #define CERES_INTERNAL_BLOCK_RANDOM_ACCESS_DIAGONAL_MATRIX_H_ +#include #include -#include #include +#include + #include "ceres/block_random_access_matrix.h" -#include "ceres/triplet_sparse_matrix.h" #include "ceres/integral_types.h" #include "ceres/internal/macros.h" #include "ceres/internal/port.h" -#include "ceres/internal/scoped_ptr.h" +#include "ceres/triplet_sparse_matrix.h" #include "ceres/types.h" namespace ceres { @@ -87,7 +88,7 @@ class BlockRandomAccessDiagonalMatrix : public BlockRandomAccessMatrix { std::vector layout_; // The underlying matrix object which actually stores the cells. - scoped_ptr tsm_; + std::unique_ptr tsm_; friend class BlockRandomAccessDiagonalMatrixTest; CERES_DISALLOW_COPY_AND_ASSIGN(BlockRandomAccessDiagonalMatrix); diff --git a/internal/ceres/block_random_access_diagonal_matrix_test.cc b/internal/ceres/block_random_access_diagonal_matrix_test.cc index 8fa3798c3..a54595cf5 100644 --- a/internal/ceres/block_random_access_diagonal_matrix_test.cc +++ b/internal/ceres/block_random_access_diagonal_matrix_test.cc @@ -29,6 +29,7 @@ // Author: sameeragarwal@google.com (Sameer Agarwal) #include +#include #include #include "ceres/block_random_access_diagonal_matrix.h" @@ -92,7 +93,7 @@ class BlockRandomAccessDiagonalMatrixTest : public ::testing::Test { protected: int num_nonzeros_; - scoped_ptr m_; + std::unique_ptr m_; }; TEST_F(BlockRandomAccessDiagonalMatrixTest, MatrixContents) { diff --git a/internal/ceres/block_random_access_sparse_matrix.cc b/internal/ceres/block_random_access_sparse_matrix.cc index b8b4a75f9..a822d691a 100644 --- a/internal/ceres/block_random_access_sparse_matrix.cc +++ b/internal/ceres/block_random_access_sparse_matrix.cc @@ -31,11 +31,12 @@ #include "ceres/block_random_access_sparse_matrix.h" #include +#include #include #include #include + #include "ceres/internal/port.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/triplet_sparse_matrix.h" #include "ceres/types.h" #include "glog/logging.h" diff --git a/internal/ceres/block_random_access_sparse_matrix.h b/internal/ceres/block_random_access_sparse_matrix.h index c8a8927d2..fb24900bc 100644 --- a/internal/ceres/block_random_access_sparse_matrix.h +++ b/internal/ceres/block_random_access_sparse_matrix.h @@ -31,16 +31,17 @@ #ifndef CERES_INTERNAL_BLOCK_RANDOM_ACCESS_SPARSE_MATRIX_H_ #define CERES_INTERNAL_BLOCK_RANDOM_ACCESS_SPARSE_MATRIX_H_ +#include #include #include -#include #include +#include + #include "ceres/block_random_access_matrix.h" #include "ceres/triplet_sparse_matrix.h" #include "ceres/integral_types.h" #include "ceres/internal/macros.h" #include "ceres/internal/port.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/types.h" #include "ceres/small_blas.h" @@ -116,7 +117,7 @@ class BlockRandomAccessSparseMatrix : public BlockRandomAccessMatrix { // iterator in the Layout object instead. std::vector, double*> > cell_values_; // The underlying matrix object which actually stores the cells. - scoped_ptr tsm_; + std::unique_ptr tsm_; friend class BlockRandomAccessSparseMatrixTest; CERES_DISALLOW_COPY_AND_ASSIGN(BlockRandomAccessSparseMatrix); diff --git a/internal/ceres/block_random_access_sparse_matrix_test.cc b/internal/ceres/block_random_access_sparse_matrix_test.cc index 688b09dc1..c5816d52a 100644 --- a/internal/ceres/block_random_access_sparse_matrix_test.cc +++ b/internal/ceres/block_random_access_sparse_matrix_test.cc @@ -29,7 +29,9 @@ // Author: sameeragarwal@google.com (Sameer Agarwal) #include +#include #include + #include "ceres/block_random_access_sparse_matrix.h" #include "ceres/internal/eigen.h" #include "glog/logging.h" @@ -168,7 +170,7 @@ class BlockRandomAccessSparseMatrixTest : public ::testing::Test { } private: - scoped_ptr m_; + std::unique_ptr m_; }; TEST_F(BlockRandomAccessSparseMatrixTest, IntPairToLongOverflow) { diff --git a/internal/ceres/block_sparse_matrix.h b/internal/ceres/block_sparse_matrix.h index abde2a6ae..b93a6faba 100644 --- a/internal/ceres/block_sparse_matrix.h +++ b/internal/ceres/block_sparse_matrix.h @@ -34,11 +34,11 @@ #ifndef CERES_INTERNAL_BLOCK_SPARSE_MATRIX_H_ #define CERES_INTERNAL_BLOCK_SPARSE_MATRIX_H_ +#include #include "ceres/block_structure.h" #include "ceres/sparse_matrix.h" #include "ceres/internal/eigen.h" #include "ceres/internal/macros.h" -#include "ceres/internal/scoped_ptr.h" namespace ceres { namespace internal { @@ -137,8 +137,8 @@ class BlockSparseMatrix : public SparseMatrix { int num_cols_; int num_nonzeros_; int max_num_nonzeros_; - scoped_array values_; - scoped_ptr block_structure_; + std::unique_ptr values_; + std::unique_ptr block_structure_; CERES_DISALLOW_COPY_AND_ASSIGN(BlockSparseMatrix); }; diff --git a/internal/ceres/block_sparse_matrix_test.cc b/internal/ceres/block_sparse_matrix_test.cc index b3d21d023..50b6766bf 100644 --- a/internal/ceres/block_sparse_matrix_test.cc +++ b/internal/ceres/block_sparse_matrix_test.cc @@ -30,10 +30,10 @@ #include "ceres/block_sparse_matrix.h" +#include #include #include "ceres/casts.h" #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/linear_least_squares_problems.h" #include "ceres/triplet_sparse_matrix.h" #include "glog/logging.h" @@ -45,7 +45,7 @@ namespace internal { class BlockSparseMatrixTest : public ::testing::Test { protected : virtual void SetUp() { - scoped_ptr problem( + std::unique_ptr problem( CreateLinearLeastSquaresProblemFromId(2)); CHECK_NOTNULL(problem.get()); A_.reset(down_cast(problem->A.release())); @@ -59,8 +59,8 @@ class BlockSparseMatrixTest : public ::testing::Test { CHECK_EQ(A_->num_nonzeros(), B_->num_nonzeros()); } - scoped_ptr A_; - scoped_ptr B_; + std::unique_ptr A_; + std::unique_ptr B_; }; TEST_F(BlockSparseMatrixTest, SetZeroTest) { @@ -109,16 +109,16 @@ TEST_F(BlockSparseMatrixTest, ToDenseMatrixTest) { } TEST_F(BlockSparseMatrixTest, AppendRows) { - scoped_ptr problem( + std::unique_ptr problem( CreateLinearLeastSquaresProblemFromId(2)); - scoped_ptr m( + std::unique_ptr m( down_cast(problem->A.release())); A_->AppendRows(*m); EXPECT_EQ(A_->num_rows(), 2 * m->num_rows()); EXPECT_EQ(A_->num_cols(), m->num_cols()); problem.reset(CreateLinearLeastSquaresProblemFromId(1)); - scoped_ptr m2( + std::unique_ptr m2( down_cast(problem->A.release())); B_->AppendRows(*m2); @@ -144,7 +144,7 @@ TEST_F(BlockSparseMatrixTest, AppendAndDeleteBlockDiagonalMatrix) { for (int i = 0; i < num_cols; ++i) { diagonal(i) = 2 * i * i + 1; } - scoped_ptr appendage( + std::unique_ptr appendage( BlockSparseMatrix::CreateDiagonalMatrix(diagonal.data(), column_blocks)); A_->AppendRows(*appendage); @@ -196,7 +196,7 @@ TEST(BlockSparseMatrix, CreateDiagonalMatrix) { diagonal(i) = 2 * i * i + 1; } - scoped_ptr m( + std::unique_ptr m( BlockSparseMatrix::CreateDiagonalMatrix(diagonal.data(), column_blocks)); const CompressedRowBlockStructure* bs = m->block_structure(); EXPECT_EQ(bs->cols.size(), column_blocks.size()); diff --git a/internal/ceres/cgnr_linear_operator.h b/internal/ceres/cgnr_linear_operator.h index 44c07cabd..ad0c6278d 100644 --- a/internal/ceres/cgnr_linear_operator.h +++ b/internal/ceres/cgnr_linear_operator.h @@ -32,8 +32,8 @@ #define CERES_INTERNAL_CGNR_LINEAR_OPERATOR_H_ #include +#include #include "ceres/linear_operator.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/internal/eigen.h" namespace ceres { @@ -111,7 +111,7 @@ class CgnrLinearOperator : public LinearOperator { private: const LinearOperator& A_; const double* D_; - scoped_array z_; + std::unique_ptr z_; }; } // namespace internal diff --git a/internal/ceres/cgnr_solver.cc b/internal/ceres/cgnr_solver.cc index 61fae758d..3a7ed3c08 100644 --- a/internal/ceres/cgnr_solver.cc +++ b/internal/ceres/cgnr_solver.cc @@ -42,8 +42,7 @@ namespace ceres { namespace internal { CgnrSolver::CgnrSolver(const LinearSolver::Options& options) - : options_(options), - preconditioner_(NULL) { + : options_(options) { if (options_.preconditioner_type != JACOBI && options_.preconditioner_type != IDENTITY) { LOG(FATAL) << "CGNR only supports IDENTITY and JACOBI preconditioners."; diff --git a/internal/ceres/cgnr_solver.h b/internal/ceres/cgnr_solver.h index f7a157369..7d9f8efcb 100644 --- a/internal/ceres/cgnr_solver.h +++ b/internal/ceres/cgnr_solver.h @@ -31,7 +31,7 @@ #ifndef CERES_INTERNAL_CGNR_SOLVER_H_ #define CERES_INTERNAL_CGNR_SOLVER_H_ -#include "ceres/internal/scoped_ptr.h" +#include #include "ceres/linear_solver.h" namespace ceres { @@ -59,7 +59,7 @@ class CgnrSolver : public BlockSparseMatrixSolver { private: const LinearSolver::Options options_; - scoped_ptr preconditioner_; + std::unique_ptr preconditioner_; CERES_DISALLOW_COPY_AND_ASSIGN(CgnrSolver); }; diff --git a/internal/ceres/compressed_row_sparse_matrix_test.cc b/internal/ceres/compressed_row_sparse_matrix_test.cc index 8ebf6cff0..4351e3d0c 100644 --- a/internal/ceres/compressed_row_sparse_matrix_test.cc +++ b/internal/ceres/compressed_row_sparse_matrix_test.cc @@ -30,11 +30,11 @@ #include "ceres/compressed_row_sparse_matrix.h" +#include #include #include "ceres/casts.h" #include "ceres/crs_matrix.h" #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/linear_least_squares_problems.h" #include "ceres/random.h" #include "ceres/triplet_sparse_matrix.h" @@ -72,7 +72,7 @@ void CompareMatrices(const SparseMatrix* a, const SparseMatrix* b) { class CompressedRowSparseMatrixTest : public ::testing::Test { protected: virtual void SetUp() { - scoped_ptr problem( + std::unique_ptr problem( CreateLinearLeastSquaresProblemFromId(1)); CHECK_NOTNULL(problem.get()); @@ -95,8 +95,8 @@ class CompressedRowSparseMatrixTest : public ::testing::Test { int num_rows; int num_cols; - scoped_ptr tsm; - scoped_ptr crsm; + std::unique_ptr tsm; + std::unique_ptr crsm; }; TEST_F(CompressedRowSparseMatrixTest, Scale) { @@ -132,7 +132,7 @@ TEST_F(CompressedRowSparseMatrixTest, AppendRows) { tsm_appendage.Resize(i, num_cols); tsm->AppendRows(tsm_appendage); - scoped_ptr crsm_appendage( + std::unique_ptr crsm_appendage( CompressedRowSparseMatrix::FromTripletSparseMatrix(tsm_appendage)); crsm->AppendRows(*crsm_appendage); @@ -143,7 +143,7 @@ TEST_F(CompressedRowSparseMatrixTest, AppendRows) { TEST_F(CompressedRowSparseMatrixTest, AppendAndDeleteBlockDiagonalMatrix) { int num_diagonal_rows = crsm->num_cols(); - scoped_array diagonal(new double[num_diagonal_rows]); + std::unique_ptr diagonal(new double[num_diagonal_rows]); for (int i = 0; i < num_diagonal_rows; ++i) { diagonal[i] = i; } @@ -156,7 +156,7 @@ TEST_F(CompressedRowSparseMatrixTest, AppendAndDeleteBlockDiagonalMatrix) { const vector pre_row_blocks = crsm->row_blocks(); const vector pre_col_blocks = crsm->col_blocks(); - scoped_ptr appendage( + std::unique_ptr appendage( CompressedRowSparseMatrix::CreateBlockDiagonalMatrix( diagonal.get(), row_and_column_blocks)); @@ -220,7 +220,7 @@ TEST(CompressedRowSparseMatrix, CreateBlockDiagonalMatrix) { diagonal(i) = i + 1; } - scoped_ptr matrix( + std::unique_ptr matrix( CompressedRowSparseMatrix::CreateBlockDiagonalMatrix(diagonal.data(), blocks)); @@ -305,7 +305,7 @@ TEST(CompressedRowSparseMatrix, Transpose) { std::copy(values, values + 17, cols); - scoped_ptr transpose(matrix.Transpose()); + std::unique_ptr transpose(matrix.Transpose()); ASSERT_EQ(transpose->row_blocks().size(), matrix.col_blocks().size()); for (int i = 0; i < transpose->row_blocks().size(); ++i) { @@ -333,9 +333,9 @@ TEST(CompressedRowSparseMatrix, FromTripletSparseMatrix) { const int kNumTrials = 10; for (int i = 0; i < kNumTrials; ++i) { - scoped_ptr tsm( + std::unique_ptr tsm( TripletSparseMatrix::CreateRandomMatrix(options)); - scoped_ptr crsm( + std::unique_ptr crsm( CompressedRowSparseMatrix::FromTripletSparseMatrix(*tsm)); Matrix expected; @@ -359,9 +359,9 @@ TEST(CompressedRowSparseMatrix, FromTripletSparseMatrixTransposed) { const int kNumTrials = 10; for (int i = 0; i < kNumTrials; ++i) { - scoped_ptr tsm( + std::unique_ptr tsm( TripletSparseMatrix::CreateRandomMatrix(options)); - scoped_ptr crsm( + std::unique_ptr crsm( CompressedRowSparseMatrix::FromTripletSparseMatrixTransposed(*tsm)); Matrix tmp; @@ -416,7 +416,7 @@ TEST_P(RightMultiplyTest, _) { options.max_row_block_size = kMaxBlockSize; options.block_density = std::max(0.5, RandDouble()); options.storage_type = ::testing::get<0>(param); - scoped_ptr matrix( + std::unique_ptr matrix( CompressedRowSparseMatrix::CreateRandomMatrix(options)); const int num_rows = matrix->num_rows(); const int num_cols = matrix->num_cols(); @@ -484,7 +484,7 @@ TEST_P(LeftMultiplyTest, _) { options.max_row_block_size = kMaxBlockSize; options.block_density = std::max(0.5, RandDouble()); options.storage_type = ::testing::get<0>(param); - scoped_ptr matrix( + std::unique_ptr matrix( CompressedRowSparseMatrix::CreateRandomMatrix(options)); const int num_rows = matrix->num_rows(); const int num_cols = matrix->num_cols(); @@ -552,7 +552,7 @@ TEST_P(SquaredColumnNormTest, _) { options.max_row_block_size = kMaxBlockSize; options.block_density = std::max(0.5, RandDouble()); options.storage_type = ::testing::get<0>(param); - scoped_ptr matrix( + std::unique_ptr matrix( CompressedRowSparseMatrix::CreateRandomMatrix(options)); const int num_cols = matrix->num_cols(); diff --git a/internal/ceres/conjugate_gradients_solver_test.cc b/internal/ceres/conjugate_gradients_solver_test.cc index 1f5c3ae74..931199860 100644 --- a/internal/ceres/conjugate_gradients_solver_test.cc +++ b/internal/ceres/conjugate_gradients_solver_test.cc @@ -31,12 +31,12 @@ // TODO(sameeragarwal): More comprehensive testing with larger and // more badly conditioned problem. +#include #include "gtest/gtest.h" #include "ceres/conjugate_gradients_solver.h" #include "ceres/linear_solver.h" #include "ceres/triplet_sparse_matrix.h" #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/types.h" namespace ceres { @@ -44,7 +44,7 @@ namespace internal { TEST(ConjugateGradientTest, Solves3x3IdentitySystem) { double diagonal[] = { 1.0, 1.0, 1.0 }; - scoped_ptr + std::unique_ptr A(TripletSparseMatrix::CreateSparseDiagonalMatrix(diagonal, 3)); Vector b(3); Vector x(3); @@ -77,7 +77,7 @@ TEST(ConjugateGradientTest, Solves3x3IdentitySystem) { TEST(ConjuateGradientTest, Solves3x3SymmetricSystem) { - scoped_ptr A(new TripletSparseMatrix(3, 3, 9)); + std::unique_ptr A(new TripletSparseMatrix(3, 3, 9)); Vector b(3); Vector x(3); diff --git a/internal/ceres/coordinate_descent_minimizer.cc b/internal/ceres/coordinate_descent_minimizer.cc index e5569d496..48fd04c34 100644 --- a/internal/ceres/coordinate_descent_minimizer.cc +++ b/internal/ceres/coordinate_descent_minimizer.cc @@ -35,8 +35,10 @@ #endif #include +#include #include #include + #include "ceres/evaluator.h" #include "ceres/linear_solver.h" #include "ceres/minimizer.h" @@ -137,7 +139,7 @@ void CoordinateDescentMinimizer::Minimize( parameter_block->SetConstant(); } - scoped_array linear_solvers( + std::unique_ptr linear_solvers( new LinearSolver*[options.num_threads]); LinearSolver::Options linear_solver_options; @@ -281,7 +283,7 @@ bool CoordinateDescentMinimizer::IsOrderingValid( // points. ParameterBlockOrdering* CoordinateDescentMinimizer::CreateOrdering( const Program& program) { - scoped_ptr ordering(new ParameterBlockOrdering); + std::unique_ptr ordering(new ParameterBlockOrdering); ComputeRecursiveIndependentSetOrdering(program, ordering.get()); ordering->Reverse(); return ordering.release(); diff --git a/internal/ceres/cost_function_to_functor_test.cc b/internal/ceres/cost_function_to_functor_test.cc index 6c9a9402f..5878d3b7c 100644 --- a/internal/ceres/cost_function_to_functor_test.cc +++ b/internal/ceres/cost_function_to_functor_test.cc @@ -29,6 +29,8 @@ // Author: sameeragarwal@google.com (Sameer Agarwal) #include "ceres/cost_function_to_functor.h" + +#include #include "ceres/dynamic_autodiff_cost_function.h" #include "ceres/dynamic_cost_function_to_functor.h" #include "ceres/autodiff_cost_function.h" @@ -58,23 +60,23 @@ void ExpectCostFunctionsAreEqual(const CostFunction& cost_function, num_parameters += parameter_block_sizes[i]; } - scoped_array parameters(new double[num_parameters]); + std::unique_ptr parameters(new double[num_parameters]); for (int i = 0; i < num_parameters; ++i) { parameters[i] = static_cast(i) + 1.0; } - scoped_array residuals(new double[num_residuals]); - scoped_array jacobians(new double[num_parameters * num_residuals]); + std::unique_ptr residuals(new double[num_residuals]); + std::unique_ptr jacobians(new double[num_parameters * num_residuals]); - scoped_array actual_residuals(new double[num_residuals]); - scoped_array actual_jacobians + std::unique_ptr actual_residuals(new double[num_residuals]); + std::unique_ptr actual_jacobians (new double[num_parameters * num_residuals]); - scoped_array parameter_blocks( + std::unique_ptr parameter_blocks( new double*[parameter_block_sizes.size()]); - scoped_array jacobian_blocks( + std::unique_ptr jacobian_blocks( new double*[parameter_block_sizes.size()]); - scoped_array actual_jacobian_blocks( + std::unique_ptr actual_jacobian_blocks( new double*[parameter_block_sizes.size()]); num_parameters = 0; @@ -258,7 +260,7 @@ class DynamicTwoParameterBlockFunctor { #define TEST_BODY(NAME) \ TEST(CostFunctionToFunctor, NAME) { \ - scoped_ptr cost_function( \ + std::unique_ptr cost_function( \ new AutoDiffCostFunction< \ CostFunctionToFunctor<2, PARAMETER_BLOCK_SIZES >, \ 2, PARAMETER_BLOCK_SIZES>(new CostFunctionToFunctor< \ @@ -267,7 +269,7 @@ class DynamicTwoParameterBlockFunctor { NAME##Functor, 2, PARAMETER_BLOCK_SIZES >( \ new NAME##Functor)))); \ \ -scoped_ptr actual_cost_function( \ +std::unique_ptr actual_cost_function( \ new AutoDiffCostFunction( \ new NAME##Functor)); \ ExpectCostFunctionsAreEqual(*cost_function, *actual_cost_function); \ @@ -316,14 +318,14 @@ TEST_BODY(TenParameterBlock) #undef TEST_BODY TEST(CostFunctionToFunctor, DynamicNumberOfResiduals) { - scoped_ptr cost_function( + std::unique_ptr cost_function( new AutoDiffCostFunction< CostFunctionToFunctor, ceres::DYNAMIC, 2, 2>( new CostFunctionToFunctor( new AutoDiffCostFunction( new TwoParameterBlockFunctor)), 2)); - scoped_ptr actual_cost_function( + std::unique_ptr actual_cost_function( new AutoDiffCostFunction( new TwoParameterBlockFunctor)); ExpectCostFunctionsAreEqual(*cost_function, *actual_cost_function); diff --git a/internal/ceres/covariance_impl.cc b/internal/ceres/covariance_impl.cc index 484c94ffa..70719b030 100644 --- a/internal/ceres/covariance_impl.cc +++ b/internal/ceres/covariance_impl.cc @@ -36,6 +36,7 @@ #include #include +#include #include #include #include @@ -337,7 +338,7 @@ bool CovarianceImpl::GetCovarianceMatrixInTangentOrAmbientSpace( // Assemble the blocks in the covariance matrix. MatrixRef covariance(covariance_matrix, covariance_size, covariance_size); const int num_threads = options_.num_threads; - scoped_array workspace( + std::unique_ptr workspace( new double[num_threads * max_covariance_block_size * max_covariance_block_size]); @@ -706,7 +707,7 @@ bool CovarianceImpl::ComputeCovarianceValuesUsingSuiteSparseQR() { // Since the covariance matrix is symmetric, the i^th row and column // are equal. const int num_threads = options_.num_threads; - scoped_array workspace(new double[num_threads * num_cols]); + std::unique_ptr workspace(new double[num_threads * num_cols]); #if !(defined(CERES_USE_TBB) || defined(CERES_USE_CXX11_THREADS)) ThreadTokenProvider thread_token_provider(num_threads); @@ -915,7 +916,7 @@ bool CovarianceImpl::ComputeCovarianceValuesUsingEigenSparseQR() { // are equal. const int num_cols = jacobian.num_cols; const int num_threads = options_.num_threads; - scoped_array workspace(new double[num_threads * num_cols]); + std::unique_ptr workspace(new double[num_threads * num_cols]); #if !(defined(CERES_USE_TBB) || defined(CERES_USE_CXX11_THREADS)) ThreadTokenProvider thread_token_provider(num_threads); diff --git a/internal/ceres/covariance_impl.h b/internal/ceres/covariance_impl.h index a3f0761f5..c3a9bc145 100644 --- a/internal/ceres/covariance_impl.h +++ b/internal/ceres/covariance_impl.h @@ -32,11 +32,11 @@ #define CERES_INTERNAL_COVARIANCE_IMPL_H_ #include +#include #include #include #include #include "ceres/covariance.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/problem_impl.h" #include "ceres/suitesparse.h" @@ -92,7 +92,7 @@ class CovarianceImpl { bool is_valid_; std::map parameter_block_to_row_index_; std::set constant_parameter_blocks_; - scoped_ptr covariance_matrix_; + std::unique_ptr covariance_matrix_; }; } // namespace internal diff --git a/internal/ceres/covariance_test.cc b/internal/ceres/covariance_test.cc index 96c962a03..afa9bb675 100644 --- a/internal/ceres/covariance_test.cc +++ b/internal/ceres/covariance_test.cc @@ -33,7 +33,9 @@ #include #include #include +#include #include + #include "ceres/compressed_row_sparse_matrix.h" #include "ceres/cost_function.h" #include "ceres/covariance_impl.h" @@ -1256,7 +1258,7 @@ class LargeScaleCovarianceTest : public ::testing::Test { } } - scoped_array parameters_; + std::unique_ptr parameters_; int parameter_block_size_; int num_parameter_blocks_; diff --git a/internal/ceres/cubic_interpolation_test.cc b/internal/ceres/cubic_interpolation_test.cc index df4369694..fd5601641 100644 --- a/internal/ceres/cubic_interpolation_test.cc +++ b/internal/ceres/cubic_interpolation_test.cc @@ -30,8 +30,8 @@ #include "ceres/cubic_interpolation.h" +#include #include "ceres/jet.h" -#include "ceres/internal/scoped_ptr.h" #include "glog/logging.h" #include "gtest/gtest.h" @@ -257,7 +257,7 @@ class CubicInterpolatorTest : public ::testing::Test { private: static const int kNumSamples = 10; static const int kNumTestSamples = 100; - scoped_array values_; + std::unique_ptr values_; }; TEST_F(CubicInterpolatorTest, ConstantFunction) { @@ -375,7 +375,7 @@ class BiCubicInterpolatorTest : public ::testing::Test { static const int kNumCols = 10; static const int kNumRowSamples = 100; static const int kNumColSamples = 100; - scoped_array values_; + std::unique_ptr values_; }; TEST_F(BiCubicInterpolatorTest, ZeroFunction) { diff --git a/internal/ceres/dense_linear_solver_test.cc b/internal/ceres/dense_linear_solver_test.cc index f8b64f822..e2e02ca4c 100644 --- a/internal/ceres/dense_linear_solver_test.cc +++ b/internal/ceres/dense_linear_solver_test.cc @@ -28,9 +28,9 @@ // // Author: sameeragarwal@google.com (Sameer Agarwal) +#include #include "ceres/casts.h" #include "ceres/context_impl.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/linear_least_squares_problems.h" #include "ceres/linear_solver.h" #include "ceres/triplet_sparse_matrix.h" @@ -61,7 +61,7 @@ TEST_P(DenseLinearSolverTest, _) { Param param = GetParam(); const bool regularized = testing::get<2>(param); - scoped_ptr problem( + std::unique_ptr problem( CreateLinearLeastSquaresProblemFromId(testing::get<3>(param))); DenseSparseMatrix lhs(*down_cast(problem->A.get())); @@ -76,7 +76,7 @@ TEST_P(DenseLinearSolverTest, _) { options.dense_linear_algebra_library_type = ::testing::get<1>(param); ContextImpl context; options.context = &context; - scoped_ptr solver(LinearSolver::Create(options)); + std::unique_ptr solver(LinearSolver::Create(options)); LinearSolver::PerSolveOptions per_solve_options; if (regularized) { diff --git a/internal/ceres/dense_normal_cholesky_solver.cc b/internal/ceres/dense_normal_cholesky_solver.cc index b13cf3fc9..fe7d931a3 100644 --- a/internal/ceres/dense_normal_cholesky_solver.cc +++ b/internal/ceres/dense_normal_cholesky_solver.cc @@ -36,7 +36,6 @@ #include "ceres/blas.h" #include "ceres/dense_sparse_matrix.h" #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/lapack.h" #include "ceres/linear_solver.h" #include "ceres/types.h" diff --git a/internal/ceres/dense_qr_solver.cc b/internal/ceres/dense_qr_solver.cc index e85fdfc0c..161e9c67a 100644 --- a/internal/ceres/dense_qr_solver.cc +++ b/internal/ceres/dense_qr_solver.cc @@ -30,12 +30,10 @@ #include "ceres/dense_qr_solver.h" - #include #include "Eigen/Dense" #include "ceres/dense_sparse_matrix.h" #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/lapack.h" #include "ceres/linear_solver.h" #include "ceres/types.h" diff --git a/internal/ceres/dense_sparse_matrix.h b/internal/ceres/dense_sparse_matrix.h index b011bfdde..9639a4ae2 100644 --- a/internal/ceres/dense_sparse_matrix.h +++ b/internal/ceres/dense_sparse_matrix.h @@ -33,10 +33,9 @@ #ifndef CERES_INTERNAL_DENSE_SPARSE_MATRIX_H_ #define CERES_INTERNAL_DENSE_SPARSE_MATRIX_H_ -#include "ceres/sparse_matrix.h" #include "ceres/internal/eigen.h" #include "ceres/internal/macros.h" -#include "ceres/internal/scoped_ptr.h" +#include "ceres/sparse_matrix.h" #include "ceres/types.h" namespace ceres { diff --git a/internal/ceres/dense_sparse_matrix_test.cc b/internal/ceres/dense_sparse_matrix_test.cc index a77f5e3ce..7c7e69a1b 100644 --- a/internal/ceres/dense_sparse_matrix_test.cc +++ b/internal/ceres/dense_sparse_matrix_test.cc @@ -34,11 +34,11 @@ #include "ceres/dense_sparse_matrix.h" +#include #include "ceres/casts.h" #include "ceres/linear_least_squares_problems.h" #include "ceres/triplet_sparse_matrix.h" #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "glog/logging.h" #include "gtest/gtest.h" @@ -69,7 +69,7 @@ void CompareMatrices(const SparseMatrix* a, const SparseMatrix* b) { class DenseSparseMatrixTest : public ::testing::Test { protected : virtual void SetUp() { - scoped_ptr problem( + std::unique_ptr problem( CreateLinearLeastSquaresProblemFromId(1)); CHECK_NOTNULL(problem.get()); @@ -84,8 +84,8 @@ class DenseSparseMatrixTest : public ::testing::Test { int num_rows; int num_cols; - scoped_ptr tsm; - scoped_ptr dsm; + std::unique_ptr tsm; + std::unique_ptr dsm; }; TEST_F(DenseSparseMatrixTest, RightMultiply) { diff --git a/internal/ceres/dogleg_strategy_test.cc b/internal/ceres/dogleg_strategy_test.cc index f1fe05a19..c435be686 100644 --- a/internal/ceres/dogleg_strategy_test.cc +++ b/internal/ceres/dogleg_strategy_test.cc @@ -29,8 +29,8 @@ // Author: moll.markus@arcor.de (Markus Moll) #include +#include #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/dense_qr_solver.h" #include "ceres/dogleg_strategy.h" #include "ceres/linear_solver.h" @@ -44,7 +44,7 @@ namespace { class Fixture : public testing::Test { protected: - scoped_ptr jacobian_; + std::unique_ptr jacobian_; Vector residual_; Vector x_; TrustRegionStrategy::Options options_; @@ -126,7 +126,7 @@ const double kEpsilon = std::numeric_limits::epsilon(); // The DoglegStrategy must never return a step that is longer than the current // trust region radius. TEST_F(DoglegStrategyFixtureEllipse, TrustRegionObeyedTraditional) { - scoped_ptr linear_solver( + std::unique_ptr linear_solver( new DenseQRSolver(LinearSolver::Options())); options_.linear_solver = linear_solver.get(); // The global minimum is at (1, 1, ..., 1), so the distance to it is @@ -149,7 +149,7 @@ TEST_F(DoglegStrategyFixtureEllipse, TrustRegionObeyedTraditional) { } TEST_F(DoglegStrategyFixtureEllipse, TrustRegionObeyedSubspace) { - scoped_ptr linear_solver( + std::unique_ptr linear_solver( new DenseQRSolver(LinearSolver::Options())); options_.linear_solver = linear_solver.get(); options_.dogleg_type = SUBSPACE_DOGLEG; @@ -169,7 +169,7 @@ TEST_F(DoglegStrategyFixtureEllipse, TrustRegionObeyedSubspace) { } TEST_F(DoglegStrategyFixtureEllipse, CorrectGaussNewtonStep) { - scoped_ptr linear_solver( + std::unique_ptr linear_solver( new DenseQRSolver(LinearSolver::Options())); options_.linear_solver = linear_solver.get(); options_.dogleg_type = SUBSPACE_DOGLEG; @@ -196,7 +196,7 @@ TEST_F(DoglegStrategyFixtureEllipse, CorrectGaussNewtonStep) { // Test if the subspace basis is a valid orthonormal basis of the space spanned // by the gradient and the Gauss-Newton point. TEST_F(DoglegStrategyFixtureEllipse, ValidSubspaceBasis) { - scoped_ptr linear_solver( + std::unique_ptr linear_solver( new DenseQRSolver(LinearSolver::Options())); options_.linear_solver = linear_solver.get(); options_.dogleg_type = SUBSPACE_DOGLEG; @@ -231,7 +231,7 @@ TEST_F(DoglegStrategyFixtureEllipse, ValidSubspaceBasis) { // in the same direction and the Gauss-Newton step is outside the trust region, // i.e. the trust region is active. TEST_F(DoglegStrategyFixtureValley, CorrectStepLocalOptimumAlongGradient) { - scoped_ptr linear_solver( + std::unique_ptr linear_solver( new DenseQRSolver(LinearSolver::Options())); options_.linear_solver = linear_solver.get(); options_.dogleg_type = SUBSPACE_DOGLEG; @@ -259,7 +259,7 @@ TEST_F(DoglegStrategyFixtureValley, CorrectStepLocalOptimumAlongGradient) { // in the same direction and the Gauss-Newton step is inside the trust region, // i.e. the trust region is inactive. TEST_F(DoglegStrategyFixtureValley, CorrectStepGlobalOptimumAlongGradient) { - scoped_ptr linear_solver( + std::unique_ptr linear_solver( new DenseQRSolver(LinearSolver::Options())); options_.linear_solver = linear_solver.get(); options_.dogleg_type = SUBSPACE_DOGLEG; diff --git a/internal/ceres/dynamic_autodiff_cost_function_test.cc b/internal/ceres/dynamic_autodiff_cost_function_test.cc index ea51c2d5c..626cdeeb2 100644 --- a/internal/ceres/dynamic_autodiff_cost_function_test.cc +++ b/internal/ceres/dynamic_autodiff_cost_function_test.cc @@ -32,8 +32,8 @@ #include +#include #include "ceres/dynamic_autodiff_cost_function.h" -#include "ceres/internal/scoped_ptr.h" #include "gtest/gtest.h" namespace ceres { @@ -418,7 +418,7 @@ class ThreeParameterCostFunctorTest : public ::testing::Test { vector parameter_blocks_; - scoped_ptr cost_function_; + std::unique_ptr cost_function_; vector > jacobian_vect_; @@ -665,7 +665,7 @@ class SixParameterCostFunctorTest : public ::testing::Test { vector parameter_blocks_; - scoped_ptr cost_function_; + std::unique_ptr cost_function_; vector > jacobian_vect_; diff --git a/internal/ceres/dynamic_compressed_row_sparse_matrix_test.cc b/internal/ceres/dynamic_compressed_row_sparse_matrix_test.cc index 40301423c..3592557cd 100644 --- a/internal/ceres/dynamic_compressed_row_sparse_matrix_test.cc +++ b/internal/ceres/dynamic_compressed_row_sparse_matrix_test.cc @@ -30,10 +30,10 @@ #include "ceres/dynamic_compressed_row_sparse_matrix.h" +#include #include "ceres/casts.h" #include "ceres/compressed_row_sparse_matrix.h" #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/linear_least_squares_problems.h" #include "ceres/triplet_sparse_matrix.h" #include "gtest/gtest.h" @@ -167,10 +167,10 @@ class DynamicCompressedRowSparseMatrixTest : public ::testing::Test { int expected_num_nonzeros; Matrix dense; - scoped_ptr tsm; - scoped_ptr crsm; + std::unique_ptr tsm; + std::unique_ptr crsm; - scoped_ptr dcrsm; + std::unique_ptr dcrsm; }; TEST_F(DynamicCompressedRowSparseMatrixTest, Initialization) { diff --git a/internal/ceres/dynamic_numeric_diff_cost_function_test.cc b/internal/ceres/dynamic_numeric_diff_cost_function_test.cc index 760fdebc0..e4db3c14d 100644 --- a/internal/ceres/dynamic_numeric_diff_cost_function_test.cc +++ b/internal/ceres/dynamic_numeric_diff_cost_function_test.cc @@ -31,8 +31,8 @@ #include +#include #include "ceres/dynamic_numeric_diff_cost_function.h" -#include "ceres/internal/scoped_ptr.h" #include "gtest/gtest.h" namespace ceres { @@ -419,7 +419,7 @@ class ThreeParameterCostFunctorTest : public ::testing::Test { vector parameter_blocks_; - scoped_ptr cost_function_; + std::unique_ptr cost_function_; vector > jacobian_vect_; diff --git a/internal/ceres/dynamic_sparse_normal_cholesky_solver.cc b/internal/ceres/dynamic_sparse_normal_cholesky_solver.cc index 6d39616e9..451cfde8e 100644 --- a/internal/ceres/dynamic_sparse_normal_cholesky_solver.cc +++ b/internal/ceres/dynamic_sparse_normal_cholesky_solver.cc @@ -33,13 +33,13 @@ #include #include #include +#include #include #include "Eigen/SparseCore" #include "ceres/compressed_row_sparse_matrix.h" #include "ceres/cxsparse.h" #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/linear_solver.h" #include "ceres/suitesparse.h" #include "ceres/triplet_sparse_matrix.h" @@ -69,7 +69,7 @@ LinearSolver::Summary DynamicSparseNormalCholeskySolver::SolveImpl( if (per_solve_options.D != NULL) { // Temporarily append a diagonal block to the A matrix, but undo // it before returning the matrix to the user. - scoped_ptr regularizer; + std::unique_ptr regularizer; if (!A->col_blocks().empty()) { regularizer.reset(CompressedRowSparseMatrix::CreateBlockDiagonalMatrix( per_solve_options.D, A->col_blocks())); diff --git a/internal/ceres/dynamic_sparse_normal_cholesky_solver_test.cc b/internal/ceres/dynamic_sparse_normal_cholesky_solver_test.cc index 1e5d179cf..4fe06f89b 100644 --- a/internal/ceres/dynamic_sparse_normal_cholesky_solver_test.cc +++ b/internal/ceres/dynamic_sparse_normal_cholesky_solver_test.cc @@ -28,10 +28,10 @@ // // Author: sameeragarwal@google.com (Sameer Agarwal) +#include #include "ceres/casts.h" #include "ceres/compressed_row_sparse_matrix.h" #include "ceres/context_impl.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/linear_least_squares_problems.h" #include "ceres/linear_solver.h" #include "ceres/triplet_sparse_matrix.h" @@ -50,7 +50,7 @@ namespace internal { class DynamicSparseNormalCholeskySolverTest : public ::testing::Test { protected: virtual void SetUp() { - scoped_ptr problem( + std::unique_ptr problem( CreateLinearLeastSquaresProblemFromId(1)); A_.reset(CompressedRowSparseMatrix::FromTripletSparseMatrix( *down_cast(problem->A.get()))); @@ -74,7 +74,7 @@ class DynamicSparseNormalCholeskySolverTest : public ::testing::Test { A_->LeftMultiply(b_.get(), rhs.data()); Vector expected_solution = lhs.llt().solve(rhs); - scoped_ptr solver(LinearSolver::Create(options)); + std::unique_ptr solver(LinearSolver::Create(options)); LinearSolver::PerSolveOptions per_solve_options; per_solve_options.D = D; Vector actual_solution(A_->num_cols()); @@ -104,9 +104,9 @@ class DynamicSparseNormalCholeskySolverTest : public ::testing::Test { TestSolver(options, D_.get()); } - scoped_ptr A_; - scoped_array b_; - scoped_array D_; + std::unique_ptr A_; + std::unique_ptr b_; + std::unique_ptr D_; }; #ifndef CERES_NO_SUITESPARSE diff --git a/internal/ceres/evaluation_callback_test.cc b/internal/ceres/evaluation_callback_test.cc index 57e09f020..cec88d62b 100644 --- a/internal/ceres/evaluation_callback_test.cc +++ b/internal/ceres/evaluation_callback_test.cc @@ -30,11 +30,11 @@ #include "ceres/solver.h" -#include #include +#include #include + #include "gtest/gtest.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/sized_cost_function.h" #include "ceres/problem.h" #include "ceres/problem_impl.h" diff --git a/internal/ceres/evaluator_test.cc b/internal/ceres/evaluator_test.cc index 7cec00a7f..79006f787 100644 --- a/internal/ceres/evaluator_test.cc +++ b/internal/ceres/evaluator_test.cc @@ -33,12 +33,12 @@ #include "ceres/evaluator.h" +#include #include "ceres/casts.h" #include "ceres/cost_function.h" #include "ceres/crs_matrix.h" #include "ceres/evaluator_test_utils.h" #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/local_parameterization.h" #include "ceres/problem_impl.h" #include "ceres/program.h" @@ -143,7 +143,7 @@ struct EvaluatorTest const double* expected_residuals, const double* expected_gradient, const double* expected_jacobian) { - scoped_ptr evaluator( + std::unique_ptr evaluator( CreateEvaluator(problem->mutable_program())); int num_residuals = expected_num_rows; int num_parameters = expected_num_cols; @@ -156,7 +156,7 @@ struct EvaluatorTest Vector gradient(num_parameters); gradient.setConstant(-3000); - scoped_ptr jacobian(evaluator->CreateJacobian()); + std::unique_ptr jacobian(evaluator->CreateJacobian()); ASSERT_EQ(expected_num_rows, evaluator->NumResiduals()); ASSERT_EQ(expected_num_cols, evaluator->NumEffectiveParameters()); @@ -531,8 +531,8 @@ TEST_P(EvaluatorTest, EvaluatorAbortsForResidualsThatFailToEvaluate) { // The values are ignored. double state[9]; - scoped_ptr evaluator(CreateEvaluator(problem.mutable_program())); - scoped_ptr jacobian(evaluator->CreateJacobian()); + std::unique_ptr evaluator(CreateEvaluator(problem.mutable_program())); + std::unique_ptr jacobian(evaluator->CreateJacobian()); double cost; EXPECT_FALSE(evaluator->Evaluate(state, &cost, NULL, NULL, NULL)); } @@ -607,8 +607,8 @@ TEST(Evaluator, EvaluatorRespectsParameterChanges) { options.num_eliminate_blocks = 0; options.context = problem.context(); string error; - scoped_ptr evaluator(Evaluator::Create(options, program, &error)); - scoped_ptr jacobian(evaluator->CreateJacobian()); + std::unique_ptr evaluator(Evaluator::Create(options, program, &error)); + std::unique_ptr jacobian(evaluator->CreateJacobian()); ASSERT_EQ(2, jacobian->num_rows()); ASSERT_EQ(2, jacobian->num_cols()); diff --git a/internal/ceres/gradient_checking_cost_function.cc b/internal/ceres/gradient_checking_cost_function.cc index eda152446..2336ffe9e 100644 --- a/internal/ceres/gradient_checking_cost_function.cc +++ b/internal/ceres/gradient_checking_cost_function.cc @@ -39,7 +39,6 @@ #include "ceres/gradient_checker.h" #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/parameter_block.h" #include "ceres/problem.h" #include "ceres/problem_impl.h" diff --git a/internal/ceres/gradient_checking_cost_function_test.cc b/internal/ceres/gradient_checking_cost_function_test.cc index 887922e02..7cf1e45ba 100644 --- a/internal/ceres/gradient_checking_cost_function_test.cc +++ b/internal/ceres/gradient_checking_cost_function_test.cc @@ -31,9 +31,10 @@ #include "ceres/gradient_checking_cost_function.h" #include +#include #include + #include "ceres/cost_function.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/local_parameterization.h" #include "ceres/loss_function.h" #include "ceres/parameter_block.h" @@ -161,7 +162,7 @@ TEST(GradientCheckingCostFunction, ResidualsAndJacobiansArePreservedTest) { TestTerm<-1, -1> term(arity, dim); GradientCheckingIterationCallback callback; - scoped_ptr gradient_checking_cost_function( + std::unique_ptr gradient_checking_cost_function( CreateGradientCheckingCostFunction(&term, NULL, kRelativeStepSize, kRelativePrecision, @@ -218,7 +219,7 @@ TEST(GradientCheckingCostFunction, SmokeTest) { { TestTerm<1, 2> term(arity, dim); GradientCheckingIterationCallback callback; - scoped_ptr gradient_checking_cost_function( + std::unique_ptr gradient_checking_cost_function( CreateGradientCheckingCostFunction(&term, NULL, kRelativeStepSize, kRelativePrecision, @@ -237,7 +238,7 @@ TEST(GradientCheckingCostFunction, SmokeTest) { { TestTerm<-1, -1> term(arity, dim); GradientCheckingIterationCallback callback; - scoped_ptr gradient_checking_cost_function( + std::unique_ptr gradient_checking_cost_function( CreateGradientCheckingCostFunction(&term, NULL, kRelativeStepSize, kRelativePrecision, @@ -358,7 +359,7 @@ TEST(GradientCheckingProblemImpl, ProblemDimensionsMatch) { NULL, z, x, y); GradientCheckingIterationCallback callback; - scoped_ptr gradient_checking_problem_impl( + std::unique_ptr gradient_checking_problem_impl( CreateGradientCheckingProblemImpl(&problem_impl, 1.0, 1.0, &callback)); // The dimensions of the two problems match. diff --git a/internal/ceres/gradient_problem_solver.cc b/internal/ceres/gradient_problem_solver.cc index 0d413752f..5ef36ad9c 100644 --- a/internal/ceres/gradient_problem_solver.cc +++ b/internal/ceres/gradient_problem_solver.cc @@ -30,6 +30,7 @@ #include "ceres/gradient_problem_solver.h" +#include #include "ceres/callbacks.h" #include "ceres/gradient_problem.h" #include "ceres/gradient_problem_evaluator.h" @@ -103,7 +104,6 @@ void GradientProblemSolver::Solve(const GradientProblemSolver::Options& options, using internal::GradientProblemSolverStateUpdatingCallback; using internal::LoggingCallback; using internal::Minimizer; - using internal::scoped_ptr; using internal::SetSummaryFinalCost; using internal::WallTimeInSeconds; @@ -135,7 +135,7 @@ void GradientProblemSolver::Solve(const GradientProblemSolver::Options& options, Minimizer::Options(GradientProblemSolverOptionsToSolverOptions(options)); minimizer_options.evaluator.reset(new GradientProblemEvaluator(problem)); - scoped_ptr logging_callback; + std::unique_ptr logging_callback; if (options.logging_type != SILENT) { logging_callback.reset( new LoggingCallback(LINE_SEARCH, options.minimizer_progress_to_stdout)); @@ -143,7 +143,7 @@ void GradientProblemSolver::Solve(const GradientProblemSolver::Options& options, logging_callback.get()); } - scoped_ptr state_updating_callback; + std::unique_ptr state_updating_callback; if (options.update_state_every_iteration) { state_updating_callback.reset( new GradientProblemSolverStateUpdatingCallback( @@ -152,7 +152,7 @@ void GradientProblemSolver::Solve(const GradientProblemSolver::Options& options, state_updating_callback.get()); } - scoped_ptr minimizer(Minimizer::Create(LINE_SEARCH)); + std::unique_ptr minimizer(Minimizer::Create(LINE_SEARCH)); Solver::Summary solver_summary; solver_summary.fixed_cost = 0.0; diff --git a/internal/ceres/graph_algorithms_test.cc b/internal/ceres/graph_algorithms_test.cc index 160ece153..644054401 100644 --- a/internal/ceres/graph_algorithms_test.cc +++ b/internal/ceres/graph_algorithms_test.cc @@ -31,11 +31,12 @@ #include "ceres/graph_algorithms.h" #include +#include #include -#include "gtest/gtest.h" + #include "ceres/graph.h" #include "ceres/internal/port.h" -#include "ceres/internal/scoped_ptr.h" +#include "gtest/gtest.h" namespace ceres { namespace internal { @@ -110,7 +111,7 @@ TEST(Degree2MaximumSpanningForest, PreserveWeights) { graph.AddEdge(0, 1, 0.5); graph.AddEdge(1, 0, 0.5); - scoped_ptr > forest(Degree2MaximumSpanningForest(graph)); + std::unique_ptr > forest(Degree2MaximumSpanningForest(graph)); const std::unordered_set& vertices = forest->vertices(); EXPECT_EQ(vertices.size(), 2); @@ -133,7 +134,7 @@ TEST(Degree2MaximumSpanningForest, StarGraph) { graph.AddEdge(0, 3, 3.0); graph.AddEdge(0, 4, 4.0); - scoped_ptr > forest(Degree2MaximumSpanningForest(graph)); + std::unique_ptr > forest(Degree2MaximumSpanningForest(graph)); const std::unordered_set& vertices = forest->vertices(); EXPECT_EQ(vertices.size(), 5); diff --git a/internal/ceres/graph_test.cc b/internal/ceres/graph_test.cc index 0907f8694..8f054756c 100644 --- a/internal/ceres/graph_test.cc +++ b/internal/ceres/graph_test.cc @@ -32,7 +32,6 @@ #include #include "gtest/gtest.h" -#include "ceres/internal/scoped_ptr.h" namespace ceres { namespace internal { diff --git a/internal/ceres/implicit_schur_complement.cc b/internal/ceres/implicit_schur_complement.cc index d05f03817..bf680d1d9 100644 --- a/internal/ceres/implicit_schur_complement.cc +++ b/internal/ceres/implicit_schur_complement.cc @@ -34,7 +34,6 @@ #include "ceres/block_sparse_matrix.h" #include "ceres/block_structure.h" #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/linear_solver.h" #include "ceres/types.h" #include "glog/logging.h" diff --git a/internal/ceres/implicit_schur_complement.h b/internal/ceres/implicit_schur_complement.h index 5d822ebae..1fac72c0e 100644 --- a/internal/ceres/implicit_schur_complement.h +++ b/internal/ceres/implicit_schur_complement.h @@ -34,11 +34,11 @@ #ifndef CERES_INTERNAL_IMPLICIT_SCHUR_COMPLEMENT_H_ #define CERES_INTERNAL_IMPLICIT_SCHUR_COMPLEMENT_H_ +#include #include "ceres/linear_operator.h" #include "ceres/linear_solver.h" #include "ceres/partitioned_matrix_view.h" #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/types.h" namespace ceres { @@ -145,12 +145,12 @@ class ImplicitSchurComplement : public LinearOperator { const LinearSolver::Options& options_; - scoped_ptr A_; + std::unique_ptr A_; const double* D_; const double* b_; - scoped_ptr block_diagonal_EtE_inverse_; - scoped_ptr block_diagonal_FtF_inverse_; + std::unique_ptr block_diagonal_EtE_inverse_; + std::unique_ptr block_diagonal_FtF_inverse_; Vector rhs_; diff --git a/internal/ceres/implicit_schur_complement_test.cc b/internal/ceres/implicit_schur_complement_test.cc index 4f54a1e8f..cbc0aeed0 100644 --- a/internal/ceres/implicit_schur_complement_test.cc +++ b/internal/ceres/implicit_schur_complement_test.cc @@ -31,13 +31,13 @@ #include "ceres/implicit_schur_complement.h" #include +#include #include "Eigen/Dense" #include "ceres/block_random_access_dense_matrix.h" #include "ceres/block_sparse_matrix.h" #include "ceres/casts.h" #include "ceres/context_impl.h" #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/linear_least_squares_problems.h" #include "ceres/linear_solver.h" #include "ceres/schur_eliminator.h" @@ -56,7 +56,7 @@ const double kEpsilon = 1e-14; class ImplicitSchurComplementTest : public ::testing::Test { protected : virtual void SetUp() { - scoped_ptr problem( + std::unique_ptr problem( CreateLinearLeastSquaresProblemFromId(2)); CHECK_NOTNULL(problem.get()); @@ -89,7 +89,7 @@ class ImplicitSchurComplementTest : public ::testing::Test { ContextImpl context; options.context = &context; - scoped_ptr eliminator( + std::unique_ptr eliminator( SchurEliminatorBase::Create(options)); CHECK_NOTNULL(eliminator.get()); const bool kFullRankETE = true; @@ -185,9 +185,9 @@ class ImplicitSchurComplementTest : public ::testing::Test { int num_cols_; int num_eliminate_blocks_; - scoped_ptr A_; - scoped_array b_; - scoped_array D_; + std::unique_ptr A_; + std::unique_ptr b_; + std::unique_ptr D_; }; // Verify that the Schur Complement matrix implied by the diff --git a/internal/ceres/inner_product_computer.h b/internal/ceres/inner_product_computer.h index d206707d3..73073f8ad 100644 --- a/internal/ceres/inner_product_computer.h +++ b/internal/ceres/inner_product_computer.h @@ -31,11 +31,11 @@ #ifndef CERES_INTERNAL_INNER_PRODUCT_COMPUTER_H_ #define CERES_INTERNAL_INNER_PRODUCT_COMPUTER_H_ +#include #include #include "ceres/block_sparse_matrix.h" #include "ceres/compressed_row_sparse_matrix.h" -#include "ceres/internal/scoped_ptr.h" namespace ceres { namespace internal { @@ -140,7 +140,7 @@ class InnerProductComputer { const BlockSparseMatrix& m_; const int start_row_block_; const int end_row_block_; - scoped_ptr result_; + std::unique_ptr result_; // For each term in the inner product, result_offsets_ contains the // location in the values array of the result_ matrix where it diff --git a/internal/ceres/inner_product_computer_test.cc b/internal/ceres/inner_product_computer_test.cc index 863f3efa5..8b2ff91c7 100644 --- a/internal/ceres/inner_product_computer_test.cc +++ b/internal/ceres/inner_product_computer_test.cc @@ -30,10 +30,10 @@ #include "ceres/inner_product_computer.h" +#include #include #include "ceres/block_sparse_matrix.h" #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/random.h" #include "ceres/triplet_sparse_matrix.h" #include "glog/logging.h" @@ -108,7 +108,7 @@ TEST(InnerProductComputer, NormalOperation) { VLOG(2) << "max col block size: " << options.max_col_block_size; VLOG(2) << "block density: " << options.block_density; - scoped_ptr random_matrix( + std::unique_ptr random_matrix( BlockSparseMatrix::CreateRandomMatrix(options)); TripletSparseMatrix tsm(random_matrix->num_rows(), @@ -126,7 +126,7 @@ TEST(InnerProductComputer, NormalOperation) { Matrix expected_inner_product = eigen_random_matrix.transpose() * eigen_random_matrix; - scoped_ptr inner_product_computer; + std::unique_ptr inner_product_computer; inner_product_computer.reset(InnerProductComputer::Create( *random_matrix, CompressedRowSparseMatrix::LOWER_TRIANGULAR)); @@ -168,7 +168,7 @@ TEST(InnerProductComputer, SubMatrix) { VLOG(2) << "max col block size: " << options.max_col_block_size; VLOG(2) << "block density: " << options.block_density; - scoped_ptr random_matrix( + std::unique_ptr random_matrix( BlockSparseMatrix::CreateRandomMatrix(options)); const std::vector& row_blocks = @@ -202,7 +202,7 @@ TEST(InnerProductComputer, SubMatrix) { Matrix expected_inner_product = eigen_random_matrix.transpose() * eigen_random_matrix; - scoped_ptr inner_product_computer; + std::unique_ptr inner_product_computer; inner_product_computer.reset(InnerProductComputer::Create( *random_matrix, start_row_block, diff --git a/internal/ceres/iterative_schur_complement_solver.cc b/internal/ceres/iterative_schur_complement_solver.cc index 7a1e7a63c..8ce907576 100644 --- a/internal/ceres/iterative_schur_complement_solver.cc +++ b/internal/ceres/iterative_schur_complement_solver.cc @@ -41,7 +41,6 @@ #include "ceres/detect_structure.h" #include "ceres/implicit_schur_complement.h" #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/linear_solver.h" #include "ceres/preconditioner.h" #include "ceres/schur_jacobi_preconditioner.h" diff --git a/internal/ceres/iterative_schur_complement_solver.h b/internal/ceres/iterative_schur_complement_solver.h index ffcfd8df2..f898f026d 100644 --- a/internal/ceres/iterative_schur_complement_solver.h +++ b/internal/ceres/iterative_schur_complement_solver.h @@ -31,9 +31,9 @@ #ifndef CERES_INTERNAL_ITERATIVE_SCHUR_COMPLEMENT_SOLVER_H_ #define CERES_INTERNAL_ITERATIVE_SCHUR_COMPLEMENT_SOLVER_H_ +#include #include "ceres/linear_solver.h" #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/types.h" namespace ceres { @@ -82,8 +82,8 @@ class IterativeSchurComplementSolver : public BlockSparseMatrixSolver { void CreatePreconditioner(BlockSparseMatrix* A); LinearSolver::Options options_; - scoped_ptr schur_complement_; - scoped_ptr preconditioner_; + std::unique_ptr schur_complement_; + std::unique_ptr preconditioner_; Vector reduced_linear_system_solution_; CERES_DISALLOW_COPY_AND_ASSIGN(IterativeSchurComplementSolver); }; diff --git a/internal/ceres/iterative_schur_complement_solver_test.cc b/internal/ceres/iterative_schur_complement_solver_test.cc index f5a545c5d..28c0d9966 100644 --- a/internal/ceres/iterative_schur_complement_solver_test.cc +++ b/internal/ceres/iterative_schur_complement_solver_test.cc @@ -35,13 +35,13 @@ #include "ceres/iterative_schur_complement_solver.h" #include +#include #include "Eigen/Dense" #include "ceres/block_random_access_dense_matrix.h" #include "ceres/block_sparse_matrix.h" #include "ceres/casts.h" #include "ceres/context_impl.h" #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/linear_least_squares_problems.h" #include "ceres/linear_solver.h" #include "ceres/schur_eliminator.h" @@ -60,7 +60,7 @@ const double kEpsilon = 1e-14; class IterativeSchurComplementSolverTest : public ::testing::Test { protected : void SetUpProblem(int problem_id) { - scoped_ptr problem( + std::unique_ptr problem( CreateLinearLeastSquaresProblemFromId(problem_id)); CHECK_NOTNULL(problem.get()); @@ -85,7 +85,7 @@ class IterativeSchurComplementSolverTest : public ::testing::Test { options.type = DENSE_QR; ContextImpl context; options.context = &context; - scoped_ptr qr(LinearSolver::Create(options)); + std::unique_ptr qr(LinearSolver::Create(options)); LinearSolver::PerSolveOptions per_solve_options; per_solve_options.D = D; @@ -114,9 +114,9 @@ class IterativeSchurComplementSolverTest : public ::testing::Test { int num_rows_; int num_cols_; int num_eliminate_blocks_; - scoped_ptr A_; - scoped_array b_; - scoped_array D_; + std::unique_ptr A_; + std::unique_ptr b_; + std::unique_ptr D_; }; TEST_F(IterativeSchurComplementSolverTest, NormalProblem) { diff --git a/internal/ceres/levenberg_marquardt_strategy_test.cc b/internal/ceres/levenberg_marquardt_strategy_test.cc index 45e4da41e..d5f746e71 100644 --- a/internal/ceres/levenberg_marquardt_strategy_test.cc +++ b/internal/ceres/levenberg_marquardt_strategy_test.cc @@ -28,8 +28,8 @@ // // Author: sameeragarwal@google.com (Sameer Agarwal) +#include #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/levenberg_marquardt_strategy.h" #include "ceres/linear_solver.h" #include "ceres/trust_region_strategy.h" @@ -86,7 +86,7 @@ TEST(LevenbergMarquardtStrategy, AcceptRejectStepRadiusScaling) { options.max_lm_diagonal = 1e8; // We need a non-null pointer here, so anything should do. - scoped_ptr linear_solver( + std::unique_ptr linear_solver( new RegularizationCheckingLinearSolver(0, NULL)); options.linear_solver = linear_solver.get(); diff --git a/internal/ceres/line_search_minimizer.cc b/internal/ceres/line_search_minimizer.cc index 5b5b83704..38e645217 100644 --- a/internal/ceres/line_search_minimizer.cc +++ b/internal/ceres/line_search_minimizer.cc @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -51,7 +52,6 @@ #include "ceres/evaluator.h" #include "ceres/internal/eigen.h" #include "ceres/internal/port.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/line_search.h" #include "ceres/line_search_direction.h" #include "ceres/stringprintf.h" @@ -164,7 +164,7 @@ void LineSearchMinimizer::Minimize(const Minimizer::Options& options, line_search_direction_options.max_lbfgs_rank = options.max_lbfgs_rank; line_search_direction_options.use_approximate_eigenvalue_bfgs_scaling = options.use_approximate_eigenvalue_bfgs_scaling; - scoped_ptr line_search_direction( + std::unique_ptr line_search_direction( LineSearchDirection::Create(line_search_direction_options)); LineSearchFunction line_search_function(evaluator); @@ -188,7 +188,7 @@ void LineSearchMinimizer::Minimize(const Minimizer::Options& options, line_search_options.is_silent = options.is_silent; line_search_options.function = &line_search_function; - scoped_ptr + std::unique_ptr line_search(LineSearch::Create(options.line_search_type, line_search_options, &summary->message)); diff --git a/internal/ceres/linear_least_squares_problems.cc b/internal/ceres/linear_least_squares_problems.cc index 0a69375f7..fb72d6301 100644 --- a/internal/ceres/linear_least_squares_problems.cc +++ b/internal/ceres/linear_least_squares_problems.cc @@ -31,13 +31,14 @@ #include "ceres/linear_least_squares_problems.h" #include +#include #include #include + #include "ceres/block_sparse_matrix.h" #include "ceres/block_structure.h" #include "ceres/casts.h" #include "ceres/file.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/stringprintf.h" #include "ceres/triplet_sparse_matrix.h" #include "ceres/types.h" @@ -297,7 +298,7 @@ LinearLeastSquaresProblem* LinearLeastSquaresProblem2() { problem->num_eliminate_blocks = 2; CompressedRowBlockStructure* bs = new CompressedRowBlockStructure; - scoped_array values(new double[num_rows * num_cols]); + std::unique_ptr values(new double[num_rows * num_cols]); for (int c = 0; c < num_cols; ++c) { bs->cols.push_back(Block()); @@ -431,7 +432,7 @@ LinearLeastSquaresProblem* LinearLeastSquaresProblem3() { problem->num_eliminate_blocks = 2; CompressedRowBlockStructure* bs = new CompressedRowBlockStructure; - scoped_array values(new double[num_rows * num_cols]); + std::unique_ptr values(new double[num_rows * num_cols]); for (int c = 0; c < num_cols; ++c) { bs->cols.push_back(Block()); @@ -538,7 +539,7 @@ LinearLeastSquaresProblem* LinearLeastSquaresProblem4() { problem->num_eliminate_blocks = 1; CompressedRowBlockStructure* bs = new CompressedRowBlockStructure; - scoped_array values(new double[num_rows * num_cols]); + std::unique_ptr values(new double[num_rows * num_cols]); // Column block structure bs->cols.push_back(Block()); diff --git a/internal/ceres/linear_least_squares_problems.h b/internal/ceres/linear_least_squares_problems.h index 384efb59a..5dfcd34e1 100644 --- a/internal/ceres/linear_least_squares_problems.h +++ b/internal/ceres/linear_least_squares_problems.h @@ -31,11 +31,11 @@ #ifndef CERES_INTERNAL_LINEAR_LEAST_SQUARES_PROBLEMS_H_ #define CERES_INTERNAL_LINEAR_LEAST_SQUARES_PROBLEMS_H_ +#include #include #include #include "ceres/sparse_matrix.h" #include "ceres/internal/port.h" -#include "ceres/internal/scoped_ptr.h" namespace ceres { namespace internal { @@ -44,21 +44,20 @@ namespace internal { // ground truth solutions. To be used by various LinearSolver tests. struct LinearLeastSquaresProblem { LinearLeastSquaresProblem() - : A(NULL), b(NULL), D(NULL), num_eliminate_blocks(0), - x(NULL), x_D(NULL) { + : num_eliminate_blocks(0) { } - scoped_ptr A; - scoped_array b; - scoped_array D; + std::unique_ptr A; + std::unique_ptr b; + std::unique_ptr D; // If using the schur eliminator then how many of the variable // blocks are e_type blocks. int num_eliminate_blocks; // Solution to min_x |Ax - b|^2 - scoped_array x; + std::unique_ptr x; // Solution to min_x |Ax - b|^2 + |Dx|^2 - scoped_array x_D; + std::unique_ptr x_D; }; // Factories for linear least squares problem. diff --git a/internal/ceres/local_parameterization_test.cc b/internal/ceres/local_parameterization_test.cc index 15f0bb136..41c78cb68 100644 --- a/internal/ceres/local_parameterization_test.cc +++ b/internal/ceres/local_parameterization_test.cc @@ -30,6 +30,8 @@ #include #include +#include + #include "Eigen/Geometry" #include "ceres/autodiff_local_parameterization.h" #include "ceres/fpclassify.h" @@ -611,10 +613,10 @@ class ProductParameterizationTest : public ::testing::Test { constant_parameters4)); } - scoped_ptr param1_; - scoped_ptr param2_; - scoped_ptr param3_; - scoped_ptr param4_; + std::unique_ptr param1_; + std::unique_ptr param2_; + std::unique_ptr param3_; + std::unique_ptr param4_; }; TEST_F(ProductParameterizationTest, LocalAndGlobalSize2) { diff --git a/internal/ceres/normal_prior.cc b/internal/ceres/normal_prior.cc index b3666cd70..a3d5d8ed7 100644 --- a/internal/ceres/normal_prior.cc +++ b/internal/ceres/normal_prior.cc @@ -33,7 +33,6 @@ #include #include #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/types.h" #include "glog/logging.h" diff --git a/internal/ceres/numeric_diff_cost_function_test.cc b/internal/ceres/numeric_diff_cost_function_test.cc index 983f11e11..f006ff0f1 100644 --- a/internal/ceres/numeric_diff_cost_function_test.cc +++ b/internal/ceres/numeric_diff_cost_function_test.cc @@ -33,10 +33,11 @@ #include #include +#include #include #include + #include "ceres/internal/macros.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/array_utils.h" #include "ceres/numeric_diff_test_utils.h" #include "ceres/test_util.h" @@ -48,7 +49,7 @@ namespace ceres { namespace internal { TEST(NumericDiffCostFunction, EasyCaseFunctorCentralDifferences) { - internal::scoped_ptr cost_function; + std::unique_ptr cost_function; cost_function.reset( new NumericDiffCostFunction cost_function; + std::unique_ptr cost_function; cost_function.reset( new NumericDiffCostFunction cost_function; + std::unique_ptr cost_function; cost_function.reset( new NumericDiffCostFunction cost_function; + std::unique_ptr cost_function; cost_function.reset( new NumericDiffCostFunction cost_function; + std::unique_ptr cost_function; cost_function.reset( new NumericDiffCostFunction cost_function; + std::unique_ptr cost_function; cost_function.reset( new NumericDiffCostFunction cost_function; + std::unique_ptr cost_function; cost_function.reset( new NumericDiffCostFunction cost_function; + std::unique_ptr cost_function; cost_function.reset( new NumericDiffCostFunction cost_function; + std::unique_ptr cost_function; cost_function.reset( new NumericDiffCostFunction cost_function; + std::unique_ptr cost_function; cost_function.reset( new NumericDiffCostFunction cost_function; + std::unique_ptr cost_function; cost_function.reset( new NumericDiffCostFunction cost_function; + std::unique_ptr cost_function; cost_function.reset( new NumericDiffCostFunction { // templates are instantiated for various shapes of the Jacobian // matrix. TEST(NumericDiffCostFunction, EigenRowMajorColMajorTest) { - scoped_ptr cost_function; + std::unique_ptr cost_function; cost_function.reset( new NumericDiffCostFunction, CENTRAL, 1, 1>( new SizeTestingCostFunction<1,1>, ceres::TAKE_OWNERSHIP)); @@ -282,7 +283,7 @@ TEST(NumericDiffCostFunction, EigenRowMajorColMajorTest) { TEST(NumericDiffCostFunction, EasyCaseFunctorCentralDifferencesAndDynamicNumResiduals) { - internal::scoped_ptr cost_function; + std::unique_ptr cost_function; cost_function.reset( new NumericDiffCostFunction cost_function; + std::unique_ptr cost_function; cost_function.reset( new NumericDiffCostFunction cost_function; + std::unique_ptr cost_function; cost_function.reset( new NumericDiffCostFunction cost_function; + std::unique_ptr cost_function; NumericDiffOptions options; // Larger initial step size is chosen to produce robust results in the // presence of random noise. @@ -337,7 +338,7 @@ TEST(NumericDiffCostFunction, RandomizedFunctorRidders) { } TEST(NumericDiffCostFunction, RandomizedCostFunctionRidders) { - internal::scoped_ptr cost_function; + std::unique_ptr cost_function; NumericDiffOptions options; // Larger initial step size is chosen to produce robust results in the // presence of random noise. @@ -368,7 +369,7 @@ TEST(NumericDiffCostFunction, PartiallyFilledResidualShouldFailEvaluation) { double* parameters[] = {¶meter}; double* jacobians[] = {jacobian}; - scoped_ptr cost_function( + std::unique_ptr cost_function( new NumericDiffCostFunction( new OnlyFillsOneOutputFunctor)); InvalidateArray(2, jacobian); diff --git a/internal/ceres/parameter_block.h b/internal/ceres/parameter_block.h index a41d9d188..9149a5488 100644 --- a/internal/ceres/parameter_block.h +++ b/internal/ceres/parameter_block.h @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -40,7 +41,6 @@ #include "ceres/integral_types.h" #include "ceres/internal/eigen.h" #include "ceres/internal/port.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/local_parameterization.h" #include "ceres/stringprintf.h" #include "glog/logging.h" @@ -368,7 +368,7 @@ class ParameterBlock { // ends up simplifying the internals of Ceres enough to justify the potential // pitfalls of using "mutable." mutable const double* state_; - mutable scoped_array local_parameterization_jacobian_; + mutable std::unique_ptr local_parameterization_jacobian_; // The index of the parameter. This is used by various other parts of Ceres to // permit switching from a ParameterBlock* to an index in another array. @@ -381,7 +381,7 @@ class ParameterBlock { int32 delta_offset_; // If non-null, contains the residual blocks this parameter block is in. - scoped_ptr residual_blocks_; + std::unique_ptr residual_blocks_; // Upper and lower bounds for the parameter block. SetUpperBound // and SetLowerBound lazily initialize the upper_bounds_ and @@ -394,8 +394,8 @@ class ParameterBlock { // std::numeric_limits::max() and // -std::numeric_limits::max() respectively which correspond // to the parameter block being unconstrained. - scoped_array upper_bounds_; - scoped_array lower_bounds_; + std::unique_ptr upper_bounds_; + std::unique_ptr lower_bounds_; // Necessary so ProblemImpl can clean up the parameterizations. friend class ProblemImpl; diff --git a/internal/ceres/parameter_block_ordering.cc b/internal/ceres/parameter_block_ordering.cc index 649ce1427..a71c01955 100644 --- a/internal/ceres/parameter_block_ordering.cc +++ b/internal/ceres/parameter_block_ordering.cc @@ -30,10 +30,11 @@ #include "ceres/parameter_block_ordering.h" +#include #include + #include "ceres/graph.h" #include "ceres/graph_algorithms.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/map_util.h" #include "ceres/parameter_block.h" #include "ceres/program.h" @@ -52,7 +53,7 @@ int ComputeStableSchurOrdering(const Program& program, vector* ordering) { CHECK_NOTNULL(ordering)->clear(); EventLogger event_logger("ComputeStableSchurOrdering"); - scoped_ptr > graph(CreateHessianGraph(program)); + std::unique_ptr > graph(CreateHessianGraph(program)); event_logger.AddEvent("CreateHessianGraph"); const vector& parameter_blocks = program.parameter_blocks(); @@ -83,7 +84,7 @@ int ComputeSchurOrdering(const Program& program, vector* ordering) { CHECK_NOTNULL(ordering)->clear(); - scoped_ptr > graph(CreateHessianGraph(program)); + std::unique_ptr > graph(CreateHessianGraph(program)); int independent_set_size = IndependentSetOrdering(*graph, ordering); const vector& parameter_blocks = program.parameter_blocks(); @@ -102,7 +103,7 @@ void ComputeRecursiveIndependentSetOrdering(const Program& program, ParameterBlockOrdering* ordering) { CHECK_NOTNULL(ordering)->Clear(); const vector parameter_blocks = program.parameter_blocks(); - scoped_ptr > graph(CreateHessianGraph(program)); + std::unique_ptr > graph(CreateHessianGraph(program)); int num_covered = 0; int round = 0; diff --git a/internal/ceres/parameter_block_ordering_test.cc b/internal/ceres/parameter_block_ordering_test.cc index 41babffdf..339e73b09 100644 --- a/internal/ceres/parameter_block_ordering_test.cc +++ b/internal/ceres/parameter_block_ordering_test.cc @@ -31,16 +31,17 @@ #include "ceres/parameter_block_ordering.h" #include +#include #include #include -#include "gtest/gtest.h" + +#include "ceres/cost_function.h" #include "ceres/graph.h" #include "ceres/problem_impl.h" #include "ceres/program.h" -#include "ceres/stl_util.h" -#include "ceres/cost_function.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/sized_cost_function.h" +#include "ceres/stl_util.h" +#include "gtest/gtest.h" namespace ceres { namespace internal { @@ -85,7 +86,7 @@ class SchurOrderingTest : public ::testing::Test { TEST_F(SchurOrderingTest, NoFixed) { const Program& program = problem_.program(); const vector& parameter_blocks = program.parameter_blocks(); - scoped_ptr graph(CreateHessianGraph(program)); + std::unique_ptr graph(CreateHessianGraph(program)); const VertexSet& vertices = graph->vertices(); EXPECT_EQ(vertices.size(), 4); @@ -130,7 +131,7 @@ TEST_F(SchurOrderingTest, AllFixed) { problem_.SetParameterBlockConstant(w_); const Program& program = problem_.program(); - scoped_ptr graph(CreateHessianGraph(program)); + std::unique_ptr graph(CreateHessianGraph(program)); EXPECT_EQ(graph->vertices().size(), 0); } @@ -139,7 +140,7 @@ TEST_F(SchurOrderingTest, OneFixed) { const Program& program = problem_.program(); const vector& parameter_blocks = program.parameter_blocks(); - scoped_ptr graph(CreateHessianGraph(program)); + std::unique_ptr graph(CreateHessianGraph(program)); const VertexSet& vertices = graph->vertices(); diff --git a/internal/ceres/partitioned_matrix_view_test.cc b/internal/ceres/partitioned_matrix_view_test.cc index 1e4889281..7eafff406 100644 --- a/internal/ceres/partitioned_matrix_view_test.cc +++ b/internal/ceres/partitioned_matrix_view_test.cc @@ -30,11 +30,11 @@ #include "ceres/partitioned_matrix_view.h" +#include #include #include "ceres/block_structure.h" #include "ceres/casts.h" #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/linear_least_squares_problems.h" #include "ceres/random.h" #include "ceres/sparse_matrix.h" @@ -50,7 +50,7 @@ class PartitionedMatrixViewTest : public ::testing::Test { protected : virtual void SetUp() { srand(5); - scoped_ptr problem( + std::unique_ptr problem( CreateLinearLeastSquaresProblemFromId(2)); CHECK_NOTNULL(problem.get()); A_.reset(problem->A.release()); @@ -68,8 +68,8 @@ class PartitionedMatrixViewTest : public ::testing::Test { int num_rows_; int num_cols_; int num_eliminate_blocks_; - scoped_ptr A_; - scoped_ptr pmv_; + std::unique_ptr A_; + std::unique_ptr pmv_; }; TEST_F(PartitionedMatrixViewTest, DimensionsTest) { @@ -143,7 +143,7 @@ TEST_F(PartitionedMatrixViewTest, LeftMultiply) { } TEST_F(PartitionedMatrixViewTest, BlockDiagonalEtE) { - scoped_ptr + std::unique_ptr block_diagonal_ee(pmv_->CreateBlockDiagonalEtE()); const CompressedRowBlockStructure* bs = block_diagonal_ee->block_structure(); @@ -157,7 +157,7 @@ TEST_F(PartitionedMatrixViewTest, BlockDiagonalEtE) { } TEST_F(PartitionedMatrixViewTest, BlockDiagonalFtF) { - scoped_ptr + std::unique_ptr block_diagonal_ff(pmv_->CreateBlockDiagonalFtF()); const CompressedRowBlockStructure* bs = block_diagonal_ff->block_structure(); diff --git a/internal/ceres/preprocessor.h b/internal/ceres/preprocessor.h index ce2eec5c0..37e42041a 100644 --- a/internal/ceres/preprocessor.h +++ b/internal/ceres/preprocessor.h @@ -39,7 +39,6 @@ #include "ceres/evaluator.h" #include "ceres/internal/eigen.h" #include "ceres/internal/port.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/iteration_callback.h" #include "ceres/linear_solver.h" #include "ceres/minimizer.h" @@ -92,11 +91,11 @@ struct PreprocessedProblem { Minimizer::Options minimizer_options; ProblemImpl* problem; - scoped_ptr gradient_checking_problem; - scoped_ptr reduced_program; - scoped_ptr linear_solver; - scoped_ptr logging_callback; - scoped_ptr state_updating_callback; + std::unique_ptr gradient_checking_problem; + std::unique_ptr reduced_program; + std::unique_ptr linear_solver; + std::unique_ptr logging_callback; + std::unique_ptr state_updating_callback; std::shared_ptr evaluator; std::shared_ptr inner_iteration_minimizer; diff --git a/internal/ceres/problem_impl.cc b/internal/ceres/problem_impl.cc index 1f3c55ba0..94af8ad26 100644 --- a/internal/ceres/problem_impl.cc +++ b/internal/ceres/problem_impl.cc @@ -34,10 +34,12 @@ #include #include #include +#include #include #include #include #include + #include "ceres/casts.h" #include "ceres/compressed_row_jacobian_writer.h" #include "ceres/compressed_row_sparse_matrix.h" @@ -822,7 +824,7 @@ bool ProblemImpl::Evaluate(const Problem::EvaluateOptions& evaluate_options, context_impl_->EnsureMinimumThreads(evaluator_options.num_threads - 1); evaluator_options.context = context_impl_; - scoped_ptr evaluator( + std::unique_ptr evaluator( new ProgramEvaluator(evaluator_options, &program)); @@ -835,7 +837,7 @@ bool ProblemImpl::Evaluate(const Problem::EvaluateOptions& evaluate_options, gradient->resize(evaluator->NumEffectiveParameters()); } - scoped_ptr tmp_jacobian; + std::unique_ptr tmp_jacobian; if (jacobian != NULL) { tmp_jacobian.reset( down_cast(evaluator->CreateJacobian())); diff --git a/internal/ceres/problem_impl.h b/internal/ceres/problem_impl.h index 4c24e3b48..44d6e89e0 100644 --- a/internal/ceres/problem_impl.h +++ b/internal/ceres/problem_impl.h @@ -40,13 +40,13 @@ #define CERES_PUBLIC_PROBLEM_IMPL_H_ #include +#include #include #include #include "ceres/context_impl.h" #include "ceres/internal/macros.h" #include "ceres/internal/port.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/problem.h" #include "ceres/types.h" @@ -209,7 +209,7 @@ class ProblemImpl { ResidualBlockSet residual_block_set_; // The actual parameter and residual blocks. - internal::scoped_ptr program_; + std::unique_ptr program_; // When removing parameter blocks, parameterizations have ambiguous // ownership. Instead of scanning the entire problem to see if the diff --git a/internal/ceres/problem_test.cc b/internal/ceres/problem_test.cc index 826e2c28c..3473c59a8 100644 --- a/internal/ceres/problem_test.cc +++ b/internal/ceres/problem_test.cc @@ -32,12 +32,12 @@ #include "ceres/problem.h" #include "ceres/problem_impl.h" +#include #include "ceres/casts.h" #include "ceres/cost_function.h" #include "ceres/crs_matrix.h" #include "ceres/evaluator_test_utils.h" #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/local_parameterization.h" #include "ceres/loss_function.h" #include "ceres/map_util.h" @@ -496,7 +496,7 @@ struct DynamicProblem : public ::testing::TestWithParam { ExpectParameterBlockContainsResidualBlock(values, r4); } - scoped_ptr problem; + std::unique_ptr problem; double y[4], z[5], w[3]; }; diff --git a/internal/ceres/program.cc b/internal/ceres/program.cc index f6cd13888..31b5d1a78 100644 --- a/internal/ceres/program.cc +++ b/internal/ceres/program.cc @@ -31,7 +31,9 @@ #include "ceres/program.h" #include +#include #include + #include "ceres/array_utils.h" #include "ceres/casts.h" #include "ceres/compressed_row_sparse_matrix.h" @@ -274,7 +276,7 @@ Program* Program::CreateReducedProgram( CHECK_NOTNULL(fixed_cost); CHECK_NOTNULL(error); - scoped_ptr reduced_program(new Program(*this)); + std::unique_ptr reduced_program(new Program(*this)); if (!reduced_program->RemoveFixedBlocks(removed_parameter_blocks, fixed_cost, error)) { @@ -292,7 +294,7 @@ bool Program::RemoveFixedBlocks(vector* removed_parameter_blocks, CHECK_NOTNULL(fixed_cost); CHECK_NOTNULL(error); - scoped_array residual_block_evaluate_scratch; + std::unique_ptr residual_block_evaluate_scratch; residual_block_evaluate_scratch.reset( new double[MaxScratchDoublesNeededForEvaluate()]); *fixed_cost = 0.0; diff --git a/internal/ceres/program_evaluator.h b/internal/ceres/program_evaluator.h index 10dcc066d..17175a684 100644 --- a/internal/ceres/program_evaluator.h +++ b/internal/ceres/program_evaluator.h @@ -83,12 +83,12 @@ #include "ceres/internal/port.h" #include +#include #include #include #include "ceres/evaluation_callback.h" #include "ceres/execution_summary.h" #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/parameter_block.h" #include "ceres/program.h" #include "ceres/residual_block.h" @@ -373,12 +373,12 @@ class ProgramEvaluator : public Evaluator { } double cost; - scoped_array residual_block_evaluate_scratch; + std::unique_ptr residual_block_evaluate_scratch; // The gradient in the local parameterization. - scoped_array gradient; + std::unique_ptr gradient; // Enough space to store the residual for the largest residual block. - scoped_array residual_block_residuals; - scoped_array jacobian_block_ptrs; + std::unique_ptr residual_block_residuals; + std::unique_ptr jacobian_block_ptrs; }; static void BuildResidualLayout(const Program& program, @@ -418,8 +418,8 @@ class ProgramEvaluator : public Evaluator { Evaluator::Options options_; Program* program_; JacobianWriter jacobian_writer_; - scoped_array evaluate_preparers_; - scoped_array evaluate_scratch_; + std::unique_ptr evaluate_preparers_; + std::unique_ptr evaluate_scratch_; std::vector residual_layout_; ::ceres::internal::ExecutionSummary execution_summary_; }; diff --git a/internal/ceres/program_test.cc b/internal/ceres/program_test.cc index 7bf512fe3..677848496 100644 --- a/internal/ceres/program_test.cc +++ b/internal/ceres/program_test.cc @@ -30,9 +30,11 @@ #include "ceres/program.h" -#include #include +#include +#include #include + #include "ceres/sized_cost_function.h" #include "ceres/problem_impl.h" #include "ceres/residual_block.h" @@ -94,7 +96,7 @@ TEST(Program, RemoveFixedBlocksNothingConstant) { vector removed_parameter_blocks; double fixed_cost = 0.0; string message; - scoped_ptr reduced_program( + std::unique_ptr reduced_program( CHECK_NOTNULL(problem .program() .CreateReducedProgram(&removed_parameter_blocks, @@ -118,7 +120,7 @@ TEST(Program, RemoveFixedBlocksAllParameterBlocksConstant) { vector removed_parameter_blocks; double fixed_cost = 0.0; string message; - scoped_ptr reduced_program( + std::unique_ptr reduced_program( CHECK_NOTNULL(problem .program() .CreateReducedProgram(&removed_parameter_blocks, @@ -145,7 +147,7 @@ TEST(Program, RemoveFixedBlocksNoResidualBlocks) { vector removed_parameter_blocks; double fixed_cost = 0.0; string message; - scoped_ptr reduced_program( + std::unique_ptr reduced_program( CHECK_NOTNULL(problem .program() .CreateReducedProgram(&removed_parameter_blocks, @@ -174,7 +176,7 @@ TEST(Program, RemoveFixedBlocksOneParameterBlockConstant) { vector removed_parameter_blocks; double fixed_cost = 0.0; string message; - scoped_ptr reduced_program( + std::unique_ptr reduced_program( CHECK_NOTNULL(problem .program() .CreateReducedProgram(&removed_parameter_blocks, @@ -201,7 +203,7 @@ TEST(Program, RemoveFixedBlocksNumEliminateBlocks) { vector removed_parameter_blocks; double fixed_cost = 0.0; string message; - scoped_ptr reduced_program( + std::unique_ptr reduced_program( CHECK_NOTNULL(problem .program() .CreateReducedProgram(&removed_parameter_blocks, @@ -227,7 +229,7 @@ TEST(Program, RemoveFixedBlocksFixedCost) { ResidualBlock *expected_removed_block = problem.program().residual_blocks()[0]; - scoped_array scratch( + std::unique_ptr scratch( new double[expected_removed_block->NumScratchDoublesForEvaluate()]); double expected_fixed_cost; expected_removed_block->Evaluate(true, @@ -240,7 +242,7 @@ TEST(Program, RemoveFixedBlocksFixedCost) { vector removed_parameter_blocks; double fixed_cost = 0.0; string message; - scoped_ptr reduced_program( + std::unique_ptr reduced_program( CHECK_NOTNULL(problem .program() .CreateReducedProgram(&removed_parameter_blocks, @@ -318,7 +320,7 @@ TEST(Program, CreateJacobianBlockSparsityTranspose) { Program* program = problem.mutable_program(); program->SetParameterOffsetsAndIndex(); - scoped_ptr actual_block_sparse_jacobian( + std::unique_ptr actual_block_sparse_jacobian( program->CreateJacobianBlockSparsityTranspose()); Matrix expected_dense_jacobian; @@ -385,7 +387,7 @@ TEST(Program, ReallocationInCreateJacobianBlockSparsityTranspose) { Program* program = problem.mutable_program(); program->SetParameterOffsetsAndIndex(); - scoped_ptr actual_block_sparse_jacobian( + std::unique_ptr actual_block_sparse_jacobian( program->CreateJacobianBlockSparsityTranspose()); Matrix expected_dense_jacobian; diff --git a/internal/ceres/reorder_program.cc b/internal/ceres/reorder_program.cc index 94a35bdab..f3480a35e 100644 --- a/internal/ceres/reorder_program.cc +++ b/internal/ceres/reorder_program.cc @@ -31,6 +31,7 @@ #include "ceres/reorder_program.h" #include +#include #include #include @@ -359,7 +360,7 @@ void MaybeReorderSchurComplementColumnsUsingSuiteSparse( MapValuesToContiguousRange(constraints.size(), &constraints[0]); // Compute a block sparse presentation of J'. - scoped_ptr tsm_block_jacobian_transpose( + std::unique_ptr tsm_block_jacobian_transpose( program->CreateJacobianBlockSparsityTranspose()); cholmod_sparse* block_jacobian_transpose = @@ -388,7 +389,7 @@ void MaybeReorderSchurComplementColumnsUsingEigen( return; #else - scoped_ptr tsm_block_jacobian_transpose( + std::unique_ptr tsm_block_jacobian_transpose( program->CreateJacobianBlockSparsityTranspose()); typedef Eigen::SparseMatrix SparseMatrix; @@ -550,7 +551,7 @@ bool ReorderProgramForSparseNormalCholesky( } // Compute a block sparse presentation of J'. - scoped_ptr tsm_block_jacobian_transpose( + std::unique_ptr tsm_block_jacobian_transpose( program->CreateJacobianBlockSparsityTranspose()); vector ordering(program->NumParameterBlocks(), 0); diff --git a/internal/ceres/residual_block.h b/internal/ceres/residual_block.h index a32f1c36c..815a7a1ca 100644 --- a/internal/ceres/residual_block.h +++ b/internal/ceres/residual_block.h @@ -34,12 +34,12 @@ #ifndef CERES_INTERNAL_RESIDUAL_BLOCK_H_ #define CERES_INTERNAL_RESIDUAL_BLOCK_H_ +#include #include #include #include "ceres/cost_function.h" #include "ceres/internal/port.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/stringprintf.h" #include "ceres/types.h" @@ -134,7 +134,7 @@ class ResidualBlock { private: const CostFunction* cost_function_; const LossFunction* loss_function_; - scoped_array parameter_blocks_; + std::unique_ptr parameter_blocks_; // The index of the residual, typically in a Program. This is only to permit // switching from a ResidualBlock* to an index in the Program's array, needed diff --git a/internal/ceres/residual_block_utils_test.cc b/internal/ceres/residual_block_utils_test.cc index 3a7e9c3d7..3beaa1009 100644 --- a/internal/ceres/residual_block_utils_test.cc +++ b/internal/ceres/residual_block_utils_test.cc @@ -30,12 +30,12 @@ #include #include +#include #include "gtest/gtest.h" #include "ceres/parameter_block.h" #include "ceres/residual_block.h" #include "ceres/residual_block_utils.h" #include "ceres/cost_function.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/sized_cost_function.h" namespace ceres { @@ -54,7 +54,7 @@ void CheckEvaluation(const CostFunction& cost_function, bool is_good) { parameter_blocks, -1); - scoped_array scratch( + std::unique_ptr scratch( new double[residual_block.NumScratchDoublesForEvaluate()]); double cost; diff --git a/internal/ceres/schur_complement_solver.cc b/internal/ceres/schur_complement_solver.cc index 16470fd8a..0fb9c309d 100644 --- a/internal/ceres/schur_complement_solver.cc +++ b/internal/ceres/schur_complement_solver.cc @@ -32,6 +32,7 @@ #include #include +#include #include #include @@ -45,7 +46,6 @@ #include "ceres/conjugate_gradients_solver.h" #include "ceres/detect_structure.h" #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/lapack.h" #include "ceres/linear_solver.h" #include "ceres/sparse_cholesky.h" @@ -325,7 +325,7 @@ LinearSolver::Summary SparseSchurComplementSolver::SolveReducedLinearSystem( return summary; } - scoped_ptr lhs; + std::unique_ptr lhs; const CompressedRowSparseMatrix::StorageType storage_type = sparse_cholesky_->StorageType(); if (storage_type == CompressedRowSparseMatrix::UPPER_TRIANGULAR) { @@ -399,9 +399,9 @@ SparseSchurComplementSolver::SolveReducedLinearSystemUsingConjugateGradients( VectorRef(solution, num_rows).setZero(); - scoped_ptr lhs_adapter( + std::unique_ptr lhs_adapter( new BlockRandomAccessSparseMatrixAdapter(*sc)); - scoped_ptr preconditioner_adapter( + std::unique_ptr preconditioner_adapter( new BlockRandomAccessDiagonalMatrixAdapter(*preconditioner_)); diff --git a/internal/ceres/schur_complement_solver.h b/internal/ceres/schur_complement_solver.h index e83a715d9..5f15c8680 100644 --- a/internal/ceres/schur_complement_solver.h +++ b/internal/ceres/schur_complement_solver.h @@ -31,6 +31,7 @@ #ifndef CERES_INTERNAL_SCHUR_COMPLEMENT_SOLVER_H_ #define CERES_INTERNAL_SCHUR_COMPLEMENT_SOLVER_H_ +#include #include #include #include @@ -40,7 +41,6 @@ #include "ceres/block_sparse_matrix.h" #include "ceres/block_structure.h" #include "ceres/internal/port.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/linear_solver.h" #include "ceres/schur_eliminator.h" #include "ceres/types.h" @@ -140,9 +140,9 @@ class SchurComplementSolver : public BlockSparseMatrixSolver { LinearSolver::Options options_; - scoped_ptr eliminator_; - scoped_ptr lhs_; - scoped_array rhs_; + std::unique_ptr eliminator_; + std::unique_ptr lhs_; + std::unique_ptr rhs_; CERES_DISALLOW_COPY_AND_ASSIGN(SchurComplementSolver); }; @@ -180,8 +180,8 @@ class SparseSchurComplementSolver : public SchurComplementSolver { // Size of the blocks in the Schur complement. std::vector blocks_; - scoped_ptr sparse_cholesky_; - scoped_ptr preconditioner_; + std::unique_ptr sparse_cholesky_; + std::unique_ptr preconditioner_; CERES_DISALLOW_COPY_AND_ASSIGN(SparseSchurComplementSolver); }; diff --git a/internal/ceres/schur_complement_solver_test.cc b/internal/ceres/schur_complement_solver_test.cc index 3f70300b5..2350858f5 100644 --- a/internal/ceres/schur_complement_solver_test.cc +++ b/internal/ceres/schur_complement_solver_test.cc @@ -31,13 +31,13 @@ #include "ceres/schur_complement_solver.h" #include +#include #include "ceres/block_sparse_matrix.h" #include "ceres/block_structure.h" #include "ceres/casts.h" #include "ceres/context_impl.h" #include "ceres/detect_structure.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/linear_least_squares_problems.h" #include "ceres/linear_solver.h" #include "ceres/triplet_sparse_matrix.h" @@ -51,7 +51,7 @@ namespace internal { class SchurComplementSolverTest : public ::testing::Test { protected: void SetUpFromProblemId(int problem_id) { - scoped_ptr problem( + std::unique_ptr problem( CreateLinearLeastSquaresProblemFromId(problem_id)); CHECK_NOTNULL(problem.get()); @@ -72,7 +72,7 @@ class SchurComplementSolverTest : public ::testing::Test { ContextImpl context; options.context = &context; - scoped_ptr qr(LinearSolver::Create(options)); + std::unique_ptr qr(LinearSolver::Create(options)); TripletSparseMatrix triplet_A(A->num_rows(), A->num_cols(), @@ -115,7 +115,7 @@ class SchurComplementSolverTest : public ::testing::Test { &options.e_block_size, &options.f_block_size); - scoped_ptr solver(LinearSolver::Create(options)); + std::unique_ptr solver(LinearSolver::Create(options)); LinearSolver::PerSolveOptions per_solve_options; LinearSolver::Summary summary; @@ -142,9 +142,9 @@ class SchurComplementSolverTest : public ::testing::Test { int num_cols; int num_eliminate_blocks; - scoped_ptr A; - scoped_array b; - scoped_array D; + std::unique_ptr A; + std::unique_ptr b; + std::unique_ptr D; Vector x; Vector sol; Vector sol_d; diff --git a/internal/ceres/schur_eliminator.h b/internal/ceres/schur_eliminator.h index df0d22da8..d93bcb0b1 100644 --- a/internal/ceres/schur_eliminator.h +++ b/internal/ceres/schur_eliminator.h @@ -32,13 +32,14 @@ #define CERES_INTERNAL_SCHUR_ELIMINATOR_H_ #include +#include #include #include + #include "ceres/block_random_access_matrix.h" #include "ceres/block_sparse_matrix.h" #include "ceres/block_structure.h" #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/linear_solver.h" namespace ceres { @@ -343,7 +344,7 @@ class SchurEliminator : public SchurEliminatorBase { // // [thread_id * buffer_size_ , (thread_id + 1) * buffer_size_] // - scoped_array buffer_; + std::unique_ptr buffer_; // Buffer to store per thread matrix matrix products used by // ChunkOuterProduct. Like buffer_ it is of size num_threads * @@ -351,7 +352,7 @@ class SchurEliminator : public SchurEliminatorBase { // // [thread_id * buffer_size_ , (thread_id + 1) * buffer_size_ -1] // - scoped_array chunk_outer_product_buffer_; + std::unique_ptr chunk_outer_product_buffer_; int buffer_size_; int uneliminated_row_begins_; diff --git a/internal/ceres/schur_eliminator_impl.h b/internal/ceres/schur_eliminator_impl.h index 628d99883..da5d922e3 100644 --- a/internal/ceres/schur_eliminator_impl.h +++ b/internal/ceres/schur_eliminator_impl.h @@ -50,12 +50,12 @@ #include #include + #include "ceres/block_random_access_matrix.h" #include "ceres/block_sparse_matrix.h" #include "ceres/block_structure.h" #include "ceres/internal/eigen.h" #include "ceres/internal/fixed_array.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/invert_psd_matrix.h" #include "ceres/map_util.h" #include "ceres/schur_eliminator.h" diff --git a/internal/ceres/schur_eliminator_test.cc b/internal/ceres/schur_eliminator_test.cc index 9826d876e..6197bfc34 100644 --- a/internal/ceres/schur_eliminator_test.cc +++ b/internal/ceres/schur_eliminator_test.cc @@ -30,6 +30,7 @@ #include "ceres/schur_eliminator.h" +#include #include "Eigen/Dense" #include "ceres/block_random_access_dense_matrix.h" #include "ceres/block_sparse_matrix.h" @@ -37,7 +38,6 @@ #include "ceres/context_impl.h" #include "ceres/detect_structure.h" #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/linear_least_squares_problems.h" #include "ceres/test_util.h" #include "ceres/triplet_sparse_matrix.h" @@ -54,7 +54,7 @@ namespace internal { class SchurEliminatorTest : public ::testing::Test { protected: void SetUpFromId(int id) { - scoped_ptr + std::unique_ptr problem(CreateLinearLeastSquaresProblemFromId(id)); CHECK_NOTNULL(problem.get()); SetupHelper(problem.get()); @@ -154,7 +154,7 @@ class SchurEliminatorTest : public ::testing::Test { &options.f_block_size); } - scoped_ptr eliminator; + std::unique_ptr eliminator; eliminator.reset(SchurEliminatorBase::Create(options)); const bool kFullRankETE = true; eliminator->Init(num_eliminate_blocks, kFullRankETE, A->block_structure()); @@ -186,9 +186,9 @@ class SchurEliminatorTest : public ::testing::Test { relative_tolerance); } - scoped_ptr A; - scoped_array b; - scoped_array D; + std::unique_ptr A; + std::unique_ptr b; + std::unique_ptr D; int num_eliminate_blocks; int num_eliminate_cols; diff --git a/internal/ceres/schur_jacobi_preconditioner.cc b/internal/ceres/schur_jacobi_preconditioner.cc index 13e6463fe..3ad5dd7c2 100644 --- a/internal/ceres/schur_jacobi_preconditioner.cc +++ b/internal/ceres/schur_jacobi_preconditioner.cc @@ -32,9 +32,9 @@ #include #include + #include "ceres/block_random_access_diagonal_matrix.h" #include "ceres/block_sparse_matrix.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/linear_solver.h" #include "ceres/schur_eliminator.h" #include "glog/logging.h" diff --git a/internal/ceres/schur_jacobi_preconditioner.h b/internal/ceres/schur_jacobi_preconditioner.h index fb7753bda..2a61d6fa1 100644 --- a/internal/ceres/schur_jacobi_preconditioner.h +++ b/internal/ceres/schur_jacobi_preconditioner.h @@ -38,11 +38,12 @@ #ifndef CERES_INTERNAL_SCHUR_JACOBI_PRECONDITIONER_H_ #define CERES_INTERNAL_SCHUR_JACOBI_PRECONDITIONER_H_ +#include #include -#include #include +#include + #include "ceres/internal/macros.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/preconditioner.h" namespace ceres { @@ -93,9 +94,9 @@ class SchurJacobiPreconditioner : public BlockSparseMatrixPreconditioner { virtual bool UpdateImpl(const BlockSparseMatrix& A, const double* D); Preconditioner::Options options_; - scoped_ptr eliminator_; + std::unique_ptr eliminator_; // Preconditioner matrix. - scoped_ptr m_; + std::unique_ptr m_; CERES_DISALLOW_COPY_AND_ASSIGN(SchurJacobiPreconditioner); }; diff --git a/internal/ceres/scratch_evaluate_preparer.h b/internal/ceres/scratch_evaluate_preparer.h index fa9ebd0e5..c8d9b937b 100644 --- a/internal/ceres/scratch_evaluate_preparer.h +++ b/internal/ceres/scratch_evaluate_preparer.h @@ -35,7 +35,7 @@ #ifndef CERES_INTERNAL_SCRATCH_EVALUATE_PREPARER_H_ #define CERES_INTERNAL_SCRATCH_EVALUATE_PREPARER_H_ -#include "ceres/internal/scoped_ptr.h" +#include namespace ceres { namespace internal { @@ -60,7 +60,7 @@ class ScratchEvaluatePreparer { private: // Scratch space for the jacobians; each jacobian is packed one after another. // There is enough scratch to hold all the jacobians for the largest residual. - scoped_array jacobian_scratch_; + std::unique_ptr jacobian_scratch_; }; } // namespace internal diff --git a/internal/ceres/solver.cc b/internal/ceres/solver.cc index 4083c599a..de3329eae 100644 --- a/internal/ceres/solver.cc +++ b/internal/ceres/solver.cc @@ -32,8 +32,10 @@ #include "ceres/solver.h" #include +#include #include // NOLINT #include + #include "ceres/casts.h" #include "ceres/context.h" #include "ceres/context_impl.h" @@ -444,7 +446,6 @@ void PostSolveSummarize(const internal::PreprocessedProblem& pp, void Minimize(internal::PreprocessedProblem* pp, Solver::Summary* summary) { using internal::Program; - using internal::scoped_ptr; using internal::Minimizer; Program* program = pp->reduced_program.get(); @@ -459,7 +460,7 @@ void Minimize(internal::PreprocessedProblem* pp, } const Vector original_reduced_parameters = pp->reduced_parameters; - scoped_ptr minimizer( + std::unique_ptr minimizer( Minimizer::Create(pp->options.minimizer_type)); minimizer->Minimize(pp->minimizer_options, pp->reduced_parameters.data(), @@ -519,7 +520,6 @@ void Solver::Solve(const Solver::Options& options, using internal::Preprocessor; using internal::ProblemImpl; using internal::Program; - using internal::scoped_ptr; using internal::WallTimeInSeconds; CHECK_NOTNULL(problem); @@ -546,7 +546,7 @@ void Solver::Solve(const Solver::Options& options, // If gradient_checking is enabled, wrap all cost functions in a // gradient checker and install a callback that terminates if any gradient // error is detected. - scoped_ptr gradient_checking_problem; + std::unique_ptr gradient_checking_problem; internal::GradientCheckingIterationCallback gradient_checking_callback; Solver::Options modified_options = options; if (options.check_gradients) { @@ -561,7 +561,7 @@ void Solver::Solve(const Solver::Options& options, program = problem_impl->mutable_program(); } - scoped_ptr preprocessor( + std::unique_ptr preprocessor( Preprocessor::Create(modified_options.minimizer_type)); PreprocessedProblem pp; diff --git a/internal/ceres/solver_test.cc b/internal/ceres/solver_test.cc index 80f12e462..8f68fec4c 100644 --- a/internal/ceres/solver_test.cc +++ b/internal/ceres/solver_test.cc @@ -31,11 +31,11 @@ #include "ceres/solver.h" #include +#include #include #include #include "gtest/gtest.h" #include "ceres/evaluation_callback.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/autodiff_cost_function.h" #include "ceres/sized_cost_function.h" #include "ceres/problem.h" @@ -98,7 +98,7 @@ TEST(Solver, UpdateStateEveryIterationOption) { double x = 50.0; const double original_x = x; - scoped_ptr cost_function(QuadraticCostFunctor::Create()); + std::unique_ptr cost_function(QuadraticCostFunctor::Create()); Problem::Options problem_options; problem_options.cost_function_ownership = DO_NOT_TAKE_OWNERSHIP; Problem problem(problem_options); diff --git a/internal/ceres/sparse_cholesky.h b/internal/ceres/sparse_cholesky.h index d77cccd8b..85487bfb1 100644 --- a/internal/ceres/sparse_cholesky.h +++ b/internal/ceres/sparse_cholesky.h @@ -52,7 +52,7 @@ namespace internal { // // Example usage: // -// scoped_ptr +// std::unique_ptr // sparse_cholesky(SparseCholesky::Create(SUITE_SPARSE, AMD)); // // CompressedRowSparseMatrix lhs = ...; diff --git a/internal/ceres/sparse_cholesky_test.cc b/internal/ceres/sparse_cholesky_test.cc index c94beeadd..79db6898c 100644 --- a/internal/ceres/sparse_cholesky_test.cc +++ b/internal/ceres/sparse_cholesky_test.cc @@ -30,6 +30,7 @@ #include "ceres/sparse_cholesky.h" +#include #include #include @@ -39,7 +40,6 @@ #include "ceres/compressed_row_sparse_matrix.h" #include "ceres/inner_product_computer.h" #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/random.h" #include "glog/logging.h" #include "gtest/gtest.h" @@ -61,12 +61,12 @@ BlockSparseMatrix* CreateRandomFullRankMatrix(const int num_col_blocks, options.min_row_block_size = 1; options.max_row_block_size = max_col_block_size; options.block_density = block_density; - scoped_ptr random_matrix( + std::unique_ptr random_matrix( BlockSparseMatrix::CreateRandomMatrix(options)); // Add a diagonal block sparse matrix to make it full rank. Vector diagonal = Vector::Ones(random_matrix->num_cols()); - scoped_ptr block_diagonal( + std::unique_ptr block_diagonal( BlockSparseMatrix::CreateDiagonalMatrix( diagonal.data(), random_matrix->block_structure()->cols)); random_matrix->AppendRows(*block_diagonal); @@ -107,14 +107,14 @@ void SparseCholeskySolverUnitTest( const int min_block_size, const int max_block_size, const double block_density) { - scoped_ptr sparse_cholesky(SparseCholesky::Create( + std::unique_ptr sparse_cholesky(SparseCholesky::Create( sparse_linear_algebra_library_type, ordering_type)); const CompressedRowSparseMatrix::StorageType storage_type = sparse_cholesky->StorageType(); - scoped_ptr m(CreateRandomFullRankMatrix( + std::unique_ptr m(CreateRandomFullRankMatrix( num_blocks, min_block_size, max_block_size, block_density)); - scoped_ptr inner_product_computer( + std::unique_ptr inner_product_computer( InnerProductComputer::Create(*m, storage_type)); inner_product_computer->Compute(); CompressedRowSparseMatrix* lhs = inner_product_computer->mutable_result(); diff --git a/internal/ceres/sparse_normal_cholesky_solver.cc b/internal/ceres/sparse_normal_cholesky_solver.cc index 37f5a8efb..057287057 100644 --- a/internal/ceres/sparse_normal_cholesky_solver.cc +++ b/internal/ceres/sparse_normal_cholesky_solver.cc @@ -33,11 +33,11 @@ #include #include #include +#include #include "ceres/block_sparse_matrix.h" #include "ceres/inner_product_computer.h" #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/linear_solver.h" #include "ceres/sparse_cholesky.h" #include "ceres/triplet_sparse_matrix.h" @@ -76,7 +76,7 @@ LinearSolver::Summary SparseNormalCholeskySolver::SolveImpl( if (per_solve_options.D != NULL) { // Temporarily append a diagonal block to the A matrix, but undo // it before returning the matrix to the user. - scoped_ptr regularizer; + std::unique_ptr regularizer; regularizer.reset(BlockSparseMatrix::CreateDiagonalMatrix( per_solve_options.D, A->block_structure()->cols)); event_logger.AddEvent("Diagonal"); diff --git a/internal/ceres/sparse_normal_cholesky_solver.h b/internal/ceres/sparse_normal_cholesky_solver.h index e24799d52..537a2c936 100644 --- a/internal/ceres/sparse_normal_cholesky_solver.h +++ b/internal/ceres/sparse_normal_cholesky_solver.h @@ -63,8 +63,8 @@ class SparseNormalCholeskySolver : public BlockSparseMatrixSolver { double* x); const LinearSolver::Options options_; - scoped_ptr sparse_cholesky_; - scoped_ptr inner_product_computer_; + std::unique_ptr sparse_cholesky_; + std::unique_ptr inner_product_computer_; CERES_DISALLOW_COPY_AND_ASSIGN(SparseNormalCholeskySolver); }; diff --git a/internal/ceres/sparse_normal_cholesky_solver_test.cc b/internal/ceres/sparse_normal_cholesky_solver_test.cc index f99129835..1b836a5f0 100644 --- a/internal/ceres/sparse_normal_cholesky_solver_test.cc +++ b/internal/ceres/sparse_normal_cholesky_solver_test.cc @@ -28,10 +28,10 @@ // // Author: sameeragarwal@google.com (Sameer Agarwal) +#include #include "ceres/block_sparse_matrix.h" #include "ceres/casts.h" #include "ceres/context_impl.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/linear_least_squares_problems.h" #include "ceres/linear_solver.h" #include "ceres/triplet_sparse_matrix.h" @@ -54,7 +54,7 @@ namespace internal { class SparseNormalCholeskySolverTest : public ::testing::Test { protected: virtual void SetUp() { - scoped_ptr problem( + std::unique_ptr problem( CreateLinearLeastSquaresProblemFromId(2)); CHECK_NOTNULL(problem.get()); @@ -79,7 +79,7 @@ class SparseNormalCholeskySolverTest : public ::testing::Test { A_->LeftMultiply(b_.get(), rhs.data()); Vector expected_solution = lhs.llt().solve(rhs); - scoped_ptr solver(LinearSolver::Create(options)); + std::unique_ptr solver(LinearSolver::Create(options)); LinearSolver::PerSolveOptions per_solve_options; per_solve_options.D = D; Vector actual_solution(A_->num_cols()); @@ -101,9 +101,9 @@ class SparseNormalCholeskySolverTest : public ::testing::Test { TestSolver(options, D_.get()); } - scoped_ptr A_; - scoped_array b_; - scoped_array D_; + std::unique_ptr A_; + std::unique_ptr b_; + std::unique_ptr D_; }; #ifndef CERES_NO_SUITESPARSE diff --git a/internal/ceres/subset_preconditioner.cc b/internal/ceres/subset_preconditioner.cc index e970b9102..c7f5ef6e4 100644 --- a/internal/ceres/subset_preconditioner.cc +++ b/internal/ceres/subset_preconditioner.cc @@ -30,10 +30,10 @@ #include "ceres/subset_preconditioner.h" +#include #include #include "ceres/compressed_row_sparse_matrix.h" #include "ceres/inner_product_computer.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/linear_solver.h" #include "ceres/sparse_cholesky.h" #include "ceres/types.h" @@ -72,7 +72,7 @@ bool SubsetPreconditioner::UpdateImpl(const BlockSparseMatrix& A, // A = [P] // [Q] // [D] - scoped_ptr regularizer( + std::unique_ptr regularizer( BlockSparseMatrix::CreateDiagonalMatrix(D, bs->cols)); m->AppendRows(*regularizer); } diff --git a/internal/ceres/subset_preconditioner.h b/internal/ceres/subset_preconditioner.h index 062253b84..77c3d9127 100644 --- a/internal/ceres/subset_preconditioner.h +++ b/internal/ceres/subset_preconditioner.h @@ -31,7 +31,7 @@ #ifndef CERES_INTERNAL_SUBSET_PRECONDITIONER_H_ #define CERES_INTERNAL_SUBSET_PRECONDITIONER_H_ -#include "ceres/internal/scoped_ptr.h" +#include #include "ceres/preconditioner.h" namespace ceres { @@ -81,8 +81,8 @@ class SubsetPreconditioner : public BlockSparseMatrixPreconditioner { const Preconditioner::Options options_; const int num_cols_; - scoped_ptr sparse_cholesky_; - scoped_ptr inner_product_computer_; + std::unique_ptr sparse_cholesky_; + std::unique_ptr inner_product_computer_; }; } // namespace internal diff --git a/internal/ceres/subset_preconditioner_test.cc b/internal/ceres/subset_preconditioner_test.cc index 147ecf8be..b159e0f5a 100644 --- a/internal/ceres/subset_preconditioner_test.cc +++ b/internal/ceres/subset_preconditioner_test.cc @@ -28,6 +28,7 @@ // // Author: sameeragarwal@google.com (Sameer Agarwal) +#include #include "ceres/subset_preconditioner.h" #include "Eigen/Dense" #include "Eigen/SparseCore" @@ -35,7 +36,6 @@ #include "ceres/compressed_row_sparse_matrix.h" #include "ceres/inner_product_computer.h" #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "glog/logging.h" #include "gtest/gtest.h" @@ -118,11 +118,11 @@ class SubsetPreconditionerTest : public ::testing::TestWithParam { inner_product_computer_->Compute(); } - scoped_ptr m_; - scoped_ptr b_; - scoped_ptr block_diagonal_; - scoped_ptr inner_product_computer_; - scoped_ptr preconditioner_; + std::unique_ptr m_; + std::unique_ptr b_; + std::unique_ptr block_diagonal_; + std::unique_ptr inner_product_computer_; + std::unique_ptr preconditioner_; Vector diagonal_; int start_row_block_; }; diff --git a/internal/ceres/tiny_solver_cost_function_adapter_test.cc b/internal/ceres/tiny_solver_cost_function_adapter_test.cc index 364fea9da..620df41b5 100644 --- a/internal/ceres/tiny_solver_cost_function_adapter_test.cc +++ b/internal/ceres/tiny_solver_cost_function_adapter_test.cc @@ -32,9 +32,9 @@ #include #include +#include #include "ceres/cost_function.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/sized_cost_function.h" #include "gtest/gtest.h" @@ -67,7 +67,7 @@ class CostFunction2x3 : public SizedCostFunction<2,3> { template void TestHelper() { - internal::scoped_ptr cost_function(new CostFunction2x3); + std::unique_ptr cost_function(new CostFunction2x3); typedef TinySolverCostFunctionAdapter CostFunctionAdapter; CostFunctionAdapter cfa(*cost_function); EXPECT_EQ(CostFunctionAdapter::NUM_RESIDUALS, kNumResiduals); diff --git a/internal/ceres/triplet_sparse_matrix.cc b/internal/ceres/triplet_sparse_matrix.cc index cd19444b0..8920747ae 100644 --- a/internal/ceres/triplet_sparse_matrix.cc +++ b/internal/ceres/triplet_sparse_matrix.cc @@ -32,9 +32,9 @@ #include #include + #include "ceres/internal/eigen.h" #include "ceres/internal/port.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/random.h" #include "ceres/types.h" #include "glog/logging.h" diff --git a/internal/ceres/triplet_sparse_matrix.h b/internal/ceres/triplet_sparse_matrix.h index 1d82e14d4..606f8e87d 100644 --- a/internal/ceres/triplet_sparse_matrix.h +++ b/internal/ceres/triplet_sparse_matrix.h @@ -31,10 +31,10 @@ #ifndef CERES_INTERNAL_TRIPLET_SPARSE_MATRIX_H_ #define CERES_INTERNAL_TRIPLET_SPARSE_MATRIX_H_ +#include #include #include "ceres/sparse_matrix.h" #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/types.h" namespace ceres { @@ -144,9 +144,9 @@ class TripletSparseMatrix : public SparseMatrix { // stored at the location (rows_[i], cols_[i]). If the there are // multiple entries with the same (rows_[i], cols_[i]), the values_ // entries corresponding to them are summed up. - scoped_array rows_; - scoped_array cols_; - scoped_array values_; + std::unique_ptr rows_; + std::unique_ptr cols_; + std::unique_ptr values_; }; } // namespace internal diff --git a/internal/ceres/triplet_sparse_matrix_test.cc b/internal/ceres/triplet_sparse_matrix_test.cc index 730272e40..d71df7b79 100644 --- a/internal/ceres/triplet_sparse_matrix_test.cc +++ b/internal/ceres/triplet_sparse_matrix_test.cc @@ -30,8 +30,8 @@ #include "ceres/triplet_sparse_matrix.h" +#include #include "gtest/gtest.h" -#include "ceres/internal/scoped_ptr.h" namespace ceres { namespace internal { @@ -279,11 +279,11 @@ TEST(TripletSparseMatrix, AppendCols) { } TEST(TripletSparseMatrix, CreateDiagonalMatrix) { - scoped_array values(new double[10]); + std::unique_ptr values(new double[10]); for (int i = 0; i < 10; ++i) values[i] = i; - scoped_ptr m( + std::unique_ptr m( TripletSparseMatrix::CreateSparseDiagonalMatrix(values.get(), 10)); EXPECT_EQ(m->num_rows(), 10); EXPECT_EQ(m->num_cols(), 10); diff --git a/internal/ceres/trust_region_minimizer.cc b/internal/ceres/trust_region_minimizer.cc index a863e6366..cd57abff7 100644 --- a/internal/ceres/trust_region_minimizer.cc +++ b/internal/ceres/trust_region_minimizer.cc @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -573,7 +574,7 @@ void TrustRegionMinimizer::DoLineSearch(const Vector& x, line_search_options.function = &line_search_function; std::string message; - scoped_ptr line_search(CHECK_NOTNULL( + std::unique_ptr line_search(CHECK_NOTNULL( LineSearch::Create(ceres::ARMIJO, line_search_options, &message))); LineSearch::Summary line_search_summary; line_search_function.Init(x, *delta); diff --git a/internal/ceres/trust_region_minimizer.h b/internal/ceres/trust_region_minimizer.h index 9c5274d7f..8ddd77e11 100644 --- a/internal/ceres/trust_region_minimizer.h +++ b/internal/ceres/trust_region_minimizer.h @@ -31,8 +31,8 @@ #ifndef CERES_INTERNAL_TRUST_REGION_MINIMIZER_H_ #define CERES_INTERNAL_TRUST_REGION_MINIMIZER_H_ +#include #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/minimizer.h" #include "ceres/solver.h" #include "ceres/sparse_matrix.h" @@ -94,7 +94,7 @@ class TrustRegionMinimizer : public Minimizer { SparseMatrix* jacobian_; TrustRegionStrategy* strategy_; - scoped_ptr step_evaluator_; + std::unique_ptr step_evaluator_; bool is_not_silent_; bool inner_iterations_are_enabled_; diff --git a/internal/ceres/visibility_based_preconditioner.cc b/internal/ceres/visibility_based_preconditioner.cc index 31d2cc31b..b13c529d8 100644 --- a/internal/ceres/visibility_based_preconditioner.cc +++ b/internal/ceres/visibility_based_preconditioner.cc @@ -33,16 +33,17 @@ #include #include #include +#include #include #include #include + #include "Eigen/Dense" #include "ceres/block_random_access_sparse_matrix.h" #include "ceres/block_sparse_matrix.h" #include "ceres/canonical_views_clustering.h" #include "ceres/graph.h" #include "ceres/graph_algorithms.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/linear_solver.h" #include "ceres/schur_eliminator.h" #include "ceres/single_linkage_clustering.h" @@ -151,9 +152,9 @@ void VisibilityBasedPreconditioner::ComputeClusterTridiagonalSparsity( // maximum spanning forest of this graph. vector > cluster_visibility; ComputeClusterVisibility(visibility, &cluster_visibility); - scoped_ptr > cluster_graph( + std::unique_ptr > cluster_graph( CHECK_NOTNULL(CreateClusterGraph(cluster_visibility))); - scoped_ptr > forest( + std::unique_ptr > forest( CHECK_NOTNULL(Degree2MaximumSpanningForest(*cluster_graph))); ForestToClusterPairs(*forest, &cluster_pairs_); } @@ -173,7 +174,7 @@ void VisibilityBasedPreconditioner::InitStorage( // memberships for each camera block. void VisibilityBasedPreconditioner::ClusterCameras( const vector >& visibility) { - scoped_ptr > schur_complement_graph( + std::unique_ptr > schur_complement_graph( CHECK_NOTNULL(CreateSchurComplementGraph(visibility))); std::unordered_map membership; @@ -412,7 +413,7 @@ LinearSolverTerminationType VisibilityBasedPreconditioner::Factorize() { const TripletSparseMatrix* tsm = down_cast(m_.get())->mutable_matrix(); - scoped_ptr lhs; + std::unique_ptr lhs; const CompressedRowSparseMatrix::StorageType storage_type = sparse_cholesky_->StorageType(); if (storage_type == CompressedRowSparseMatrix::UPPER_TRIANGULAR) { diff --git a/internal/ceres/visibility_based_preconditioner.h b/internal/ceres/visibility_based_preconditioner.h index 1c831d0a6..b47bb68d6 100644 --- a/internal/ceres/visibility_based_preconditioner.h +++ b/internal/ceres/visibility_based_preconditioner.h @@ -48,14 +48,15 @@ #ifndef CERES_INTERNAL_VISIBILITY_BASED_PRECONDITIONER_H_ #define CERES_INTERNAL_VISIBILITY_BASED_PRECONDITIONER_H_ +#include #include #include #include #include #include + #include "ceres/graph.h" #include "ceres/internal/macros.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/linear_solver.h" #include "ceres/pair_hash.h" #include "ceres/preconditioner.h" @@ -185,11 +186,11 @@ class VisibilityBasedPreconditioner : public BlockSparseMatrixPreconditioner { // Set of cluster pairs (including self pairs (i,i)) in the // preconditioner. std::unordered_set, pair_hash> cluster_pairs_; - scoped_ptr eliminator_; + std::unique_ptr eliminator_; // Preconditioner matrix. - scoped_ptr m_; - scoped_ptr sparse_cholesky_; + std::unique_ptr m_; + std::unique_ptr sparse_cholesky_; CERES_DISALLOW_COPY_AND_ASSIGN(VisibilityBasedPreconditioner); }; diff --git a/internal/ceres/visibility_based_preconditioner_test.cc b/internal/ceres/visibility_based_preconditioner_test.cc index 2227116c1..437b5d4c8 100644 --- a/internal/ceres/visibility_based_preconditioner_test.cc +++ b/internal/ceres/visibility_based_preconditioner_test.cc @@ -30,6 +30,7 @@ #include "ceres/visibility_based_preconditioner.h" +#include #include "Eigen/Dense" #include "ceres/block_random_access_dense_matrix.h" #include "ceres/block_random_access_sparse_matrix.h" @@ -37,7 +38,6 @@ #include "ceres/casts.h" #include "ceres/file.h" #include "ceres/internal/eigen.h" -#include "ceres/internal/scoped_ptr.h" #include "ceres/linear_least_squares_problems.h" #include "ceres/schur_eliminator.h" #include "ceres/stringprintf.h" @@ -66,7 +66,7 @@ namespace internal { // void SetUp() { // string input_file = TestFileAbsolutePath("problem-6-1384-000.lsqp"); -// scoped_ptr problem( +// std::unique_ptr problem( // CHECK_NOTNULL(CreateLinearLeastSquaresProblemFromFile(input_file))); // A_.reset(down_cast(problem->A.release())); // b_.reset(problem->b.release()); @@ -98,7 +98,7 @@ namespace internal { // schur_complement_.reset(new BlockRandomAccessDenseMatrix(blocks)); // Vector rhs(schur_complement_->num_rows()); -// scoped_ptr eliminator; +// std::unique_ptr eliminator; // LinearSolver::Options eliminator_options; // eliminator_options.elimination_groups = options_.elimination_groups; // eliminator_options.num_threads = options_.num_threads; @@ -230,13 +230,13 @@ namespace internal { // int num_eliminate_blocks_; // int num_camera_blocks_; -// scoped_ptr A_; -// scoped_array b_; -// scoped_array D_; +// std::unique_ptr A_; +// std::unique_ptr b_; +// std::unique_ptr D_; // Preconditioner::Options options_; -// scoped_ptr preconditioner_; -// scoped_ptr schur_complement_; +// std::unique_ptr preconditioner_; +// std::unique_ptr schur_complement_; // }; // TEST_F(VisibilityBasedPreconditionerTest, OneClusterClusterJacobi) { diff --git a/internal/ceres/visibility_test.cc b/internal/ceres/visibility_test.cc index 73517dadb..81ad99f9f 100644 --- a/internal/ceres/visibility_test.cc +++ b/internal/ceres/visibility_test.cc @@ -31,11 +31,12 @@ #include "ceres/visibility.h" +#include #include #include + #include "ceres/block_structure.h" #include "ceres/graph.h" -#include "ceres/internal/scoped_ptr.h" #include "glog/logging.h" #include "gtest/gtest.h" @@ -106,7 +107,7 @@ TEST(VisibilityTest, SimpleMatrix) { ASSERT_EQ(visibility[i].size(), 1); } - scoped_ptr > graph(CreateSchurComplementGraph(visibility)); + std::unique_ptr > graph(CreateSchurComplementGraph(visibility)); EXPECT_EQ(graph->vertices().size(), visibility.size()); for (int i = 0; i < visibility.size(); ++i) { EXPECT_EQ(graph->VertexWeight(i), 1.0); @@ -182,7 +183,7 @@ TEST(VisibilityTest, NoEBlocks) { ASSERT_EQ(visibility[i].size(), 0); } - scoped_ptr > graph(CreateSchurComplementGraph(visibility)); + std::unique_ptr > graph(CreateSchurComplementGraph(visibility)); EXPECT_EQ(graph->vertices().size(), visibility.size()); for (int i = 0; i < visibility.size(); ++i) { EXPECT_EQ(graph->VertexWeight(i), 1.0);