30 return mode.grain_size(std::max<int64_t>(1, 32768 / type_size));
35 return mode.
grain_size(std::max<int64_t>(1, 32768 / type_size));
39template<exec_mode::Tag Mode>
42 if constexpr (mode.is_parallel) {
54template<
typename T, exec_mode::Tag Mode = exec_mode::Parallel>
58 if constexpr (!mode.is_parallel) {
64 src.materialize(range, dst);
72template<
typename T, exec_mode::Tag Mode = exec_mode::Parallel>
76 if constexpr (!mode.is_parallel) {
82 copy(src.slice(range), dst.slice(range), exec_mode::serial);
90void copy(
const GVArray &src,
91 const IndexMask &selection,
98template<
typename T, exec_mode::Tag Mode = exec_mode::Parallel>
102 const Mode mode = {})
118 constexpr int64_t chunk_size = 1024;
122 for (const int64_t i : range) {
123 const int64_t start = i * chunk_size;
124 const Span<T> chunk = data.slice_safe(start, chunk_size);
125 const T partial_sum = std::accumulate(chunk.begin(), chunk.end(), T());
126 partial_sums[i] = partial_sum;
129 return std::accumulate(partial_sums.begin(), partial_sums.end(),
T());
135template<
typename T,
typename IndexT, exec_mode::Tag Mode = exec_mode::Parallel>
139 const Mode mode = {})
142 if constexpr (!mode.is_parallel) {
144 dst[indices[i]] = src[i];
149 threading::parallel_for(indices.
index_range(), grain_size, [&](
const IndexRange range) {
150 scatter(src.slice(range), indices.slice(range), dst, exec_mode::serial);
155template<
typename T, exec_mode::Tag Mode = exec_mode::Parallel>
159 const Mode mode = {})
165 exec_mode_tag_for_copy(mode,
sizeof(
T)));
171void gather(
const GVArray &src,
172 const IndexMask &indices,
174 exec_mode::Mode mode = exec_mode::parallel);
180 const IndexMask &indices,
182 exec_mode::Mode mode = exec_mode::parallel);
187template<
typename T, exec_mode::Tag Mode = exec_mode::Parallel>
191 const Mode mode = {})
195 if constexpr (!mode.is_parallel) {
199 const int64_t grain_size = calc_copy_grain_size(mode,
sizeof(
T));
200 threading::parallel_for(indices.
index_range(), grain_size, [&](
const IndexRange range) {
201 src.materialize_compressed(indices.slice(range), dst.slice(range));
209template<
typename T,
typename IndexT, exec_mode::Tag Mode = exec_mode::Parallel>
214 const Mode mode = {})
219 exec_mode_tag_for_copy(mode,
sizeof(
T)));
225template<
typename T,
typename IndexT, exec_mode::Tag Mode = exec_mode::Parallel>
229 const Mode mode = {})
237template<
typename T,
typename IndexT, exec_mode::Tag Mode = exec_mode::Parallel>
242 const Mode mode = {})
250 exec_mode_tag_for_copy(mode,
sizeof(
T)));
253 case CommonVArrayInfo::Type::Span: {
254 const Span span(
static_cast<const T *
>(info.
data), src.
size());
255 gather(span, indices, dst_mask, dst, mode);
258 case CommonVArrayInfo::Type::Single: {
259 index_mask::masked_fill(dst, *
static_cast<const T *
>(info.
data), dst_mask);
268template<
typename T,
typename IndexT, exec_mode::Tag Mode = exec_mode::Parallel>
272 const Mode mode = {})
274 gather(src, indices, dst.
index_range(), dst, mode);
299 for (const int dst_i : range) {
300 dst.slice(dst_offsets[dst_i]).copy_from(src.slice(src_offsets[selection[dst_i]]));
326 [&](
const int src_i,
const int dst_i) { dst.
slice(dst_offsets[dst_i]).
fill(src[src_i]); },
416 if (span[i - 1] == value && span[i] != value) {
420 else if (span[i] == value) {
436 std::iota(span.
begin(), span.
end(), start);
439template<
typename T, exec_mode::Tag Mode = exec_mode::Parallel>
445template<
typename T, exec_mode::Tag Mode = exec_mode::Parallel>
449 const Mode mode = {})
452 fill_index_range(
mask, span, mode);
464 if (all_values[indices[i]] != values[i]) {
479 const int64_t grain_size = 8192)
486 const Span<T> sub_span = span.slice(range);
487 const T *max_elem = std::max_element(sub_span.begin(), sub_span.end());
488 if (*max_elem < *init_max) {
493 [&](
const T *a,
const T *
b) {
499 return std::distance(span.
begin(), max_it);
503 const int64_t grain_size = 8192)
508 if (
array.is_single()) {
509 return array.first();
511 if (
array.is_span()) {
519 int64_t max_index = init_i;
520 T max_elem = array[max_index];
521 for (const int i : range) {
522 if (max_elem < array[i]) {
#define PRF_scope_with_name(ui_name, category)
IndexRange index_range() const
static constexpr IndexRange from_end_size(const int64_t end, const int64_t size)
constexpr IndexRange drop_front(int64_t n) const
constexpr int64_t size() const
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
constexpr void fill(const T &value) const
constexpr T * end() const
constexpr T * begin() const
constexpr IndexRange index_range() const
constexpr void copy_from(Span< T > values) const
constexpr Span slice(int64_t start, int64_t size) const
constexpr const T & first() const
constexpr int64_t size() const
constexpr IndexRange index_range() const
constexpr const T * begin() const
constexpr bool is_empty() const
IndexRange index_range() const
void materialize_compressed(const IndexMask &mask, MutableSpan< T > r_span) const
CommonVArrayInfo common_info() const
void append(const T &value)
void foreach_index_optimized(Fn &&fn, Mode mode=exec_mode::serial) const
int64_t min_array_size() const
IndexRange index_range() const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
float length(VecOp< float, D >) RET
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
void gather(const GVArray &src, const IndexMask &indices, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
void gather_to_groups(const OffsetIndices< int > dst_offsets, const IndexMask &src_selection, const Span< T > src, MutableSpan< T > dst)
T compute_sum(const Span< T > data)
void copy_group_to_group(OffsetIndices< int > src_offsets, OffsetIndices< int > dst_offsets, const IndexMask &selection, GSpan src, GMutableSpan dst)
Vector< IndexRange > find_all_ranges(const Span< T > span, const T &value)
void scatter(const Span< T > src, const Span< IndexT > indices, MutableSpan< T > dst, const Mode mode={})
void gather_group_to_group(const OffsetIndices< int > src_offsets, const OffsetIndices< int > dst_offsets, const IndexMask &selection, const Span< T > src, MutableSpan< T > dst)
void copy(const GVArray &src, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
std::optional< int64_t > max_element_index(const Span< T > &span, const int64_t grain_size=8192)
bool indexed_data_equal(const Span< T > all_values, const Span< int > indices, const Span< T > values)
constexpr auto exec_mode_tag_for_copy(const Mode mode, const int64_t type_size)
BooleanMix booleans_mix_calc(const VArray< bool > &varray, IndexRange range_to_check)
void fill_index_range(MutableSpan< T > span, const T start=0)
constexpr int64_t calc_copy_grain_size(const exec_mode::Tag auto mode, const int64_t type_size)
void gather(GSpan src, Span< int > map, GMutableSpan dst)
constexpr ParallelGrainSize grain_size(int grain_size)
constexpr Parallel parallel
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Value parallel_reduce(IndexRange range, int64_t grain_size, const Value &identity, const Function &function, const Reduction &reduction)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MINLINE uint64_t divide_ceil_ul(uint64_t a, uint64_t b)
BMesh const char void * data
constexpr int grain_size(const int fallback) const