Skip to content

Commit

Permalink
Add getter for the number of outputs, rename.
Browse files Browse the repository at this point in the history
  • Loading branch information
bluescarni committed Jul 8, 2024
1 parent bdc7d4a commit d4d61a0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
3 changes: 2 additions & 1 deletion include/heyoka/model/sgp4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ class HEYOKA_DLL_PUBLIC_INLINE_CLASS sgp4_propagator
sgp4_propagator &operator=(sgp4_propagator &&) noexcept;
~sgp4_propagator();

[[nodiscard]] std::uint32_t get_n_sats() const;
[[nodiscard]] std::uint32_t get_nsats() const;
[[nodiscard]] std::uint32_t get_nouts() const noexcept;

[[nodiscard]] std::uint32_t get_diff_order() const noexcept;
[[nodiscard]] const std::vector<expression> &get_diff_args() const;
Expand Down
17 changes: 12 additions & 5 deletions src/model/sgp4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,11 +638,18 @@ sgp4_propagator<T>::~sgp4_propagator() = default;

template <typename T>
requires std::same_as<T, double> || std::same_as<T, float>
std::uint32_t sgp4_propagator<T>::get_n_sats() const
std::uint32_t sgp4_propagator<T>::get_nsats() const
{
return boost::numeric_cast<std::uint32_t>(m_impl->m_sat_buffer.size() / 9u);
}

template <typename T>
requires std::same_as<T, double> || std::same_as<T, float>
std::uint32_t sgp4_propagator<T>::get_nouts() const noexcept
{
return m_impl->m_cf_tprop.get_nouts();
}

template <typename T>
requires std::same_as<T, double> || std::same_as<T, float>
void sgp4_propagator<T>::check_with_diff(const char *fname) const
Expand Down Expand Up @@ -719,7 +726,7 @@ template <typename T>
requires std::same_as<T, double> || std::same_as<T, float>
void sgp4_propagator<T>::operator()(out_2d out, in_1d<T> tms)
{
const auto n_sats = get_n_sats();
const auto n_sats = get_nsats();
assert(n_sats != 0u); // LCOV_EXCL_LINE

// Prepare the init buffer span.
Expand Down Expand Up @@ -787,7 +794,7 @@ void sgp4_propagator<T>::operator()(out_2d out, in_1d<date> dates)
if (dates.data_handle() == nullptr) [[unlikely]] {
throw std::invalid_argument("A null array of dates was passed to the call operator of an sgp4_propagator");
}
const auto n_sats = get_n_sats();
const auto n_sats = get_nsats();
if (dates.extent(0) != n_sats) [[unlikely]] {
throw std::invalid_argument(
fmt::format("Invalid array of dates passed to the call operator of an sgp4_propagator: the number of "
Expand Down Expand Up @@ -860,7 +867,7 @@ void sgp4_propagator<T>::operator()(out_3d out, in_2d<T> tms)
n_evals, tms.extent(0)));
}

const auto n_sats = get_n_sats();
const auto n_sats = get_nsats();
assert(n_sats != 0u); // LCOV_EXCL_LINE

// Prepare the init buffer span.
Expand Down Expand Up @@ -928,7 +935,7 @@ void sgp4_propagator<T>::operator()(out_3d out, in_2d<date> dates)
throw std::invalid_argument(
"A null array of dates was passed to the batch-mode call operator of an sgp4_propagator");
}
const auto n_sats = get_n_sats();
const auto n_sats = get_nsats();
if (dates.extent(1) != n_sats) [[unlikely]] {
throw std::invalid_argument(fmt::format(
"Invalid array of dates passed to the batch-mode call operator of an sgp4_propagator: the number of "
Expand Down
12 changes: 7 additions & 5 deletions test/model_sgp4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,20 @@ TEST_CASE("propagator basics")
prop_t prop{md_input_t{ins.data(), 2}};
REQUIRE(prop.get_diff_order() == 0u);
auto prop2 = prop;
REQUIRE(prop2.get_n_sats() == 2u);
REQUIRE(prop2.get_nsats() == 2u);

// Move construction.
auto prop3 = std::move(prop2);
REQUIRE(prop3.get_n_sats() == 2u);
REQUIRE(prop3.get_nsats() == 2u);

// Revive prop2 via copy assignment.
prop2 = prop3;
REQUIRE(prop2.get_n_sats() == 2u);
REQUIRE(prop2.get_nsats() == 2u);

// Revive via move assignment.
prop_t prop4;
prop4 = std::move(prop2);
REQUIRE(prop4.get_n_sats() == 2u);
REQUIRE(prop4.get_nsats() == 2u);
}

TEST_CASE("propagator single")
Expand Down Expand Up @@ -208,6 +208,7 @@ TEST_CASE("propagator single")

for (auto cm : {false, true}) {
prop_t prop{md_input_t{ins.data(), 2}, kw::compact_mode = cm};
REQUIRE(prop.get_nouts() == 6u);

std::vector<double> outs(12u);
prop_t::out_2d out{outs.data(), 6, 2};
Expand Down Expand Up @@ -544,6 +545,7 @@ TEST_CASE("derivatives")

prop_t prop{md_input_t{ins.data(), 2}, kw::diff_order = 2};

REQUIRE(prop.get_nouts() == 168u);
REQUIRE(prop.get_diff_order() == 2u);
auto sl = prop.get_dslice(1);
REQUIRE(sl.first == 6u);
Expand Down Expand Up @@ -690,5 +692,5 @@ TEST_CASE("s11n")
ia >> prop;
}

REQUIRE(prop.get_n_sats() == 2u);
REQUIRE(prop.get_nsats() == 2u);
}

0 comments on commit d4d61a0

Please sign in to comment.