Skip to content

Commit

Permalink
feat(modernise): concatenates nested namespaces (capability introduce…
Browse files Browse the repository at this point in the history
…d in C++17 std)
  • Loading branch information
krishnakumarg1984 committed Jun 21, 2023
1 parent 2031067 commit ad891db
Show file tree
Hide file tree
Showing 49 changed files with 106 additions and 213 deletions.
2 changes: 1 addition & 1 deletion cpp/sopt/config.in.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 3 additions & 5 deletions cpp/sopt/cppflow_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
#include "cppflow/model.h"
#include <stdexcept>

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<double> const &image, int image_rows, int image_cols){
Expand Down Expand Up @@ -93,5 +92,4 @@ namespace cppflowutils {
return output_image;
}

} // namespace cppflowutils
} // namespace sopt
} // namespace sopt::cppflowutils
6 changes: 2 additions & 4 deletions cpp/sopt/cppflow_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
#include "cppflow/ops.h"
#include <complex>

namespace sopt {
namespace cppflowutils {
namespace sopt::cppflowutils {

//! Converts a sopt::Image to a cppflow::tensor
cppflow::tensor convert_image_to_tensor(sopt::Image<double> const &image, int image_rows, int image_cols);
Expand All @@ -20,6 +19,5 @@ cppflow::tensor convert_image_to_tensor(sopt::Vector<std::complex<double>> const
//! Convert a cppflow:tensor to an Eigen::Array
Eigen::Map<Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic>> convert_tensor_to_image(std::vector<float> model_output, int image_rows, int image_cols);

} // namespace cppflowutils
} // namespace sopt
} // namespace sopt::cppflowutils
#endif
13 changes: 4 additions & 9 deletions cpp/sopt/credible_region.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#include "sopt/logging.h"
#include "sopt/types.h"

namespace sopt {
namespace credible_region {
namespace sopt::credible_region {

template <class T>
t_real compute_energy_upper_bound(
Expand Down Expand Up @@ -54,11 +53,9 @@ credible_interval(const Eigen::MatrixBase<T> &solution, const t_uint &rows, cons
const std::tuple<t_uint, t_uint> &grid_pixel_size,
const std::function<t_real(typename T::PlainObject)> &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 <class T>
t_real compute_energy_upper_bound(
Expand Down Expand Up @@ -197,8 +194,6 @@ credible_interval(const Eigen::MatrixBase<T> &solution, const t_uint &rows, cons
return credible_interval_grid<typename T::PlainObject, K>(solution, rows, cols, grid_pixel_size,
objective_function, energy_upperbound);
}
} // namespace credible_region

} // namespace sopt
} // namespace sopt::credible_region

#endif
6 changes: 2 additions & 4 deletions cpp/sopt/forward_backward.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -282,6 +281,5 @@ typename ForwardBackward<SCALAR>::Diagnostic ForwardBackward<SCALAR>::operator()
}
return {niters, converged, std::move(residual)};
}
} // namespace algorithm
} // namespace sopt
} // namespace sopt::algorithm
#endif
6 changes: 2 additions & 4 deletions cpp/sopt/gradient_operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class T>
Vector<T> diff(const Vector<T> &x) {
Expand Down Expand Up @@ -61,7 +60,6 @@ LinearTransform<Vector<T>> gradient_operator(const t_int rows, const t_int cols)
},
{{0, 1, static_cast<t_int>(2 * rows * cols)}});
}
} // namespace gradient_operator
} // namespace sopt
} // namespace sopt::gradient_operator

#endif
6 changes: 2 additions & 4 deletions cpp/sopt/imaging_forward_backward.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
#include "sopt/mpi/utilities.h"
#endif

namespace sopt {
namespace algorithm {
namespace sopt::algorithm {
template <class SCALAR>
class ImagingForwardBackward {
//! Underlying algorithm
Expand Down Expand Up @@ -337,6 +336,5 @@ bool ImagingForwardBackward<SCALAR>::is_converged(ScalarRelativeVariation<Scalar
// better evaluate each convergence function everytime, especially with mpi
return user and res and obj;
}
} // namespace algorithm
} // namespace sopt
} // namespace sopt::algorithm
#endif
6 changes: 2 additions & 4 deletions cpp/sopt/imaging_padmm.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
#include "sopt/relative_variation.h"
#include "sopt/types.h"

namespace sopt {
namespace algorithm {
namespace sopt::algorithm {
template <class SCALAR>
class ImagingProximalADMM {
//! Underlying algorithm
Expand Down Expand Up @@ -346,6 +345,5 @@ bool ImagingProximalADMM<SCALAR>::is_converged(ScalarRelativeVariation<Scalar> &
// better evaluate each convergence function everytime, especially with mpi
return user and res and obj;
}
} // namespace algorithm
} // namespace sopt
} // namespace sopt::algorithm
#endif
6 changes: 2 additions & 4 deletions cpp/sopt/imaging_primal_dual.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
#include "sopt/relative_variation.h"
#include "sopt/types.h"

namespace sopt {
namespace algorithm {
namespace sopt::algorithm {
template <class SCALAR>
class ImagingPrimalDual {
//! Underlying algorithm
Expand Down Expand Up @@ -394,6 +393,5 @@ bool ImagingPrimalDual<SCALAR>::is_converged(ScalarRelativeVariation<Scalar> &sc
// better evaluate each convergence function everytime, especially with mpi
return user and res and obj;
}
} // namespace algorithm
} // namespace sopt
} // namespace sopt::algorithm
#endif
6 changes: 2 additions & 4 deletions cpp/sopt/joint_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
#include "sopt/logging.h"
#include "sopt/types.h"

namespace sopt {
namespace algorithm {
namespace sopt::algorithm {

template <class ALGORITHM>
class JointMAP {
Expand Down Expand Up @@ -135,7 +134,6 @@ class JointMAP {
};
};

} // namespace algorithm
} // namespace sopt
} // namespace sopt::algorithm

#endif
6 changes: 2 additions & 4 deletions cpp/sopt/l1_g_proximal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -145,6 +144,5 @@ class L1GProximal : public GProximal<SCALAR> {
}

};
}
}
} // namespace sopt::algorithm
#endif
6 changes: 2 additions & 4 deletions cpp/sopt/l1_proximal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -475,7 +474,6 @@ class L1<SCALAR>::Breaker {
std::array<Real, 4> objectives;
bool do_two_cycle;
};
} // namespace proximal
} // namespace sopt
} // namespace sopt::proximal

