Skip to content

Commit be28071

Browse files
committed
reformat everything
1 parent d8cf82f commit be28071

File tree

14 files changed

+316
-311
lines changed

14 files changed

+316
-311
lines changed

include/riccati/arena_matrix.hpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ class arena_matrix : public Eigen::Map<MatrixType> {
6060
* @param allocator The allocator to receive memory from
6161
* @param size number of elements
6262
*/
63-
template <typename T, typename Int, std::enable_if_t<std::is_integral_v<Int>>* = nullptr>
63+
template <typename T, typename Int,
64+
std::enable_if_t<std::is_integral_v<Int>>* = nullptr>
6465
arena_matrix(arena_allocator<T, arena_alloc>& allocator, Int size)
6566
: Base::Map(allocator.template allocate<Scalar>(size), size),
6667
allocator_(allocator) {}
@@ -74,15 +75,15 @@ class arena_matrix : public Eigen::Map<MatrixType> {
7475
arena_matrix(arena_allocator<T, arena_alloc>& allocator,
7576
const Expr& other) // NOLINT
7677
: Base::Map(
77-
allocator.template allocate<Scalar>(other.size()),
78-
(RowsAtCompileTime == 1 && Expr::ColsAtCompileTime == 1)
79-
|| (ColsAtCompileTime == 1 && Expr::RowsAtCompileTime == 1)
80-
? other.cols()
81-
: other.rows(),
82-
(RowsAtCompileTime == 1 && Expr::ColsAtCompileTime == 1)
83-
|| (ColsAtCompileTime == 1 && Expr::RowsAtCompileTime == 1)
84-
? other.rows()
85-
: other.cols()),
78+
allocator.template allocate<Scalar>(other.size()),
79+
(RowsAtCompileTime == 1 && Expr::ColsAtCompileTime == 1)
80+
|| (ColsAtCompileTime == 1 && Expr::RowsAtCompileTime == 1)
81+
? other.cols()
82+
: other.rows(),
83+
(RowsAtCompileTime == 1 && Expr::ColsAtCompileTime == 1)
84+
|| (ColsAtCompileTime == 1 && Expr::RowsAtCompileTime == 1)
85+
? other.rows()
86+
: other.cols()),
8687
allocator_(allocator) {
8788
allocator_.owns_alloc_ = false;
8889
(*this).noalias() = other;
@@ -169,7 +170,8 @@ inline auto to_arena(dummy_allocator& arena, const Expr& expr) noexcept {
169170
}
170171

171172
template <typename Expr, typename T>
172-
inline auto empty_arena_matrix(arena_allocator<T, arena_alloc>& alloc, Expr&& expr) {
173+
inline auto empty_arena_matrix(arena_allocator<T, arena_alloc>& alloc,
174+
Expr&& expr) {
173175
using plain_type_t = typename std::decay_t<Expr>::PlainObject;
174176
return arena_matrix<plain_type_t>(alloc, expr.rows(), expr.cols());
175177
}
@@ -181,19 +183,19 @@ inline auto empty_arena_matrix(dummy_allocator& arena, Expr&& expr) {
181183
}
182184

183185
template <typename Expr, typename T>
184-
inline auto empty_arena_matrix(arena_allocator<T, arena_alloc>& alloc, Eigen::Index rows, Eigen::Index cols) {
186+
inline auto empty_arena_matrix(arena_allocator<T, arena_alloc>& alloc,
187+
Eigen::Index rows, Eigen::Index cols) {
185188
using plain_type_t = typename std::decay_t<Expr>::PlainObject;
186189
return arena_matrix<plain_type_t>(alloc, rows, cols);
187190
}
188191

189192
template <typename Expr>
190-
inline auto empty_arena_matrix(dummy_allocator& arena, Eigen::Index rows, Eigen::Index cols) {
193+
inline auto empty_arena_matrix(dummy_allocator& arena, Eigen::Index rows,
194+
Eigen::Index cols) {
191195
using plain_type_t = typename std::decay_t<Expr>::PlainObject;
192196
return plain_type_t(rows, cols);
193197
}
194198

195-
196-
197199
template <typename T>
198200
inline void print(const char* name, const arena_matrix<T>& x) {
199201
#ifdef RICCATI_DEBUG

include/riccati/chebyshev.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,11 @@ RICCATI_ALWAYS_INLINE auto spectral_chebyshev(SolverInfo&& info, Scalar x0,
405405
auto&& D = info.Dn(niter);
406406
auto ws = omega(info, x_scaled);
407407
auto gs = gamma(info, x_scaled);
408-
auto D2 = eval(info.alloc_,
409-
((D * D) + h * (gs.asDiagonal() * D)) +
410-
((ws * h / 2.0).array().square()).matrix().asDiagonal().toDenseMatrix());
408+
auto D2 = eval(info.alloc_, ((D * D) + h * (gs.asDiagonal() * D))
409+
+ ((ws * h / 2.0).array().square())
410+
.matrix()
411+
.asDiagonal()
412+
.toDenseMatrix());
411413
const auto n = std::round(std::get<0>(info.chebyshev_[niter]));
412414
auto D2ic = eval(info.alloc_, matrix_t<complex_t>::Zero(n + 3, n + 1));
413415
D2ic.topRows(n + 1) = D2;

include/riccati/evolve.hpp

Lines changed: 73 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ namespace riccati {
6666
* standard discrete steps of the solver.
6767
*/
6868
template <typename SolverInfo, typename Scalar, typename Vec, typename YScalar>
69-
inline auto osc_evolve(SolverInfo &&info, Scalar xi, Scalar xf,
70-
YScalar yi, YScalar dyi,
71-
Scalar eps, Scalar epsilon_h, Scalar init_stepsize,
72-
Vec &&x_eval, bool hard_stop = false) {
69+
inline auto osc_evolve(SolverInfo &&info, Scalar xi, Scalar xf, YScalar yi,
70+
YScalar dyi, Scalar eps, Scalar epsilon_h,
71+
Scalar init_stepsize, Vec &&x_eval,
72+
bool hard_stop = false) {
7373
int sign = init_stepsize > 0 ? 1 : -1;
7474
using complex_t = promote_complex_t<Scalar>;
7575
using vectorc_t = vector_t<complex_t>;
@@ -92,12 +92,14 @@ inline auto osc_evolve(SolverInfo &&info, Scalar xi, Scalar xf,
9292
constexpr bool dense_output = compile_size_v<Vec> != 0;
9393
auto osc_ret = osc_step<dense_output>(info, omega_n, gamma_n, xi,
9494
init_stepsize, yi, dyi, eps);
95-
auto make_osc_ret = [](auto&& tup) {
96-
return std::make_tuple(std::get<0>(tup), std::get<1>(tup), std::get<2>(tup), std::get<3>(tup));
95+
auto make_osc_ret = [](auto &&tup) {
96+
return std::make_tuple(std::get<0>(tup), std::get<1>(tup), std::get<2>(tup),
97+
std::get<3>(tup));
9798
};
9899
if (std::get<0>(osc_ret) == 0) {
99-
return std::make_tuple(false, xi, init_stepsize, make_osc_ret(osc_ret), vectorc_t(0),
100-
vectorc_t(0), static_cast<Eigen::Index>(0),
100+
return std::make_tuple(false, xi, init_stepsize, make_osc_ret(osc_ret),
101+
vectorc_t(0), vectorc_t(0),
102+
static_cast<Eigen::Index>(0),
101103
static_cast<Eigen::Index>(0));
102104
} else {
103105
Eigen::Index dense_size = 0;
@@ -140,7 +142,8 @@ inline auto osc_evolve(SolverInfo &&info, Scalar xi, Scalar xf,
140142
// o and g written here
141143
auto h_next = choose_osc_stepsize(info, x_next, hosc_ini, epsilon_h);
142144
// TODO: CANNOT RETURN ARENA MATRIX FROM OSC_RET
143-
return std::make_tuple(true, x_next, std::get<0>(h_next), make_osc_ret(osc_ret), std::move(yeval),
145+
return std::make_tuple(true, x_next, std::get<0>(h_next),
146+
make_osc_ret(osc_ret), std::move(yeval),
144147
std::move(dyeval), dense_start, dense_size);
145148
}
146149
}
@@ -199,10 +202,10 @@ inline auto osc_evolve(SolverInfo &&info, Scalar xi, Scalar xf,
199202
* standard discrete steps of the solver.
200203
*/
201204
template <typename SolverInfo, typename Scalar, typename Vec, typename YScalar>
202-
inline auto nonosc_evolve(SolverInfo &&info, Scalar xi, Scalar xf,
203-
YScalar yi, YScalar dyi,
204-
Scalar eps, Scalar epsilon_h, Scalar init_stepsize,
205-
Vec &&x_eval, bool hard_stop = false) {
205+
inline auto nonosc_evolve(SolverInfo &&info, Scalar xi, Scalar xf, YScalar yi,
206+
YScalar dyi, Scalar eps, Scalar epsilon_h,
207+
Scalar init_stepsize, Vec &&x_eval,
208+
bool hard_stop = false) {
206209
using complex_t = promote_complex_t<Scalar>;
207210
using vectorc_t = vector_t<complex_t>;
208211
vectorc_t yeval;
@@ -244,12 +247,12 @@ inline auto nonosc_evolve(SolverInfo &&info, Scalar xi, Scalar xf,
244247
if (dense_size != 0) {
245248
auto x_eval_map = x_eval.segment(dense_start, dense_size);
246249
auto xi_scaled
247-
= (xi + init_stepsize / 2
248-
+ (init_stepsize / 2)
249-
* std::get<2>(info.chebyshev_[std::get<6>(nonosc_ret)])
250-
.array())
251-
.matrix()
252-
.eval();
250+
= (xi + init_stepsize / 2
251+
+ (init_stepsize / 2)
252+
* std::get<2>(info.chebyshev_[std::get<6>(nonosc_ret)])
253+
.array())
254+
.matrix()
255+
.eval();
253256
auto Linterp = interpolate(xi_scaled, x_eval_map, info.alloc_);
254257
yeval = Linterp * std::get<4>(nonosc_ret);
255258
dyeval = Linterp * std::get<5>(nonosc_ret);
@@ -325,25 +328,26 @@ inline auto nonosc_evolve(SolverInfo &&info, Scalar xi, Scalar xf,
325328
* equations.
326329
* 6. @ref Eigen::Matrix<std::complex<Scalar>, -1, 1>: A vector containing the
327330
* interpolated solution at the specified `x_eval` The function returns these
328-
* 7. An array of logging information for the solver process. This can be added with the
329-
* info() from the `SolverInfo` object to get the total log information.
330-
* vectors encapsulated in a standard tuple, providing comprehensive information
331-
* about the solution process, including where the solution was evaluated, the
332-
* values and derivatives of the solution at those points, success status of
333-
* each step, type of each step, and phase angles where applicable.
331+
* 7. An array of logging information for the solver process. This can be added
332+
* with the info() from the `SolverInfo` object to get the total log
333+
* information. vectors encapsulated in a standard tuple, providing
334+
* comprehensive information about the solution process, including where the
335+
* solution was evaluated, the values and derivatives of the solution at those
336+
* points, success status of each step, type of each step, and phase angles
337+
* where applicable.
334338
*/
335339
template <typename SolverInfo, typename Scalar, typename Vec, typename YScalar>
336-
inline auto evolve(SolverInfo &info, Scalar xi, Scalar xf,
337-
YScalar yi, YScalar dyi,
338-
Scalar eps, Scalar epsilon_h, Scalar init_stepsize,
339-
Vec &&x_eval, bool hard_stop = false,
340+
inline auto evolve(SolverInfo &info, Scalar xi, Scalar xf, YScalar yi,
341+
YScalar dyi, Scalar eps, Scalar epsilon_h,
342+
Scalar init_stepsize, Vec &&x_eval, bool hard_stop = false,
340343
LogLevel log_level = riccati::LogLevel::ERROR) {
341344
using vectord_t = vector_t<Scalar>;
342345
Scalar direction = init_stepsize > 0 ? 1 : -1;
343346
if (init_stepsize * (xf - xi) < 0) {
344347
throw std::domain_error(
345348
"Direction of integration does not match stepsize sign,"
346-
" adjust the direction or stepsize so that integration happens from xi to xf.");
349+
" adjust the direction or stepsize so that integration happens from xi "
350+
"to xf.");
347351
}
348352
// Check that yeval and x_eval are right size
349353
constexpr bool dense_output = compile_size_v<Vec> != 0;
@@ -432,8 +436,8 @@ inline auto evolve(SolverInfo &info, Scalar xi, Scalar xf,
432436
* std::min(std::min(static_cast<Scalar>(1e8),
433437
static_cast<Scalar>(std::abs(omega_i / domega_i))),
434438
std::abs(gamma_i / dgamma_i));
435-
info.logger().template log<LogLevel::INFO>(log_level,
436-
"[setup]", std::pair("hslo_ini", hslo_ini));
439+
info.logger().template log<LogLevel::INFO>(log_level, "[setup]",
440+
std::pair("hslo_ini", hslo_ini));
437441
if (hard_stop) {
438442
if (direction * (xi + hosc_ini) > direction * xf) {
439443
hosc_ini = xf - xi;
@@ -460,9 +464,10 @@ inline auto evolve(SolverInfo &info, Scalar xi, Scalar xf,
460464
&& direction * xcurrent < direction * xf) {
461465
if (unlikely(log_level >= LogLevel::INFO)) {
462466
[&]() RICCATI_COLD_PATH {
463-
info.logger().template log<LogLevel::INFO>(log_level,
464-
std::pair("std::abs(xcurrent - xf)", std::abs(xcurrent - xf)),
465-
std::pair("direction * xcurrent", direction * xcurrent));
467+
info.logger().template log<LogLevel::INFO>(
468+
log_level,
469+
std::pair("std::abs(xcurrent - xf)", std::abs(xcurrent - xf)),
470+
std::pair("direction * xcurrent", direction * xcurrent));
466471
}();
467472
}
468473
Scalar phase{0.0};
@@ -489,22 +494,20 @@ inline auto evolve(SolverInfo &info, Scalar xi, Scalar xf,
489494
if constexpr (dense_output) {
490495
std::tie(success, y, dy, err, phase, un, d_un, a_pair)
491496
= osc_step<dense_output>(info, omega_n, gamma_n, xcurrent, hosc,
492-
yprev, dyprev, eps);
497+
yprev, dyprev, eps);
493498
} else {
494-
std::tie(success, y, dy, err, phase)
495-
= osc_step<dense_output>(info, omega_n, gamma_n, xcurrent, hosc,
496-
yprev, dyprev, eps);
499+
std::tie(success, y, dy, err, phase) = osc_step<dense_output>(
500+
info, omega_n, gamma_n, xcurrent, hosc, yprev, dyprev, eps);
497501
}
498502
steptype = 1;
499503
solver_counts[get_idx(LogInfo::RICCSTEP)].second++;
500504
}
501505
if (unlikely(log_level >= LogLevel::INFO)) {
502506
[&]() RICCATI_COLD_PATH {
503-
info.logger().template log<LogLevel::INFO>(log_level,
504-
std::pair("oscillatory step", (success ? "success" : "failure")),
505-
std::pair("x", xcurrent),
506-
std::pair("stepsize", hosc)
507-
);
507+
info.logger().template log<LogLevel::INFO>(
508+
log_level,
509+
std::pair("oscillatory step", (success ? "success" : "failure")),
510+
std::pair("x", xcurrent), std::pair("stepsize", hosc));
508511
}();
509512
}
510513
} else {
@@ -518,14 +521,14 @@ inline auto evolve(SolverInfo &info, Scalar xi, Scalar xf,
518521
steptype = 0;
519522
if (unlikely(log_level >= LogLevel::INFO)) {
520523
[&]() RICCATI_COLD_PATH {
521-
info.logger().template log<LogLevel::INFO>(log_level,
522-
std::pair("nonoscillatory step", (success ? "success" : "failures")),
523-
std::pair("x", xcurrent),
524-
std::pair("stepsize", hslo),
525-
std::pair("y", y.real()),
526-
std::pair("dy", dy.real()),
527-
std::pair("err", std::real(err)),
528-
std::pair("cheb_steps", cheb_N));
524+
info.logger().template log<LogLevel::INFO>(
525+
log_level,
526+
std::pair("nonoscillatory step",
527+
(success ? "success" : "failures")),
528+
std::pair("x", xcurrent), std::pair("stepsize", hslo),
529+
std::pair("y", y.real()), std::pair("dy", dy.real()),
530+
std::pair("err", std::real(err)),
531+
std::pair("cheb_steps", cheb_N));
529532
}();
530533
}
531534
if (!success) {
@@ -546,10 +549,9 @@ inline auto evolve(SolverInfo &info, Scalar xi, Scalar xf,
546549
if (dense_size != 0) {
547550
if (unlikely(log_level >= LogLevel::INFO)) {
548551
[&]() RICCATI_COLD_PATH {
549-
info.logger().template log<LogLevel::INFO>(log_level,
550-
"dense output",
551-
std::pair("x_start", xcurrent),
552-
std::pair("x_end", xcurrent + h));
552+
info.logger().template log<LogLevel::INFO>(
553+
log_level, "dense output", std::pair("x_start", xcurrent),
554+
std::pair("x_end", xcurrent + h));
553555
}();
554556
}
555557
auto x_eval_map
@@ -583,17 +585,13 @@ inline auto evolve(SolverInfo &info, Scalar xi, Scalar xf,
583585
}
584586
}
585587
// Finish appending and ending conditions
586-
if (unlikely(log_level >= LogLevel::INFO)) {
587-
[&]() RICCATI_COLD_PATH {
588-
info.logger().template log<LogLevel::INFO>(log_level,
589-
"step completed",
590-
std::pair("y", y),
591-
std::pair("dy", dy),
592-
std::pair("x_next", xcurrent + h),
593-
std::pair("phase", phase),
594-
std::pair("steptype", steptype)
595-
);
596-
}();
588+
if (unlikely(log_level >= LogLevel::INFO)) {
589+
[&]() RICCATI_COLD_PATH {
590+
info.logger().template log<LogLevel::INFO>(
591+
log_level, "step completed", std::pair("y", y), std::pair("dy", dy),
592+
std::pair("x_next", xcurrent + h), std::pair("phase", phase),
593+
std::pair("steptype", steptype));
594+
}();
597595
}
598596
ys.push_back(y);
599597
dys.push_back(dy);
@@ -641,32 +639,31 @@ inline auto evolve(SolverInfo &info, Scalar xi, Scalar xf,
641639
}
642640
info.alloc_.recover_memory();
643641
}
644-
if constexpr (!std::is_same_v<std::decay_t<decltype(info.logger())>, EmptyLogger>) {
642+
if constexpr (!std::is_same_v<std::decay_t<decltype(info.logger())>,
643+
EmptyLogger>) {
645644
if (unlikely(log_level >= LogLevel::INFO)) {
646645
info.logger().template log<LogLevel::INFO>(log_level,
647-
std::string("x", xcurrent));
646+
std::string("x", xcurrent));
648647
std::size_t riccati_steps = 0;
649648
std::size_t rk_steps = 0;
650-
for (auto& success : successes) {
649+
for (auto &success : successes) {
651650
if (success) {
652651
riccati_steps++;
653652
} else {
654653
rk_steps++;
655654
}
656655
}
657-
info.logger().template log<LogLevel::INFO>(log_level,
658-
std::pair("Total Steps", successes.size())
659-
);
660-
for (auto&& info_pair : solver_counts) {
656+
info.logger().template log<LogLevel::INFO>(
657+
log_level, std::pair("Total Steps", successes.size()));
658+
for (auto &&info_pair : solver_counts) {
661659
info.logger().template log<LogLevel::INFO>(log_level, info_pair);
662660
}
663661
}
664662
}
665663
return std::make_tuple(xs, ys, dys, successes, phases, steptypes, yeval,
666-
dyeval, 1.0);
664+
dyeval, 1.0);
667665
}
668666

669-
670667
} // namespace riccati
671668

672669
#endif

include/riccati/logger.hpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,12 @@ class PtrLogger : public LoggerBase<PtrLogger<Ptr>> {
199199
RICCATI_NO_INLINE explicit PtrLogger(const std::shared_ptr<Stream>& output)
200200
: output_(output) {}
201201

202-
203-
204202
template <LogLevel Level, typename T, typename... Args>
205-
inline auto concat_string(std::stringstream& stream, T&& arg, Args&&... args) {
203+
inline auto concat_string(std::stringstream& stream, T&& arg,
204+
Args&&... args) {
206205
if constexpr (is_pair_v<T>) {
207-
if constexpr (std::is_same_v<LogInfo, std::decay_t<decltype(arg.first)>>) {
206+
if constexpr (std::is_same_v<LogInfo,
207+
std::decay_t<decltype(arg.first)>>) {
208208
stream << to_string(arg.first) << "=";
209209
} else {
210210
stream << "[" << arg.first << "=";
@@ -248,7 +248,7 @@ class PtrLogger : public LoggerBase<PtrLogger<Ptr>> {
248248
}
249249

250250
template <LogLevel Level, typename T, typename... Args,
251-
std::enable_if_t<sizeof...(Args) != 0>* = nullptr>
251+
std::enable_if_t<sizeof...(Args) != 0>* = nullptr>
252252
inline void log(LogLevel UserLevel, T&& arg, Args&&... args) {
253253
if constexpr (!RICCATI_DEBUG_VAL && Level == LogLevel::DEBUG) {
254254
return;
@@ -258,7 +258,9 @@ class PtrLogger : public LoggerBase<PtrLogger<Ptr>> {
258258
}
259259
std::stringstream stream;
260260
stream << std::setprecision(18);
261-
this->log<Level>(UserLevel, concat_string<Level>(stream, std::forward<T>(arg), std::forward<Args>(args)...));
261+
this->log<Level>(UserLevel,
262+
concat_string<Level>(stream, std::forward<T>(arg),
263+
std::forward<Args>(args)...));
262264
}
263265
};
264266

0 commit comments

Comments
 (0)