Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a linspace-like function in AMReX_Algorithm.H #3698

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Src/Base/AMReX_Algorithm.H
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,24 @@ namespace amrex
#endif
}

template<typename ItType, typename ValType,
typename std::enable_if<
std::is_floating_point<typename std::iterator_traits<ItType>::value_type>::value &&
std::is_floating_point<ValType>::value,
int>::type = 0>
AMREX_GPU_HOST_DEVICE
void linspace (ItType first, const ItType& last, const ValType& start, const ValType& stop)
{
const std::ptrdiff_t count = last-first;
if (count >= 2){
const auto delta = (stop - start)/(count - 1);
for (std::ptrdiff_t i = 0; i < count-1; ++i){
*(first++) = start + i*delta;
}
*first = stop;
}
}

namespace detail {

struct clzll_tag {};
Expand Down
Loading