Open3D (C++ API)  0.12.0
Macros
Dispatch.h File Reference

(313315d (Wed Dec 23 23:39:47 2020 -0800))

#include "open3d/core/Dtype.h"
#include "open3d/utility/Console.h"

Go to the source code of this file.

Macros

#define DISPATCH_DTYPE_TO_TEMPLATE(DTYPE, ...)
 
#define DISPATCH_DTYPE_TO_TEMPLATE_WITH_BOOL(DTYPE, ...)
 

Macro Definition Documentation

◆ DISPATCH_DTYPE_TO_TEMPLATE

#define DISPATCH_DTYPE_TO_TEMPLATE (   DTYPE,
  ... 
)
Value:
[&] { \
if (DTYPE == open3d::core::Dtype::Float32) { \
using scalar_t = float; \
return __VA_ARGS__(); \
} else if (DTYPE == open3d::core::Dtype::Float64) { \
using scalar_t = double; \
return __VA_ARGS__(); \
} else if (DTYPE == open3d::core::Dtype::Int32) { \
using scalar_t = int32_t; \
return __VA_ARGS__(); \
} else if (DTYPE == open3d::core::Dtype::Int64) { \
using scalar_t = int64_t; \
return __VA_ARGS__(); \
} else if (DTYPE == open3d::core::Dtype::UInt8) { \
using scalar_t = uint8_t; \
return __VA_ARGS__(); \
} else if (DTYPE == open3d::core::Dtype::UInt16) { \
using scalar_t = uint16_t; \
return __VA_ARGS__(); \
} else { \
utility::LogError("Unsupported data type."); \
} \
}()
void LogError(const char *format, const Args &... args)
Definition: Console.h:176
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample playback_handle k4a_logging_message_cb_t void min_level device_handle k4a_imu_sample_t int32_t
Definition: K4aPlugin.cpp:398
static const Dtype UInt8
Definition: Dtype.h:46
static const Dtype Int32
Definition: Dtype.h:44
static const Dtype UInt16
Definition: Dtype.h:47
static const Dtype Float32
Definition: Dtype.h:42
static const Dtype Int64
Definition: Dtype.h:45
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample playback_handle k4a_logging_message_cb_t void min_level device_handle k4a_imu_sample_t timeout_in_ms capture_handle capture_handle capture_handle image_handle float
Definition: K4aPlugin.cpp:465
static const Dtype Float64
Definition: Dtype.h:43

Call a numerical templated funciton based on Dtype. Warp the function to a lambda function to use DISPATCH_DTYPE_TO_TEMPLATE.

Before: if (dtype == Dtype::Float32) { func<float>(args); } else if (dtype == Dtype::Float64) { func<double>(args); } else ...

Now: DISPATCH_DTYPE_TO_TEMPLATE(dtype, [&]() { func<scalar_t>(args); });

Inspired by: https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/Dispatch.h

◆ DISPATCH_DTYPE_TO_TEMPLATE_WITH_BOOL

#define DISPATCH_DTYPE_TO_TEMPLATE_WITH_BOOL (   DTYPE,
  ... 
)
Value:
[&] { \
if (DTYPE == open3d::core::Dtype::Bool) { \
using scalar_t = bool; \
return __VA_ARGS__(); \
} else { \
DISPATCH_DTYPE_TO_TEMPLATE(DTYPE, __VA_ARGS__); \
} \
}()
static const Dtype Bool
Definition: Dtype.h:48