Skip to content

Commit

Permalink
[core] Reorganize headers
Browse files Browse the repository at this point in the history
+ move exception macros from math.hpp to exceptions.hpp
+ only include exceptions header in fwd.hpp
+ move utils/fmt-eigen.hpp up to base folder
  • Loading branch information
ManifoldFR committed Dec 1, 2023
1 parent bd44b0b commit 47ab413
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
8 changes: 8 additions & 0 deletions include/proxnlp/exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
PROXNLP_RUNTIME_ERROR(fmt::format( \
"Input size invalid (expected {:d}, got {:d})", nx, x.size()))

#define PROXNLP_RAISE_IF_NAN(value) \
if (::proxnlp::math::check_value(value)) \
PROXNLP_RUNTIME_ERROR("Encountered NaN.\n")

#define PROXNLP_RAISE_IF_NAN_NAME(value, name) \
if (::proxnlp::math::check_value(value)) \
PROXNLP_RUNTIME_ERROR(fmt::format("Encountered NaN for value {:s}.\n", name))

namespace proxnlp {

class RuntimeError : public std::runtime_error {
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions include/proxnlp/fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ using std::unique_ptr;
} // namespace proxnlp

#include "proxnlp/math.hpp"
#include "proxnlp/exceptions.hpp"
#include "proxnlp/macros.hpp"
#include "proxnlp/config.hpp"
#include "proxnlp/deprecated.hpp"
Expand Down
1 change: 1 addition & 0 deletions include/proxnlp/linalg/ldlt-base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma once

#include "proxnlp/math.hpp"
#include "proxnlp/exceptions.hpp"
#include "proxnlp/macros.hpp"

#include <Eigen/Cholesky>
Expand Down
23 changes: 4 additions & 19 deletions include/proxnlp/math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#pragma once

#include <Eigen/Core>
#include <limits>
#include <vector>

namespace proxnlp {

Expand All @@ -17,22 +19,6 @@ constexpr bool is_eigen_matrix_type =
template <typename T, typename T2 = void>
using enable_if_eigen_dense = std::enable_if_t<is_eigen_dense_type<T>, T2>;

} // namespace proxnlp

#include "proxnlp/utils/fmt-eigen.hpp"
#include "proxnlp/exceptions.hpp"

#include <limits>
#include <vector>

#define PROXNLP_RAISE_IF_NAN(value) \
if (::proxnlp::math::check_value(value)) \
PROXNLP_RUNTIME_ERROR("Encountered NaN.\n")

#define PROXNLP_RAISE_IF_NAN_NAME(value, name) \
if (::proxnlp::math::check_value(value)) \
PROXNLP_RUNTIME_ERROR(fmt::format("Encountered NaN for value {:s}.\n", name))

/// Macro typedefs for dynamic-sized vectors/matrices, used for cost funcs,
/// merit funcs because we don't CRTP them and virtual members funcs can't be
/// templated.
Expand All @@ -51,8 +37,6 @@ using enable_if_eigen_dense = std::enable_if_t<is_eigen_dense_type<T>, T2>;
using Matrix6Xs = Eigen::Matrix<Scalar, 6, Eigen::Dynamic>; \
using Matrix6s = Eigen::Matrix<Scalar, 6, 6>

namespace proxnlp {

/// @brief Typedefs for math (Eigen vectors, matrices) depending on scalar
/// type.
template <typename _Scalar> struct math_types {
Expand Down Expand Up @@ -108,5 +92,6 @@ bool check_value(const Eigen::MatrixBase<MatrixType> &x) {
}

} // namespace math

} // namespace proxnlp

#include "proxnlp/fmt-eigen.hpp"

0 comments on commit 47ab413

Please sign in to comment.