#endif
6 changes: 2 additions & 4 deletions cpp/sopt/l2_forward_backward.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
#include "sopt/mpi/utilities.h"
#endif

namespace sopt {
namespace algorithm {
namespace sopt::algorithm {
template <class SCALAR>
class L2ForwardBackward {
//! Underlying algorithm
Expand Down Expand Up @@ -337,6 +336,5 @@ bool L2ForwardBackward<SCALAR>::is_converged(ScalarRelativeVariation<Scalar> &sc
// better evaluate each convergence function everytime, especially with mpi
return user and res and obj;
}
} // namespace algorithm
} // namespace sopt
} // namespace sopt::algorithm
#endif
6 changes: 2 additions & 4 deletions cpp/sopt/l2_primal_dual.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
#include "sopt/relative_variation.h"
#include "sopt/types.h"

namespace sopt {
namespace algorithm {
namespace sopt::algorithm {
template <class SCALAR>
class ImagingPrimalDual {
//! Underlying algorithm
Expand Down Expand Up @@ -395,6 +394,5 @@ bool ImagingPrimalDual<SCALAR>::is_converged(ScalarRelativeVariation<Scalar> &sc
// better evaluate each convergence function everytime, especially with mpi
return user and res and obj;
}
} // namespace algorithm
} // namespace sopt
} // namespace sopt::algorithm
#endif
6 changes: 2 additions & 4 deletions cpp/sopt/logging.disabled.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
#include <memory>
#include <string>

namespace sopt {
namespace logging {
namespace sopt::logging {
//! Name of the sopt logger
const std::string name_prefix = "sopt::";

Expand All @@ -17,8 +16,7 @@ inline std::shared_ptr<int> 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_(...)
Expand Down
6 changes: 2 additions & 4 deletions cpp/sopt/logging.enabled.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
#include <spdlog/sinks/stdout_sinks.h>
#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.
Expand Down Expand Up @@ -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, ...) \
Expand Down
6 changes: 2 additions & 4 deletions cpp/sopt/mpi/communicator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#include <mpi.h>
#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)
Expand Down Expand Up @@ -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
6 changes: 2 additions & 4 deletions cpp/sopt/mpi/communicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
#include <cxxabi.h>
#include <typeinfo>

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
Expand Down Expand Up @@ -584,7 +583,6 @@ Communicator::broadcast(t_uint const root) const {
MPI_Bcast(result.data(), result.size(), Type<typename T::value_type>::value, root, **this);
return result;
}
} // namespace mpi
} // namespace sopt
} // namespace sopt::mpi
#endif /* ifdef SOPT_MPI */
#endif /* ifndef SOPT_MPI_COMMUNICATOR */
6 changes: 2 additions & 4 deletions cpp/sopt/mpi/registered_types.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "sopt/mpi/registered_types.h"

namespace sopt {
namespace mpi {
namespace sopt::mpi {
MPIType const Type<std::int8_t>::value = MPI_INT8_T;
MPIType const Type<std::int16_t>::value = MPI_INT16_T;
MPIType const Type<std::int32_t>::value = MPI_INT32_T;
Expand Down Expand Up @@ -33,5 +32,4 @@ static_assert(is_registered_type<std::complex<double>>::value,
"Checking complex double is registered");
static_assert(not is_registered_type<std::complex<int>>::value,
"Checking complex int is NOT registered");
} // namespace mpi
} // namespace sopt
} // namespace sopt::mpi
6 changes: 2 additions & 4 deletions cpp/sopt/mpi/registered_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
#ifdef SOPT_MPI
#include <complex>
#include <mpi.h>
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
Expand Down Expand Up @@ -73,7 +72,6 @@ template <class T, class = details::void_t<>>
class is_registered_type : public std::false_type {};
template <class T>
class is_registered_type<T, details::void_t<decltype(Type<T>::value)>> : public std::true_type {};
} // namespace mpi
} // namespace sopt
} // namespace sopt::mpi
#endif
#endif /* ifndef SOPT_TYPES */
6 changes: 2 additions & 4 deletions cpp/sopt/mpi/session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -80,5 +79,4 @@ void finalize() {
MPI_Finalize();
}

} // namespace mpi
} // namespace sopt
} // namespace sopt::mpi
Loading

0 comments on commit ad891db

Please sign in to comment.