Skip to content

Commit

Permalink
[DLG] Super-minor changes to avoid gcc warnings
Browse files Browse the repository at this point in the history
diegolodares committed Dec 28, 2023
1 parent b7faf4b commit dfcaf2f
Showing 5 changed files with 45 additions and 18 deletions.
24 changes: 14 additions & 10 deletions lion/foundation/tuple_helpers.h
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@

#ifndef _MSC_VER

namespace detail::tuple_helpers {
namespace lioncpp::detail::tuple_helpers {

template<typename IndexType, IndexType Offset, typename IntegerSequence>
struct offset_integer_sequence {};
@@ -51,7 +51,7 @@ constexpr void tuple_index_for_impl(Tuple &&tuple, Fun &&f, std::integer_sequenc
(f(std::get<Is>(std::forward<Tuple>(tuple)), std::integral_constant<IndexType, Is>{}), ...);
}

} // end namespace detail::tuple_helpers
} // end namespace lioncpp::detail::tuple_helpers


//
@@ -64,8 +64,9 @@ template<std::size_t Begin, std::size_t End,
typename std::enable_if_t<Begin < End>* = nullptr>
constexpr void index_for(Fun &&f)
{
detail::tuple_helpers::index_for_impl(std::forward<Fun>(f),
detail::tuple_helpers::offset_integer_sequence_t<std::size_t, Begin,
lioncpp::detail::tuple_helpers::index_for_impl(
std::forward<Fun>(f),
lioncpp::detail::tuple_helpers::offset_integer_sequence_t<std::size_t, Begin,
std::make_integer_sequence<std::size_t, End - Begin> >{});
}

@@ -84,7 +85,8 @@ template<std::size_t End,
typename Fun>
constexpr void index_for(Fun &&f)
{
detail::tuple_helpers::index_for_impl(std::forward<Fun>(f),
lioncpp::detail::tuple_helpers::index_for_impl(
std::forward<Fun>(f),
std::make_integer_sequence<std::size_t, End>{});
}

@@ -98,7 +100,8 @@ constexpr void index_for(Fun &&f)
template<typename Tuple, typename Fun>
constexpr void tuple_for(Tuple &&tuple, Fun &&f)
{
detail::tuple_helpers::tuple_for_impl(std::forward<Tuple>(tuple),
lioncpp::detail::tuple_helpers::tuple_for_impl(
std::forward<Tuple>(tuple),
std::forward<Fun>(f),
std::make_integer_sequence<std::size_t, std::tuple_size_v<std::decay_t<Tuple> > >{});
}
@@ -113,7 +116,8 @@ constexpr void tuple_for(Tuple &&tuple, Fun &&f)
template<typename Tuple, typename Fun>
constexpr void tuple_index_for(Tuple &&tuple, Fun &&f)
{
detail::tuple_helpers::tuple_index_for_impl(std::forward<Tuple>(tuple),
lioncpp::detail::tuple_helpers::tuple_index_for_impl(
std::forward<Tuple>(tuple),
std::forward<Fun>(f),
std::make_integer_sequence<std::size_t, std::tuple_size_v<std::decay_t<Tuple> > >{});
}
@@ -256,7 +260,7 @@ constexpr auto array_cat(const std::array<Type, sizes>&... arrays)

#else

namespace detail::tuple_helpers {
namespace lioncpp::detail::tuple_helpers {

template<typename... Args>
struct add_array_sizes {};
@@ -273,7 +277,7 @@ struct add_array_sizes<std::array<T, size>, RestOfArrays...>
static constexpr std::size_t value = size + add_array_sizes<RestOfArrays...>::value;
};

} // end namespace detail::tuple_helpers
} // end namespace lioncpp::detail::tuple_helpers

template<typename Type, std::size_t... sizes>
constexpr auto array_cat(const std::array<Type, sizes>&... arrays)
@@ -283,7 +287,7 @@ constexpr auto array_cat(const std::array<Type, sizes>&... arrays)
// (implementation that works in VS2017).
//

std::array<Type, ::detail::tuple_helpers::add_array_sizes<std::array<Type, sizes>...>::value> result;
std::array<Type, lioncpp::detail::tuple_helpers::add_array_sizes<std::array<Type, sizes>...>::value> result;
std::size_t index = 0u;

tuple_for(std::forward_as_tuple(arrays...),
18 changes: 17 additions & 1 deletion lion/foundation/utils.hpp
Original file line number Diff line number Diff line change
@@ -804,14 +804,30 @@ std::vector<ScalarType> grid_vectors2points_rowmaj(const ContainerOfGridVectorsT
// etc).
//

// VS2017 doesn't have std::exclusive_scan...
const auto std__exclusive_scan = [](auto first, auto last, auto d_first, auto init, auto &&binary_op)
{
#if defined(_MSC_VER) && _MSC_VER <= 1916
while (first != last) {
auto v = init;
init = binary_op(init, *first);
++first;
*d_first++ = std::move(v);
}
return d_first;
#else
return std::exclusive_scan(first, last, d_first, init, binary_op);
#endif
};

const auto num_grid_vectors = grid_vectors.size();

std::vector<std::size_t> grid_vector_sizes(num_grid_vectors);
std::transform(grid_vectors.cbegin(), grid_vectors.cend(), grid_vector_sizes.begin(),
[](auto &gv) { return gv.size(); });

std::vector<std::size_t> grid_vectors_accumulated_sizes(num_grid_vectors);
std::exclusive_scan(grid_vector_sizes.cbegin(), grid_vector_sizes.cend(),
std__exclusive_scan(grid_vector_sizes.cbegin(), grid_vector_sizes.cend(),
grid_vectors_accumulated_sizes.begin(), std::size_t{ 1u }, std::multiplies<>{});

const auto total_num_points = (*grid_vectors_accumulated_sizes.rbegin()) *
2 changes: 1 addition & 1 deletion lion/math/ipopt_optimize_nlp_cppad.h
Original file line number Diff line number Diff line change
@@ -375,7 +375,7 @@ NLP_complete_output ipopt_compute_complete_nlp_cppad(std::size_t nx,
// at point "x" with Lagrange multipliers "lambda"
//

bool ok = true;
//bool ok = true;

Optimization_result<Dvector> solution;

15 changes: 10 additions & 5 deletions lion/math/matrix_extensions.h
Original file line number Diff line number Diff line change
@@ -493,11 +493,16 @@ std::ostream& operator<<(std::ostream &os, const std::array<T,N>& v)
template <typename T>
std::ostream& operator<<(std::ostream &os, const std::vector<T>& v)
{
os << "{" ;
for (auto it = v.cbegin(); it < v.cend()-1; ++it)
os << *it << ", " ;

os << v.back() << "}" ;
if (v.empty()) {
os << "{}";
}
else {
os << "{" ;
for (auto it = v.cbegin(); it < std::prev(v.cend()); ++it) {
os << *it << ", " ;
}
os << v.back() << "}" ;
}

return os;
}
4 changes: 3 additions & 1 deletion lion/math/mumps_interface.h
Original file line number Diff line number Diff line change
@@ -18,9 +18,11 @@ inline std::vector<std::vector<double>> mumps_solve_linear_system(size_type n_cp
size_t n_rhs = rhs_cpp.size();

assert(n_rhs > 0);
for ( const auto& rhs_i : rhs_cpp ) {
#ifndef NDEBUG
for (const auto &rhs_i : rhs_cpp) {
assert(rhs_i.size() == n_cpp);
}
#endif

DMUMPS_STRUC_C id;
MUMPS_INT n = static_cast<MUMPS_INT>(n_cpp);

0 comments on commit dfcaf2f

Please sign in to comment.