2022-09-14 08:54:04 -05:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
|
|
2022-09-13 11:36:14 -05:00
|
|
|
#include "BLI_array_utils.hh"
|
|
|
|
|
|
|
|
|
|
namespace blender::array_utils {
|
|
|
|
|
|
|
|
|
|
void copy(const GVArray &src,
|
|
|
|
|
const IndexMask selection,
|
|
|
|
|
GMutableSpan dst,
|
|
|
|
|
const int64_t grain_size)
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(src.type() == dst.type());
|
2023-01-17 13:11:56 +01:00
|
|
|
BLI_assert(src.size() >= selection.min_array_size());
|
|
|
|
|
BLI_assert(dst.size() >= selection.min_array_size());
|
2022-09-13 11:36:14 -05:00
|
|
|
threading::parallel_for(selection.index_range(), grain_size, [&](const IndexRange range) {
|
|
|
|
|
src.materialize_to_uninitialized(selection.slice(range), dst.data());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-17 22:12:02 -05:00
|
|
|
void gather(const GVArray &src,
|
|
|
|
|
const IndexMask indices,
|
|
|
|
|
GMutableSpan dst,
|
|
|
|
|
const int64_t grain_size)
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(src.type() == dst.type());
|
|
|
|
|
BLI_assert(indices.size() == dst.size());
|
|
|
|
|
threading::parallel_for(indices.index_range(), grain_size, [&](const IndexRange range) {
|
|
|
|
|
src.materialize_compressed_to_uninitialized(indices.slice(range), dst.slice(range).data());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-19 12:38:48 -05:00
|
|
|
void gather(const GSpan src, const IndexMask indices, GMutableSpan dst, const int64_t grain_size)
|
|
|
|
|
{
|
|
|
|
|
gather(GVArray::ForSpan(src), indices, dst, grain_size);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-03 22:59:25 -05:00
|
|
|
void invert_booleans(MutableSpan<bool> span)
|
|
|
|
|
{
|
|
|
|
|
threading::parallel_for(span.index_range(), 4096, [&](IndexRange range) {
|
|
|
|
|
for (const int i : range) {
|
|
|
|
|
span[i] = !span[i];
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-13 11:36:14 -05:00
|
|
|
} // namespace blender::array_utils
|