Skip to content

Commit

Permalink
Merge topic 'min-max-windows-confusion'
Browse files Browse the repository at this point in the history
dfd27ac windows: guard `std::min` and `std::max` usage

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Dmitriy Morozov <dmitriy@mrzv.org>
Merge-request: !80
  • Loading branch information
mathstuf authored and kwrobot committed Oct 30, 2023
2 parents 4513292 + dfd27ac commit 7cda7ee
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion bindings/python/ext/pybind11/include/pybind11/numpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -1655,7 +1655,7 @@ broadcast_trivial
broadcast(const std::array<buffer_info, N> &buffers, ssize_t &ndim, std::vector<ssize_t> &shape) {
ndim = std::accumulate(
buffers.begin(), buffers.end(), ssize_t(0), [](ssize_t res, const buffer_info &buf) {
return std::max(res, buf.ndim);
return (std::max)(res, buf.ndim);
});

shape.clear();
Expand Down
2 changes: 1 addition & 1 deletion examples/amr/nyx-amrex-henson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ int main()
}

// record neighbors
for (int nbr_lev = std::max(0, lev-1); nbr_lev <= std::min(finest_level, lev+1); ++nbr_lev)
for (int nbr_lev = (std::max)(0, lev-1); nbr_lev <= (std::min)(finest_level, lev+1); ++nbr_lev)
{
// gotta do this yoga to work around AMReX's static variables
const Box& nbr_lev_domain = amr->getLevel(nbr_lev).Domain();
Expand Down
10 changes: 5 additions & 5 deletions include/diy/decomposition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,8 @@ fill_bounds(Bounds& bounds, //!< (output) bounds
bounds.max[i] += ghosts[i];
} else
{
bounds.min[i] = std::max(domain.min[i], bounds.min[i] - ghosts[i]);
bounds.max[i] = std::min(domain.max[i], bounds.max[i] + ghosts[i]);
bounds.min[i] = (std::max)(domain.min[i], bounds.min[i] - ghosts[i]);
bounds.max[i] = (std::min)(domain.max[i], bounds.max[i] + ghosts[i]);
}
}
}
Expand Down Expand Up @@ -652,7 +652,7 @@ point_to_gid(const Point& p) const
for (int axis = dim - 1; axis >= 0; --axis)
{
int bottom = detail::BoundsHelper<Bounds>::lower(p[axis], divisions[axis], domain.min[axis], domain.max[axis], share_face[axis]);
bottom = std::max(0, bottom);
bottom = (std::max)(0, bottom);

// coupled with coords_to_gid
gid *= divisions[axis];
Expand Down Expand Up @@ -692,8 +692,8 @@ top_bottom(int& top, int& bottom, const Point& p, int axis) const

if (!wrap[axis])
{
bottom = std::max(0, bottom);
top = std::min(divisions[axis], top);
bottom = (std::max)(0, bottom);
top = (std::min)(divisions[axis], top);
}
}

Expand Down
2 changes: 1 addition & 1 deletion include/diy/detail/algorithms/kdtree-sampling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ compute_local_samples(Block* b, const diy::ReduceProxy& srp, int dim) const
// compute and enqueue local samples
Samples samples;
size_t points_size = (b->*points_).size();
size_t n = std::min(points_size, samples_);
size_t n = (std::min)(points_size, samples_);
samples.reserve(n);
for (size_t i = 0; i < n; ++i)
{
Expand Down
2 changes: 1 addition & 1 deletion include/diy/detail/master/execution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ execute()
}
else
{
num_threads = std::min(threads_, limit_);
num_threads = (std::min)(threads_, limit_);
blocks_per_thread = limit_/num_threads;
}

Expand Down
4 changes: 2 additions & 2 deletions include/diy/master.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ order_gids()
order.limit = order.size();
else
// average number of queues per block * in-memory block limit
order.limit = std::max((size_t) 1, order.size() / size() * limit_);
order.limit = (std::max)((size_t) 1, order.size() / size() * limit_);

