ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
Dispatch.h File Reference
#include <Logging.h>
#include "cloudViewer/core/Dtype.h"
Include dependency graph for Dispatch.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define DISPATCH_DTYPE_TO_TEMPLATE(DTYPE, ...)
 
#define DISPATCH_DTYPE_TO_TEMPLATE_WITH_BOOL(DTYPE, ...)
 
#define DISPATCH_FLOAT_DTYPE_TO_TEMPLATE(DTYPE, ...)
 
#define DISPATCH_FLOAT_INT_DTYPE_TO_TEMPLATE(FDTYPE, IDTYPE, ...)
 
#define DISPATCH_INT_DTYPE_PREFIX_TO_TEMPLATE(DTYPE, PREFIX, ...)
 

Macro Definition Documentation

◆ DISPATCH_DTYPE_TO_TEMPLATE

#define DISPATCH_DTYPE_TO_TEMPLATE (   DTYPE,
  ... 
)

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

Before: if (dtype == core::Float32) { func<float>(args); } else if (dtype == core::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

Definition at line 31 of file Dispatch.h.

◆ DISPATCH_DTYPE_TO_TEMPLATE_WITH_BOOL

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

Definition at line 68 of file Dispatch.h.

◆ DISPATCH_FLOAT_DTYPE_TO_TEMPLATE

#define DISPATCH_FLOAT_DTYPE_TO_TEMPLATE (   DTYPE,
  ... 
)
Value:
[&] { \
if (DTYPE == cloudViewer::core::Float32) { \
using scalar_t = float; \
return __VA_ARGS__(); \
} else if (DTYPE == cloudViewer::core::Float64) { \
using scalar_t = double; \
return __VA_ARGS__(); \
} else { \
cloudViewer::utility::LogError("Unsupported data type."); \
} \
}()
#define LogError(...)
Definition: Logging.h:60
const Dtype Float64
Definition: Dtype.cpp:43
const Dtype Float32
Definition: Dtype.cpp:42

Definition at line 78 of file Dispatch.h.

◆ DISPATCH_FLOAT_INT_DTYPE_TO_TEMPLATE

#define DISPATCH_FLOAT_INT_DTYPE_TO_TEMPLATE (   FDTYPE,
  IDTYPE,
  ... 
)
Value:
[&] { \
if (FDTYPE == cloudViewer::core::Float32 && \
IDTYPE == cloudViewer::core::Int32) { \
using scalar_t = float; \
using int_t = int32_t; \
return __VA_ARGS__(); \
} else if (FDTYPE == cloudViewer::core::Float32 && \
IDTYPE == cloudViewer::core::Int64) { \
using scalar_t = float; \
using int_t = int64_t; \
return __VA_ARGS__(); \
} else if (FDTYPE == cloudViewer::core::Float64 && \
IDTYPE == cloudViewer::core::Int32) { \
using scalar_t = double; \
using int_t = int32_t; \
return __VA_ARGS__(); \
} else if (FDTYPE == cloudViewer::core::Float64 && \
IDTYPE == cloudViewer::core::Int64) { \
using scalar_t = double; \
using int_t = int64_t; \
return __VA_ARGS__(); \
} else { \
cloudViewer::utility::LogError("Unsupported data type."); \
} \
}()
const Dtype Int64
Definition: Dtype.cpp:47
const Dtype Int32
Definition: Dtype.cpp:46

Definition at line 91 of file Dispatch.h.

◆ DISPATCH_INT_DTYPE_PREFIX_TO_TEMPLATE

#define DISPATCH_INT_DTYPE_PREFIX_TO_TEMPLATE (   DTYPE,
  PREFIX,
  ... 
)
Value:
[&] { \
if (DTYPE == cloudViewer::core::Int8) { \
using scalar_##PREFIX##_t = int8_t; \
return __VA_ARGS__(); \
} else if (DTYPE == cloudViewer::core::Int16) { \
using scalar_##PREFIX##_t = int16_t; \
return __VA_ARGS__(); \
} else if (DTYPE == cloudViewer::core::Int32) { \
using scalar_##PREFIX##_t = int32_t; \
return __VA_ARGS__(); \
} else if (DTYPE == cloudViewer::core::Int64) { \
using scalar_##PREFIX##_t = int64_t; \
return __VA_ARGS__(); \
} else if (DTYPE == cloudViewer::core::UInt8) { \
using scalar_##PREFIX##_t = uint8_t; \
return __VA_ARGS__(); \
} else if (DTYPE == cloudViewer::core::UInt16) { \
using scalar_##PREFIX##_t = uint16_t; \
return __VA_ARGS__(); \
} else if (DTYPE == cloudViewer::core::UInt32) { \
using scalar_##PREFIX##_t = uint32_t; \
return __VA_ARGS__(); \
} else if (DTYPE == cloudViewer::core::UInt64) { \
using scalar_##PREFIX##_t = uint64_t; \
return __VA_ARGS__(); \
} else { \
cloudViewer::utility::LogError("Unsupported data type."); \
} \
}()
const Dtype Int8
Definition: Dtype.cpp:44
const Dtype UInt64
Definition: Dtype.cpp:51
const Dtype UInt32
Definition: Dtype.cpp:50
const Dtype UInt8
Definition: Dtype.cpp:48
const Dtype Int16
Definition: Dtype.cpp:45
const Dtype UInt16
Definition: Dtype.cpp:49

Definition at line 118 of file Dispatch.h.