11 #include <oneapi/dpl/algorithm>
12 #include <oneapi/dpl/execution>
29 int64_t *non_zero_indices_ptr = non_zero_indices.
GetDataPtr<int64_t>(),
33 auto it = std::copy_if(
34 oneapi::dpl::execution::dpcpp_default, indices_ptr,
35 indices_ptr + num_elements, non_zero_indices_ptr,
36 [src_iter](int64_t index) {
37 auto src_ptr = static_cast<const scalar_t*>(
38 src_iter.GetPtr(index));
39 CLOUDVIEWER_ASSERT(src_ptr != nullptr &&
"Internal error.");
42 num_non_zeros = std::distance(non_zero_indices_ptr, it);
46 const auto num_dims = src.NumDims();
50 sycl::marray<int64_t, MAX_DIMS> shape_vec;
55 for (
auto k = 0; k < num_dims; ++k) shape_vec[k] = shape[k];
56 Tensor
result({num_dims,
static_cast<int64_t
>(num_non_zeros)},
Int64,
58 int64_t* result_ptr =
result.GetDataPtr<int64_t>();
61 queue.parallel_for(num_non_zeros, [=](int64_t i) {
62 auto non_zero_index = non_zero_indices_ptr[i];
63 auto this_result_ptr =
64 result_ptr + i + (num_dims - 1) * num_non_zeros;
67 for (
auto dim = num_dims - 1; dim >= 0;
68 dim--, this_result_ptr -= num_non_zeros) {
69 *this_result_ptr = non_zero_index % shape_vec[dim];
70 non_zero_index = non_zero_index / shape_vec[dim];
#define DISPATCH_DTYPE_TO_TEMPLATE_WITH_BOOL(DTYPE,...)
#define CLOUDVIEWER_ASSERT(...)
static Tensor Arange(const Scalar start, const Scalar stop, const Scalar step=1, const Dtype dtype=core::Int64, const Device &device=core::Device("CPU:0"))
Create a 1D tensor with evenly spaced values in the given interval.
int64_t NumElements() const
Device GetDevice() const override
static SYCLContext & GetInstance()
Get singleton instance.
sycl::queue GetDefaultQueue(const Device &device)
Get the default SYCL queue given an CloudViewer device.
Tensor NonZeroSYCL(const Tensor &src)
static constexpr int64_t MAX_DIMS
Generic file read and write utility for python interface.