ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ArangeCPU.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
12 
13 namespace cloudViewer {
14 namespace core {
15 namespace kernel {
16 
17 void ArangeCPU(const Tensor& start,
18  const Tensor& stop,
19  const Tensor& step,
20  Tensor& dst) {
21  Dtype dtype = start.GetDtype();
22  DISPATCH_DTYPE_TO_TEMPLATE(dtype, [&]() {
23  scalar_t sstart = start.Item<scalar_t>();
24  scalar_t sstep = step.Item<scalar_t>();
25  scalar_t* dst_ptr = dst.GetDataPtr<scalar_t>();
26  int64_t n = dst.GetLength();
27  ParallelFor(start.GetDevice(), n, [&](int64_t workload_idx) {
28  dst_ptr[workload_idx] =
29  sstart + static_cast<scalar_t>(sstep * workload_idx);
30  });
31  });
32 }
33 
34 } // namespace kernel
35 } // namespace core
36 } // namespace cloudViewer
#define DISPATCH_DTYPE_TO_TEMPLATE(DTYPE,...)
Definition: Dispatch.h:31
int64_t GetLength() const
Definition: Tensor.h:1125
Dtype GetDtype() const
Definition: Tensor.h:1164
Device GetDevice() const override
Definition: Tensor.cpp:1435
void ArangeCPU(const Tensor &start, const Tensor &stop, const Tensor &step, Tensor &dst)
Definition: ArangeCPU.cpp:17
void ParallelFor(const Device &device, int64_t n, const func_t &func)
Definition: ParallelFor.h:111
Generic file read and write utility for python interface.