From ad891db35868986668f912a344bc9a5304ba2048 Mon Sep 17 00:00:00 2001 From: Krishnakumar Gopalakrishnan Date: Wed, 21 Jun 2023 22:33:00 +0100 Subject: [PATCH] feat(modernise): concatenates nested namespaces (capability introduced in C++17 std) --- cpp/sopt/config.in.h | 2 +- cpp/sopt/cppflow_utils.cc | 8 +++----- cpp/sopt/cppflow_utils.h | 6 ++---- cpp/sopt/credible_region.h | 13 ++++--------- cpp/sopt/forward_backward.h | 6 ++---- cpp/sopt/gradient_operator.h | 6 ++---- cpp/sopt/imaging_forward_backward.h | 6 ++---- cpp/sopt/imaging_padmm.h | 6 ++---- cpp/sopt/imaging_primal_dual.h | 6 ++---- cpp/sopt/joint_map.h | 6 ++---- cpp/sopt/l1_g_proximal.h | 6 ++---- cpp/sopt/l1_proximal.h | 6 ++---- cpp/sopt/l2_forward_backward.h | 6 ++---- cpp/sopt/l2_primal_dual.h | 6 ++---- cpp/sopt/logging.disabled.h | 6 ++---- cpp/sopt/logging.enabled.h | 6 ++---- cpp/sopt/mpi/communicator.cc | 6 ++---- cpp/sopt/mpi/communicator.h | 6 ++---- cpp/sopt/mpi/registered_types.cc | 6 ++---- cpp/sopt/mpi/registered_types.h | 6 ++---- cpp/sopt/mpi/session.cc | 6 ++---- cpp/sopt/mpi/session.h | 6 ++---- cpp/sopt/mpi/utilities.h | 6 ++---- cpp/sopt/objective_functions.h | 12 ++++-------- cpp/sopt/padmm.h | 6 ++---- cpp/sopt/positive_quadrant.h | 6 ++---- cpp/sopt/power_method.h | 6 ++---- cpp/sopt/primal_dual.h | 6 ++---- cpp/sopt/proximal.h | 7 ++----- cpp/sopt/proximal_expression.h | 13 ++++--------- cpp/sopt/reweighted.h | 6 ++---- cpp/sopt/sdmm.h | 6 ++---- cpp/sopt/tf_g_proximal.h | 8 +++----- cpp/sopt/tv_primal_dual.h | 6 ++---- cpp/sopt/utilities.cc | 6 ++---- cpp/sopt/utilities.h | 6 ++---- cpp/sopt/wavelets/direct.h | 6 ++---- cpp/sopt/wavelets/indirect.h | 6 ++---- cpp/sopt/wavelets/innards.impl.h | 6 ++---- cpp/sopt/wavelets/sara.cc | 4 +--- cpp/sopt/wavelets/sara.h | 6 ++---- cpp/sopt/wavelets/wavelet_data.cc | 6 ++---- cpp/sopt/wavelets/wavelet_data.h | 6 ++---- cpp/sopt/wavelets/wavelets.cc | 6 ++---- cpp/sopt/wavelets/wavelets.h | 6 ++---- cpp/sopt/wrapper.h | 12 ++++-------- cpp/tools_for_tests/directories.in.h | 6 ++---- cpp/tools_for_tests/tiffwrappers.cc | 6 ++---- cpp/tools_for_tests/tiffwrappers.h | 6 ++---- 49 files changed, 106 insertions(+), 213 deletions(-) diff --git a/cpp/sopt/config.in.h b/cpp/sopt/config.in.h index c9d351ed9..eb01f0c6d 100644 --- a/cpp/sopt/config.in.h +++ b/cpp/sopt/config.in.h @@ -45,6 +45,6 @@ inline constexpr bool color_logger() { return @SOPT_COLOR_LOGGING@; } //! Number of threads used during testing inline constexpr std::size_t number_of_threads_in_tests() { return @SOPT_DEFAULT_OPENMP_THREADS@; } # endif -} +} // namespace sopt #endif diff --git a/cpp/sopt/cppflow_utils.cc b/cpp/sopt/cppflow_utils.cc index 90c8dd10f..5c43bf4cb 100644 --- a/cpp/sopt/cppflow_utils.cc +++ b/cpp/sopt/cppflow_utils.cc @@ -6,10 +6,9 @@ #include "cppflow/model.h" #include -namespace sopt { -namespace cppflowutils { +namespace sopt::cppflowutils { - // arbitrary constant for imaginary part of image vectors. + // arbitrary constant for imaginary part of image vectors. const double imaginary_threshold = 1e-10; cppflow::tensor convert_image_to_tensor(Image const &image, int image_rows, int image_cols){ @@ -93,5 +92,4 @@ namespace cppflowutils { return output_image; } -} // namespace cppflowutils -} // namespace sopt +} // namespace sopt::cppflowutils diff --git a/cpp/sopt/cppflow_utils.h b/cpp/sopt/cppflow_utils.h index 4987657f4..9505b339b 100644 --- a/cpp/sopt/cppflow_utils.h +++ b/cpp/sopt/cppflow_utils.h @@ -7,8 +7,7 @@ #include "cppflow/ops.h" #include -namespace sopt { -namespace cppflowutils { +namespace sopt::cppflowutils { //! Converts a sopt::Image to a cppflow::tensor cppflow::tensor convert_image_to_tensor(sopt::Image const &image, int image_rows, int image_cols); @@ -20,6 +19,5 @@ cppflow::tensor convert_image_to_tensor(sopt::Vector> const //! Convert a cppflow:tensor to an Eigen::Array Eigen::Map> convert_tensor_to_image(std::vector model_output, int image_rows, int image_cols); -} // namespace cppflowutils -} // namespace sopt +} // namespace sopt::cppflowutils #endif diff --git a/cpp/sopt/credible_region.h b/cpp/sopt/credible_region.h index 292271ac5..909399898 100644 --- a/cpp/sopt/credible_region.h +++ b/cpp/sopt/credible_region.h @@ -10,8 +10,7 @@ #include "sopt/logging.h" #include "sopt/types.h" -namespace sopt { -namespace credible_region { +namespace sopt::credible_region { template t_real compute_energy_upper_bound( @@ -54,11 +53,9 @@ credible_interval(const Eigen::MatrixBase &solution, const t_uint &rows, cons const std::tuple &grid_pixel_size, const std::function &objective_function, const t_real &alpha); -} // namespace credible_region -} // namespace sopt +} // namespace sopt::credible_region -namespace sopt { -namespace credible_region { +namespace sopt::credible_region { template t_real compute_energy_upper_bound( @@ -197,8 +194,6 @@ credible_interval(const Eigen::MatrixBase &solution, const t_uint &rows, cons return credible_interval_grid(solution, rows, cols, grid_pixel_size, objective_function, energy_upperbound); } -} // namespace credible_region - -} // namespace sopt +} // namespace sopt::credible_region #endif diff --git a/cpp/sopt/forward_backward.h b/cpp/sopt/forward_backward.h index ca03a106a..82e7b6fe0 100644 --- a/cpp/sopt/forward_backward.h +++ b/cpp/sopt/forward_backward.h @@ -9,8 +9,7 @@ #include "sopt/logging.h" #include "sopt/types.h" -namespace sopt { -namespace algorithm { +namespace sopt::algorithm { //! \brief Forward Backward Splitting //! \details \f$\min_{x} f(\Phi x - y) + g(z)\f$. \f$y\f$ is a target vector. @@ -282,6 +281,5 @@ typename ForwardBackward::Diagnostic ForwardBackward::operator() } return {niters, converged, std::move(residual)}; } -} // namespace algorithm -} // namespace sopt +} // namespace sopt::algorithm #endif diff --git a/cpp/sopt/gradient_operator.h b/cpp/sopt/gradient_operator.h index 906aea5dc..4ab06f2d2 100644 --- a/cpp/sopt/gradient_operator.h +++ b/cpp/sopt/gradient_operator.h @@ -5,8 +5,7 @@ #include "sopt/linear_transform.h" #include "sopt/logging.h" -namespace sopt { -namespace gradient_operator { +namespace sopt::gradient_operator { //! Numerical derivative of 1d vector template Vector diff(const Vector &x) { @@ -61,7 +60,6 @@ LinearTransform> gradient_operator(const t_int rows, const t_int cols) }, {{0, 1, static_cast(2 * rows * cols)}}); } -} // namespace gradient_operator -} // namespace sopt +} // namespace sopt::gradient_operator #endif diff --git a/cpp/sopt/imaging_forward_backward.h b/cpp/sopt/imaging_forward_backward.h index 2d813dafa..c2caf8f19 100644 --- a/cpp/sopt/imaging_forward_backward.h +++ b/cpp/sopt/imaging_forward_backward.h @@ -19,8 +19,7 @@ #include "sopt/mpi/utilities.h" #endif -namespace sopt { -namespace algorithm { +namespace sopt::algorithm { template class ImagingForwardBackward { //! Underlying algorithm @@ -337,6 +336,5 @@ bool ImagingForwardBackward::is_converged(ScalarRelativeVariation class ImagingProximalADMM { //! Underlying algorithm @@ -346,6 +345,5 @@ bool ImagingProximalADMM::is_converged(ScalarRelativeVariation & // better evaluate each convergence function everytime, especially with mpi return user and res and obj; } -} // namespace algorithm -} // namespace sopt +} // namespace sopt::algorithm #endif diff --git a/cpp/sopt/imaging_primal_dual.h b/cpp/sopt/imaging_primal_dual.h index 1274fce7b..9c7f93f2c 100644 --- a/cpp/sopt/imaging_primal_dual.h +++ b/cpp/sopt/imaging_primal_dual.h @@ -14,8 +14,7 @@ #include "sopt/relative_variation.h" #include "sopt/types.h" -namespace sopt { -namespace algorithm { +namespace sopt::algorithm { template class ImagingPrimalDual { //! Underlying algorithm @@ -394,6 +393,5 @@ bool ImagingPrimalDual::is_converged(ScalarRelativeVariation &sc // better evaluate each convergence function everytime, especially with mpi return user and res and obj; } -} // namespace algorithm -} // namespace sopt +} // namespace sopt::algorithm #endif diff --git a/cpp/sopt/joint_map.h b/cpp/sopt/joint_map.h index fa3e69f90..8b2853739 100644 --- a/cpp/sopt/joint_map.h +++ b/cpp/sopt/joint_map.h @@ -11,8 +11,7 @@ #include "sopt/logging.h" #include "sopt/types.h" -namespace sopt { -namespace algorithm { +namespace sopt::algorithm { template class JointMAP { @@ -135,7 +134,6 @@ class JointMAP { }; }; -} // namespace algorithm -} // namespace sopt +} // namespace sopt::algorithm #endif diff --git a/cpp/sopt/l1_g_proximal.h b/cpp/sopt/l1_g_proximal.h index e19d7fb83..1fb4ae614 100644 --- a/cpp/sopt/l1_g_proximal.h +++ b/cpp/sopt/l1_g_proximal.h @@ -19,8 +19,7 @@ #include "sopt/mpi/communicator.h" #endif -namespace sopt { -namespace algorithm { +namespace sopt::algorithm { // Implementation of g_proximal with l1 proximal. // Owns the private object l1_proximal_ and implements the @@ -145,6 +144,5 @@ class L1GProximal : public GProximal { } }; -} -} +} // namespace sopt::algorithm #endif diff --git a/cpp/sopt/l1_proximal.h b/cpp/sopt/l1_proximal.h index b3dd7c20c..cad8e50db 100644 --- a/cpp/sopt/l1_proximal.h +++ b/cpp/sopt/l1_proximal.h @@ -13,8 +13,7 @@ #include "sopt/mpi/utilities.h" #endif -namespace sopt { -namespace proximal { +namespace sopt::proximal { //! \brief L1 proximal, including linear transform //! \details This function computes the prox operator of the l1 @@ -475,7 +474,6 @@ class L1::Breaker { std::array objectives; bool do_two_cycle; }; -} // namespace proximal -} // namespace sopt +} // namespace sopt::proximal #endif diff --git a/cpp/sopt/l2_forward_backward.h b/cpp/sopt/l2_forward_backward.h index 7d6eefd7f..c1915d990 100644 --- a/cpp/sopt/l2_forward_backward.h +++ b/cpp/sopt/l2_forward_backward.h @@ -18,8 +18,7 @@ #include "sopt/mpi/utilities.h" #endif -namespace sopt { -namespace algorithm { +namespace sopt::algorithm { template class L2ForwardBackward { //! Underlying algorithm @@ -337,6 +336,5 @@ bool L2ForwardBackward::is_converged(ScalarRelativeVariation &sc // better evaluate each convergence function everytime, especially with mpi return user and res and obj; } -} // namespace algorithm -} // namespace sopt +} // namespace sopt::algorithm #endif diff --git a/cpp/sopt/l2_primal_dual.h b/cpp/sopt/l2_primal_dual.h index b1c478427..195c331a1 100644 --- a/cpp/sopt/l2_primal_dual.h +++ b/cpp/sopt/l2_primal_dual.h @@ -13,8 +13,7 @@ #include "sopt/relative_variation.h" #include "sopt/types.h" -namespace sopt { -namespace algorithm { +namespace sopt::algorithm { template class ImagingPrimalDual { //! Underlying algorithm @@ -395,6 +394,5 @@ bool ImagingPrimalDual::is_converged(ScalarRelativeVariation &sc // better evaluate each convergence function everytime, especially with mpi return user and res and obj; } -} // namespace algorithm -} // namespace sopt +} // namespace sopt::algorithm #endif diff --git a/cpp/sopt/logging.disabled.h b/cpp/sopt/logging.disabled.h index 49fe33e6a..d7729e731 100644 --- a/cpp/sopt/logging.disabled.h +++ b/cpp/sopt/logging.disabled.h @@ -5,8 +5,7 @@ #include #include -namespace sopt { -namespace logging { +namespace sopt::logging { //! Name of the sopt logger const std::string name_prefix = "sopt::"; @@ -17,8 +16,7 @@ inline std::shared_ptr get() { return nullptr; } inline void set_level(std::string const &, std::string const &){}; inline void set_level(std::string const &){}; inline bool has_level(std::string const &, std::string const &) { return false; } -} // namespace logging -} // namespace sopt +} // namespace sopt::logging //! \macro For internal use only #define SOPT_LOG_(...) diff --git a/cpp/sopt/logging.enabled.h b/cpp/sopt/logging.enabled.h index 7499cce96..4d462a198 100644 --- a/cpp/sopt/logging.enabled.h +++ b/cpp/sopt/logging.enabled.h @@ -7,8 +7,7 @@ #include #include "sopt/exception.h" -namespace sopt { -namespace logging { +namespace sopt::logging { void set_level(std::string const &level, std::string const &name = ""); //! \brief Initializes a logger. @@ -65,8 +64,7 @@ inline bool has_level(std::string const &level, std::string const &name = "") { #undef SOPT_MACRO else SOPT_THROW("Unknown logging level ") << level << "\n"; } -} // namespace logging -} // namespace sopt +} // namespace sopt::logging //! \macro For internal use only #define SOPT_LOG_(NAME, TYPE, ...) \ diff --git a/cpp/sopt/mpi/communicator.cc b/cpp/sopt/mpi/communicator.cc index afacaf9b1..e17f94b4f 100644 --- a/cpp/sopt/mpi/communicator.cc +++ b/cpp/sopt/mpi/communicator.cc @@ -3,8 +3,7 @@ #include #include "sopt/mpi/session.h" -namespace sopt { -namespace mpi { +namespace sopt::mpi { void Communicator::delete_comm(Communicator::Impl *const impl) { if (impl->comm != MPI_COMM_WORLD and impl->comm != MPI_COMM_SELF and impl->comm != MPI_COMM_NULL) @@ -49,5 +48,4 @@ std::string Communicator::broadcast(std::string const &input, t_uint const root) return result; } -} // namespace mpi -} // namespace sopt +} // namespace sopt::mpi diff --git a/cpp/sopt/mpi/communicator.h b/cpp/sopt/mpi/communicator.h index 2441f4669..aadef7bdc 100644 --- a/cpp/sopt/mpi/communicator.h +++ b/cpp/sopt/mpi/communicator.h @@ -19,8 +19,7 @@ #include #include -namespace sopt { -namespace mpi { +namespace sopt::mpi { //! \brief A C++ wrapper for an mpi communicator //! \details All copies made of this communicator are shallow: they reference @@ -584,7 +583,6 @@ Communicator::broadcast(t_uint const root) const { MPI_Bcast(result.data(), result.size(), Type::value, root, **this); return result; } -} // namespace mpi -} // namespace sopt +} // namespace sopt::mpi #endif /* ifdef SOPT_MPI */ #endif /* ifndef SOPT_MPI_COMMUNICATOR */ diff --git a/cpp/sopt/mpi/registered_types.cc b/cpp/sopt/mpi/registered_types.cc index 73c9eb76d..d4075fcad 100644 --- a/cpp/sopt/mpi/registered_types.cc +++ b/cpp/sopt/mpi/registered_types.cc @@ -1,7 +1,6 @@ #include "sopt/mpi/registered_types.h" -namespace sopt { -namespace mpi { +namespace sopt::mpi { MPIType const Type::value = MPI_INT8_T; MPIType const Type::value = MPI_INT16_T; MPIType const Type::value = MPI_INT32_T; @@ -33,5 +32,4 @@ static_assert(is_registered_type>::value, "Checking complex double is registered"); static_assert(not is_registered_type>::value, "Checking complex int is NOT registered"); -} // namespace mpi -} // namespace sopt +} // namespace sopt::mpi diff --git a/cpp/sopt/mpi/registered_types.h b/cpp/sopt/mpi/registered_types.h index 5460bd4da..6865f480a 100644 --- a/cpp/sopt/mpi/registered_types.h +++ b/cpp/sopt/mpi/registered_types.h @@ -5,8 +5,7 @@ #ifdef SOPT_MPI #include #include -namespace sopt { -namespace mpi { +namespace sopt::mpi { //! Type of an mpi tupe typedef decltype(MPI_CHAR) MPIType; // Some MPI libraries don't actually have a type defined that will work in the above line @@ -73,7 +72,6 @@ template > class is_registered_type : public std::false_type {}; template class is_registered_type::value)>> : public std::true_type {}; -} // namespace mpi -} // namespace sopt +} // namespace sopt::mpi #endif #endif /* ifndef SOPT_TYPES */ diff --git a/cpp/sopt/mpi/session.cc b/cpp/sopt/mpi/session.cc index 0b655fa27..64f007e5e 100644 --- a/cpp/sopt/mpi/session.cc +++ b/cpp/sopt/mpi/session.cc @@ -5,8 +5,7 @@ #include "sopt/logging.h" #include "sopt/types.h" -namespace sopt { -namespace mpi { +namespace sopt::mpi { namespace details { void initializer::deleter(initializer *tag) { @@ -80,5 +79,4 @@ void finalize() { MPI_Finalize(); } -} // namespace mpi -} // namespace sopt +} // namespace sopt::mpi diff --git a/cpp/sopt/mpi/session.h b/cpp/sopt/mpi/session.h index c6bbe08f4..b4b8fee3e 100644 --- a/cpp/sopt/mpi/session.h +++ b/cpp/sopt/mpi/session.h @@ -8,8 +8,7 @@ #include #endif -namespace sopt { -namespace mpi { +namespace sopt::mpi { #ifdef SOPT_MPI namespace details { struct initializer { @@ -29,6 +28,5 @@ bool finalized(); inline void init(int argc, const char **argv) {} inline bool initialized() { return false; }; #endif -} // namespace mpi -} // namespace sopt +} // namespace sopt::mpi #endif /* ifndef SOPT_MPI_SESSION_H */ diff --git a/cpp/sopt/mpi/utilities.h b/cpp/sopt/mpi/utilities.h index a0bf9e869..b89885ec6 100644 --- a/cpp/sopt/mpi/utilities.h +++ b/cpp/sopt/mpi/utilities.h @@ -8,8 +8,7 @@ #include "sopt/mpi/communicator.h" #include "sopt/real_type.h" -namespace sopt { -namespace mpi { +namespace sopt::mpi { //! Computes norm of distributed vector template @@ -63,7 +62,6 @@ typename real_type::type l1_norm(Eigen::MatrixBase cons Communicator const &comm) { return comm.all_sum_all(sopt::l1_norm(input)); } -} // namespace mpi -} // namespace sopt +} // namespace sopt::mpi #endif #endif diff --git a/cpp/sopt/objective_functions.h b/cpp/sopt/objective_functions.h index da7f3ed0b..7740669ba 100644 --- a/cpp/sopt/objective_functions.h +++ b/cpp/sopt/objective_functions.h @@ -9,8 +9,7 @@ #include "sopt/maths.h" #include "sopt/types.h" -namespace sopt { -namespace objective_functions { +namespace sopt::objective_functions { //! returns g(x) + ||y - Φ x||_2^2 as a function template std::function const unconstrained_regularisation( @@ -31,10 +30,8 @@ std::function const unconstrained_l1_regularisation( const t_real &gamma, const t_real &sig, const T &y, const sopt::LinearTransform &measurement_operator, const sopt::LinearTransform &wavelet_operator); -} // namespace objective_functions -} // namespace sopt -namespace sopt { -namespace objective_functions { +} // namespace sopt::objective_functions +namespace sopt::objective_functions { template std::function const unconstrained_regularisation( @@ -70,6 +67,5 @@ std::function const unconstrained_l1_regularisation( const LinearTransform mop = {measurement_operator, measurement_operator}; return unconstrained_l1_regularisation(gamma, sig, mop * y, mop, wavelet_operator); } -} // namespace objective_functions -} // namespace sopt +} // namespace sopt::objective_functions #endif diff --git a/cpp/sopt/padmm.h b/cpp/sopt/padmm.h index e742040ef..6d453b2dd 100644 --- a/cpp/sopt/padmm.h +++ b/cpp/sopt/padmm.h @@ -9,8 +9,7 @@ #include "sopt/logging.h" #include "sopt/types.h" -namespace sopt { -namespace algorithm { +namespace sopt::algorithm { //! \brief Proximal Alternate Direction method of mutltipliers //! \details \f$\min_{x, z} f(x) + h(z)\f$ subject to \f$Φx + z = y\f$. \f$y\f$ is a target vector. @@ -263,6 +262,5 @@ typename ProximalADMM::Diagnostic ProximalADMM::operator()( } return {niters, converged, std::move(residual)}; } -} // namespace algorithm -} // namespace sopt +} // namespace sopt::algorithm #endif diff --git a/cpp/sopt/positive_quadrant.h b/cpp/sopt/positive_quadrant.h index 422efa8f7..dfbb1fb45 100644 --- a/cpp/sopt/positive_quadrant.h +++ b/cpp/sopt/positive_quadrant.h @@ -4,8 +4,7 @@ #include "sopt/linear_transform.h" #include "sopt/types.h" -namespace sopt { -namespace algorithm { +namespace sopt::algorithm { //! \brief Computes according to given algorithm and then projects it to the positive quadrant //! \details C implementation of the reweighted algorithms uses this, even-though the solutions are //! already constrained to the positive quadrant. @@ -57,7 +56,6 @@ template PositiveQuadrant positive_quadrant(ALGORITHM const &algo) { return {algo}; } -} // namespace algorithm -} // namespace sopt +} // namespace sopt::algorithm #endif diff --git a/cpp/sopt/power_method.h b/cpp/sopt/power_method.h index c570c4871..a909d527b 100644 --- a/cpp/sopt/power_method.h +++ b/cpp/sopt/power_method.h @@ -14,8 +14,7 @@ #include "sopt/mpi/communicator.h" #endif -namespace sopt { -namespace algorithm { +namespace sopt::algorithm { //! \brief Returns the eigenvalue and eigenvector for eigenvalue of the Linear Transform with //! largest magnitude template @@ -242,6 +241,5 @@ typename PowerMethod::DiagnosticAndResult PowerMethod::operator( } return DiagnosticAndResult{itermax(), converged, previous_magnitude, eigenvector.normalized()}; } -} // namespace algorithm -} // namespace sopt +} // namespace sopt::algorithm #endif diff --git a/cpp/sopt/primal_dual.h b/cpp/sopt/primal_dual.h index 4166ac86b..014206fe2 100644 --- a/cpp/sopt/primal_dual.h +++ b/cpp/sopt/primal_dual.h @@ -14,8 +14,7 @@ #include "sopt/mpi/utilities.h" #endif -namespace sopt { -namespace algorithm { +namespace sopt::algorithm { //! \brief Primal Dual Algorithm //! \details \f$\min_{x, z} f(x) + h(z)\f$ subject to \f$Φx + z = y\f$. \f$y\f$ is a target vector. @@ -358,6 +357,5 @@ typename PrimalDual::Diagnostic PrimalDual::operator()( } return {niters, converged, std::move(residual)}; } -} // namespace algorithm -} // namespace sopt +} // namespace sopt::algorithm #endif diff --git a/cpp/sopt/proximal.h b/cpp/sopt/proximal.h index d94f358bb..e49a3440b 100644 --- a/cpp/sopt/proximal.h +++ b/cpp/sopt/proximal.h @@ -11,9 +11,7 @@ #include "sopt/mpi/utilities.h" #endif -namespace sopt { -//! Holds some standard proximals -namespace proximal { +namespace sopt::proximal { //! Proximal of euclidian norm class EuclidianNorm { @@ -363,7 +361,6 @@ template Translation translate(FUNCTION const &func, VECTOR const &translation) { return Translation(func, translation); } -} // namespace proximal -} // namespace sopt +} // namespace sopt::proximal #endif diff --git a/cpp/sopt/proximal_expression.h b/cpp/sopt/proximal_expression.h index 563a0e635..c57d836c6 100644 --- a/cpp/sopt/proximal_expression.h +++ b/cpp/sopt/proximal_expression.h @@ -6,9 +6,7 @@ #include #include "sopt/maths.h" -namespace sopt { -//! Holds some standard proximals -namespace proximal { +namespace sopt::proximal { namespace details { //! \brief Expression referencing a lazy proximal function call @@ -85,11 +83,9 @@ using ProximalExpression = details::DelayedProximalFunction using EnveloppeExpression = details::DelayedProximalEnveloppeFunction>; -} // namespace proximal -} // namespace sopt +} // namespace sopt::proximal -namespace Eigen { -namespace internal { +namespace Eigen::internal { template struct traits> { typedef typename VECTOR::PlainObject ReturnType; @@ -98,7 +94,6 @@ template struct traits> { typedef typename VECTOR::PlainObject ReturnType; }; -} // namespace internal -} // namespace Eigen +} // namespace Eigen::internal #endif diff --git a/cpp/sopt/reweighted.h b/cpp/sopt/reweighted.h index 6f0140c0a..44144b546 100644 --- a/cpp/sopt/reweighted.h +++ b/cpp/sopt/reweighted.h @@ -4,8 +4,7 @@ #include "sopt/linear_transform.h" #include "sopt/types.h" -namespace sopt { -namespace algorithm { +namespace sopt::algorithm { template class Reweighted; @@ -284,6 +283,5 @@ Reweighted>> reweighted(PrimalDual c return {posq, set_weights, reweightee}; } -} // namespace algorithm -} // namespace sopt +} // namespace sopt::algorithm #endif diff --git a/cpp/sopt/sdmm.h b/cpp/sopt/sdmm.h index 7d7453bea..5ed24f149 100644 --- a/cpp/sopt/sdmm.h +++ b/cpp/sopt/sdmm.h @@ -14,8 +14,7 @@ #include "sopt/types.h" #include "sopt/wrapper.h" -namespace sopt { -namespace algorithm { +namespace sopt::algorithm { //! \brief Simultaneous-direction method of the multipliers //! \details The algorithm is detailed in (doi) 10.1093/mnras/stu202. @@ -303,6 +302,5 @@ void SDMM::sanity_check(t_Vector const &x) const { } if (doexit) SOPT_THROW("Input to SDMM is inconsistent"); } -} // namespace algorithm -} // namespace sopt +} // namespace sopt::algorithm #endif diff --git a/cpp/sopt/tf_g_proximal.h b/cpp/sopt/tf_g_proximal.h index 4be635e22..631d66b98 100644 --- a/cpp/sopt/tf_g_proximal.h +++ b/cpp/sopt/tf_g_proximal.h @@ -19,8 +19,7 @@ #include "cppflow/model.h" #include "sopt/cppflow_utils.h" -namespace sopt { -namespace algorithm { +namespace sopt::algorithm { // Implementation of g_proximal with a TensorFlow model. Owns private // object model_ and implements the @@ -105,13 +104,12 @@ class TFGProximal : public GProximal { // Added template keyword to suppress error on apple-clang, for reference // https://stackoverflow.com/questions/3786360/confusing-template-error auto output_vector = model_output[0].template get_data(); - + for(int i = 0; i < image_size; i++) { image_out[i] = static_cast(output_vector[i]); } } }; -} -} +} // namespace sopt::algorithm #endif diff --git a/cpp/sopt/tv_primal_dual.h b/cpp/sopt/tv_primal_dual.h index 0ee1149c0..c3360126e 100644 --- a/cpp/sopt/tv_primal_dual.h +++ b/cpp/sopt/tv_primal_dual.h @@ -13,8 +13,7 @@ #include "sopt/relative_variation.h" #include "sopt/types.h" -namespace sopt { -namespace algorithm { +namespace sopt::algorithm { template class TVPrimalDual { //! Underlying algorithm @@ -391,6 +390,5 @@ bool TVPrimalDual::is_converged(ScalarRelativeVariation &scalvar // better evaluate each convergence function everytime, especially with mpi return user and res and obj; } -} // namespace algorithm -} // namespace sopt +} // namespace sopt::algorithm #endif diff --git a/cpp/sopt/utilities.cc b/cpp/sopt/utilities.cc index 5cfd1ccce..3009c3587 100644 --- a/cpp/sopt/utilities.cc +++ b/cpp/sopt/utilities.cc @@ -34,8 +34,7 @@ uint32_t convert_from_greyscale(double pixel) { } } // namespace -namespace sopt { -namespace utilities { +namespace sopt::utilities { Image<> read_tiff(std::string const &filename) { SOPT_MEDIUM_LOG("Reading image file {} ", filename); TIFF *tif = TIFFOpen(filename.c_str(), "r"); @@ -99,5 +98,4 @@ void write_tiff(Image<> const &image, std::string const &filename) { TIFFClose(tif); SOPT_TRACE("Freeing raster"); } -} // namespace utilities -} // namespace sopt +} // namespace sopt::utilities diff --git a/cpp/sopt/utilities.h b/cpp/sopt/utilities.h index 856848538..8999d2724 100644 --- a/cpp/sopt/utilities.h +++ b/cpp/sopt/utilities.h @@ -5,12 +5,10 @@ #include #include "sopt/types.h" -namespace sopt { -namespace utilities { +namespace sopt::utilities { //! Reads tiff image sopt::Image<> read_tiff(std::string const &name); //! Writes a tiff greyscale file void write_tiff(Image<> const &image, std::string const &filename); -} // namespace utilities -} // namespace sopt +} // namespace sopt::utilities #endif diff --git a/cpp/sopt/wavelets/direct.h b/cpp/sopt/wavelets/direct.h index 648978668..c0739a961 100644 --- a/cpp/sopt/wavelets/direct.h +++ b/cpp/sopt/wavelets/direct.h @@ -7,8 +7,7 @@ #include "sopt/wavelets/wavelet_data.h" // Function inside anonymouns namespace won't appear in library -namespace sopt { -namespace wavelets { +namespace sopt::wavelets { namespace { //! \brief Single-level 1d direct transform @@ -110,6 +109,5 @@ auto direct_transform(Eigen::ArrayBase const &signal, t_uint levels, Wavelet direct_transform(result, signal, levels, wavelet); return result; } -} // namespace wavelets -} // namespace sopt +} // namespace sopt::wavelets #endif diff --git a/cpp/sopt/wavelets/indirect.h b/cpp/sopt/wavelets/indirect.h index dcd399252..c1ccc6d8b 100644 --- a/cpp/sopt/wavelets/indirect.h +++ b/cpp/sopt/wavelets/indirect.h @@ -7,8 +7,7 @@ #include "sopt/wavelets/wavelet_data.h" // Function inside anonymouns namespace won't appear in library -namespace sopt { -namespace wavelets { +namespace sopt::wavelets { namespace { //! Single-level 1d indirect transform //! \param[in] coeffs_: input coefficients @@ -114,6 +113,5 @@ auto indirect_transform(Eigen::ArrayBase const &coeffs, t_uint levels, indirect_transform(coeffs, result, levels, wavelet); return result; } -} // namespace wavelets -} // namespace sopt +} // namespace sopt::wavelets #endif diff --git a/cpp/sopt/wavelets/innards.impl.h b/cpp/sopt/wavelets/innards.impl.h index 5135225d0..81a29fa34 100644 --- a/cpp/sopt/wavelets/innards.impl.h +++ b/cpp/sopt/wavelets/innards.impl.h @@ -5,8 +5,7 @@ #include // Function inside anonymouns namespace won't appear in library -namespace sopt { -namespace wavelets { +namespace sopt::wavelets { namespace { //! \brief Returns evaluated expression or copy of input //! \details Gets C++ to figure out what the exact type is. Eigen tries and avoids copies. But @@ -138,6 +137,5 @@ void up_convolve_sum(Eigen::ArrayBase &result, Eigen::ArrayBase const &c } } } // namespace -} // namespace wavelets -} // namespace sopt +} // namespace sopt::wavelets #endif diff --git a/cpp/sopt/wavelets/sara.cc b/cpp/sopt/wavelets/sara.cc index 66396657a..414d71a7d 100644 --- a/cpp/sopt/wavelets/sara.cc +++ b/cpp/sopt/wavelets/sara.cc @@ -1,6 +1,4 @@ #include "sara.h" #include "sopt/config.h" -namespace sopt { -namespace wavelets {} // namespace wavelets -} // namespace sopt +namespace sopt::wavelets {} // namespace sopt::wavelets diff --git a/cpp/sopt/wavelets/sara.h b/cpp/sopt/wavelets/sara.h index 142ddad46..b21d3bb53 100644 --- a/cpp/sopt/wavelets/sara.h +++ b/cpp/sopt/wavelets/sara.h @@ -12,8 +12,7 @@ #include "sopt/mpi/communicator.h" #endif -namespace sopt { -namespace wavelets { +namespace sopt::wavelets { //! Sparsity Averaging Reweighted Analysis class SARA : public std::vector { @@ -210,6 +209,5 @@ T distribute_sara(T const &all_wavelets, mpi::Communicator const &comm) { return distribute_sara(all_wavelets, comm.size(), comm.rank()); } #endif -} // namespace wavelets -} // namespace sopt +} // namespace sopt::wavelets #endif diff --git a/cpp/sopt/wavelets/wavelet_data.cc b/cpp/sopt/wavelets/wavelet_data.cc index ff49058f2..1ea7df423 100644 --- a/cpp/sopt/wavelets/wavelet_data.cc +++ b/cpp/sopt/wavelets/wavelet_data.cc @@ -4,8 +4,7 @@ #include #include "sopt/types.h" -namespace sopt { -namespace wavelets { +namespace sopt::wavelets { namespace { //! Vector setup from initializer list, because easier @@ -1718,5 +1717,4 @@ WaveletData const &daubechies_data(t_uint n) { } return *result; } -} // namespace wavelets -} // namespace sopt +} // namespace sopt::wavelets diff --git a/cpp/sopt/wavelets/wavelet_data.h b/cpp/sopt/wavelets/wavelet_data.h index 823be59b1..7d4cb9db5 100644 --- a/cpp/sopt/wavelets/wavelet_data.h +++ b/cpp/sopt/wavelets/wavelet_data.h @@ -5,8 +5,7 @@ #include "sopt/types.h" #include "sopt/wavelets/innards.impl.h" -namespace sopt { -namespace wavelets { +namespace sopt::wavelets { //! Holds wavelets coefficients struct WaveletData { @@ -42,6 +41,5 @@ struct WaveletData { //! Factory function returning specific daubechie wavelet data WaveletData const &daubechies_data(t_uint); -} // namespace wavelets -} // namespace sopt +} // namespace sopt::wavelets #endif diff --git a/cpp/sopt/wavelets/wavelets.cc b/cpp/sopt/wavelets/wavelets.cc index dda02b500..7258f9d55 100644 --- a/cpp/sopt/wavelets/wavelets.cc +++ b/cpp/sopt/wavelets/wavelets.cc @@ -3,8 +3,7 @@ #include #include "sopt/logging.h" -namespace sopt { -namespace wavelets { +namespace sopt::wavelets { Wavelet factory(std::string name, t_uint nlevels) { if (name == "dirac" or name == "Dirac") { @@ -22,5 +21,4 @@ Wavelet factory(std::string name, t_uint nlevels) { // Unknown input wavelet throw std::exception(); } -} // namespace wavelets -} // namespace sopt +} // namespace sopt::wavelets diff --git a/cpp/sopt/wavelets/wavelets.h b/cpp/sopt/wavelets/wavelets.h index 6bdda26b4..643d0fe9b 100644 --- a/cpp/sopt/wavelets/wavelets.h +++ b/cpp/sopt/wavelets/wavelets.h @@ -7,8 +7,7 @@ #include "sopt/wavelets/indirect.h" #include "sopt/wavelets/wavelet_data.h" -namespace sopt { -namespace wavelets { +namespace sopt::wavelets { // Advance declaration so we can define the subsequent friend function class Wavelet; @@ -133,6 +132,5 @@ class Wavelet : public WaveletData { //! Number of levels in the wavelet t_uint levels_; }; -} // namespace wavelets -} // namespace sopt +} // namespace sopt::wavelets #endif diff --git a/cpp/sopt/wrapper.h b/cpp/sopt/wrapper.h index 28273c113..f06f47c72 100644 --- a/cpp/sopt/wrapper.h +++ b/cpp/sopt/wrapper.h @@ -9,8 +9,7 @@ #include "sopt/maths.h" #include "sopt/types.h" -namespace sopt { -namespace details { +namespace sopt::details { //! Expression referencing the result of a function call template class AppliedFunction : public Eigen::ReturnByValue> { @@ -132,15 +131,12 @@ WrapFunction wrap(OperatorFunction const &func, std::array sizes = {{1, 1, 0}}) { return WrapFunction(func, sizes); } -} // namespace details -} // namespace sopt +} // namespace sopt::details -namespace Eigen { -namespace internal { +namespace Eigen::internal { template struct traits> { typedef typename VECTOR::PlainObject ReturnType; }; -} // namespace internal -} // namespace Eigen +} // namespace Eigen::internal #endif diff --git a/cpp/tools_for_tests/directories.in.h b/cpp/tools_for_tests/directories.in.h index 536bb1f2c..db024b5cc 100644 --- a/cpp/tools_for_tests/directories.in.h +++ b/cpp/tools_for_tests/directories.in.h @@ -4,14 +4,12 @@ #include "sopt/config.h" #include -namespace sopt { -namespace notinstalled { +namespace sopt::notinstalled { //! Holds images and such inline std::string data_directory() { return "@PROJECT_SOURCE_DIR@/images"; } //! Output artefacts from tests inline std::string output_directory() { return "@PROJECT_BINARY_DIR@/outputs"; } //! Tensorflow models inline std::string models_directory() { return "@PROJECT_SOURCE_DIR@/lexci_models"; } -} -} /* sopt::notinstalled */ +} // namespace sopt::notinstalled #endif diff --git a/cpp/tools_for_tests/tiffwrappers.cc b/cpp/tools_for_tests/tiffwrappers.cc index 32c087b2a..3d9d67061 100644 --- a/cpp/tools_for_tests/tiffwrappers.cc +++ b/cpp/tools_for_tests/tiffwrappers.cc @@ -5,12 +5,10 @@ #include "sopt/types.h" #include "sopt/utilities.h" -namespace sopt { -namespace notinstalled { +namespace sopt::notinstalled { Image<> read_standard_tiff(std::string const &name) { std::string const stdname = sopt::notinstalled::data_directory() + "/" + name + ".tiff"; bool const is_std = std::ifstream(stdname).good(); return sopt::utilities::read_tiff(is_std ? stdname : name); } -} // namespace notinstalled -} // namespace sopt +} // namespace sopt::notinstalled diff --git a/cpp/tools_for_tests/tiffwrappers.h b/cpp/tools_for_tests/tiffwrappers.h index 9c0121871..3410382e4 100644 --- a/cpp/tools_for_tests/tiffwrappers.h +++ b/cpp/tools_for_tests/tiffwrappers.h @@ -5,10 +5,8 @@ #include #include "sopt/types.h" -namespace sopt { -namespace notinstalled { +namespace sopt::notinstalled { //! Reads tiff image from sopt data directory if it exists sopt::Image<> read_standard_tiff(std::string const &name); -} // namespace notinstalled -} // namespace sopt +} // namespace sopt::notinstalled #endif