return order;
}
Expand Down Expand Up @@ -1121,7 +1121,7 @@ send_different_rank(int from, int to, int proc, QueueRecord& qr, bool remote, IE
{
detail::VectorWindow<char> window;
window.begin = &buffer->buffer[msg_buff_idx];
window.count = std::min(MAX_MPI_MESSAGE_COUNT, buffer->size() - msg_buff_idx);
window.count = (std::min)(MAX_MPI_MESSAGE_COUNT, buffer->size() - msg_buff_idx);

inflight_sends().emplace_back();
auto& inflight_send = inflight_sends().back();
Expand Down
4 changes: 2 additions & 2 deletions include/diy/mpi/operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ namespace mpi
};

template<class U>
struct maximum { const U& operator()(const U& x, const U& y) const { return std::max(x,y); } };
struct maximum { const U& operator()(const U& x, const U& y) const { return (std::max)(x,y); } };
template<class U>
struct minimum { const U& operator()(const U& x, const U& y) const { return std::min(x,y); } };
struct minimum { const U& operator()(const U& x, const U& y) const { return (std::min)(x,y); } };
//!@}

namespace detail
Expand Down
12 changes: 6 additions & 6 deletions tests/backward/backward.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ class StackTraceImpl<system_tag::current_tag> : public StackTraceImplHolder {
}
}

_stacktrace.resize(std::min(_stacktrace.size(), skip_n_firsts() + depth));
_stacktrace.resize((std::min)(_stacktrace.size(), skip_n_firsts() + depth));
return size();
}

Expand Down Expand Up @@ -1073,7 +1073,7 @@ class StackTraceImpl<system_tag::current_tag> : public StackTraceImplHolder {
}
}

_stacktrace.resize(std::min(_stacktrace.size(), skip_n_firsts() + depth));
_stacktrace.resize((std::min)(_stacktrace.size(), skip_n_firsts() + depth));
return size();
}
};
Expand Down Expand Up @@ -1111,7 +1111,7 @@ class StackTraceImpl<system_tag::current_tag> : public StackTraceImplHolder {
}
}

_stacktrace.resize(std::min(_stacktrace.size(), skip_n_firsts() + depth));
_stacktrace.resize((std::min)(_stacktrace.size(), skip_n_firsts() + depth));
return size();
}
};
Expand Down Expand Up @@ -1204,7 +1204,7 @@ class StackTraceImpl<system_tag::current_tag> : public StackTraceImplHolder {
}
}

_stacktrace.resize(std::min(_stacktrace.size(), skip_n_firsts() + depth));
_stacktrace.resize((std::min)(_stacktrace.size(), skip_n_firsts() + depth));
return size();
}

Expand Down Expand Up @@ -3857,8 +3857,8 @@ class SnippetFactory {

using std::max;
using std::min;
unsigned a = min(line_a, line_b);
unsigned b = max(line_a, line_b);
unsigned a = (min)(line_a, line_b);
unsigned b = (max)(line_a, line_b);

if ((b - a) < (context_size / 3)) {
return src_file.get_lines((a + b - context_size + 1) / 2, context_size);
Expand Down
2 changes: 1 addition & 1 deletion tests/blobs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ int main(int argc, char* argv[])

Catch::Session session;

BlobsFixture::nblocks = std::max(world.size(), 2);
BlobsFixture::nblocks = (std::max)(world.size(), 2);
bool help;

std::string log_level = "info";
Expand Down
4 changes: 2 additions & 2 deletions tests/catch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7306,7 +7306,7 @@ namespace Catch {
template <typename Clock>
ExecutionPlan<FloatDuration<Clock>> prepare(const IConfig &cfg, Environment<FloatDuration<Clock>> env) const {
auto min_time = env.clock_resolution.mean * Detail::minimum_ticks;
auto run_time = std::max(min_time, std::chrono::duration_cast<decltype(min_time)>(cfg.benchmarkWarmupTime()));
auto run_time = (std::max)(min_time, std::chrono::duration_cast<decltype(min_time)>(cfg.benchmarkWarmupTime()));
auto&& test = Detail::run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(run_time), 1, fun);
int new_iters = static_cast<int>(std::ceil(min_time * test.iterations / test.elapsed));
return { new_iters, test.elapsed / test.iterations * new_iters * cfg.benchmarkSamples(), fun, std::chrono::duration_cast<FloatDuration<Clock>>(cfg.benchmarkWarmupTime()), Detail::warmup_iterations };
Expand Down Expand Up @@ -10923,7 +10923,7 @@ namespace Catch {
FatalConditionHandler::FatalConditionHandler() {
assert(!altStackMem && "Cannot initialize POSIX signal handler when one already exists");
if (altStackSize == 0) {
altStackSize = std::max(static_cast<size_t>(SIGSTKSZ), minStackSizeForErrors);
altStackSize = (std::max)(static_cast<size_t>(SIGSTKSZ), minStackSizeForErrors);
}
altStackMem = new char[altStackSize]();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ int main(int argc, char* argv[])

Catch::Session session;

SimpleFixture::nblocks = std::max(world.size(), 2);
SimpleFixture::nblocks = (std::max)(world.size(), 2);
bool help;

std::string log_level = "info";
Expand Down

0 comments on commit 7cda7ee

Please sign in to comment.