19 #include "fastdeploy/core/fd_type.h" 20 #include "fastdeploy/core/float16.h" 27 Scalar() : Scalar(0) {}
28 Scalar(
double val) : dtype_(FDDataType::FP64) {
32 Scalar(
float val) : dtype_(FDDataType::FP32) {
36 Scalar(float16 val) : dtype_(FDDataType::FP16) {
40 Scalar(int64_t val) : dtype_(FDDataType::INT64) {
44 Scalar(int32_t val) : dtype_(FDDataType::INT32) {
48 Scalar(int16_t val) : dtype_(FDDataType::INT16) {
52 Scalar(int8_t val) : dtype_(FDDataType::INT8) {
56 Scalar(uint8_t val) : dtype_(FDDataType::UINT8) {
60 Scalar(
bool val) : dtype_(FDDataType::BOOL) {
66 explicit Scalar(
const std::string& str_value) : dtype_(FDDataType::FP64) {
67 if (str_value ==
"inf") {
68 data_.f64 = std::numeric_limits<double>::infinity();
69 }
else if (str_value ==
"-inf") {
70 data_.f64 = -std::numeric_limits<double>::infinity();
71 }
else if (str_value ==
"nan") {
72 data_.f64 = std::numeric_limits<double>::quiet_NaN();
74 data_.f64 = std::stod(str_value);
78 template <
typename RT>
inline RT to()
const {
80 case FDDataType::FP32:
81 return static_cast<RT
>(data_.f32);
82 case FDDataType::FP64:
83 return static_cast<RT
>(data_.f64);
84 case FDDataType::FP16:
85 return static_cast<RT
>(data_.f16);
86 case FDDataType::INT32:
87 return static_cast<RT
>(data_.i32);
88 case FDDataType::INT64:
89 return static_cast<RT
>(data_.i64);
90 case FDDataType::INT16:
91 return static_cast<RT
>(data_.i16);
92 case FDDataType::INT8:
93 return static_cast<RT
>(data_.i8);
94 case FDDataType::UINT8:
95 return static_cast<RT
>(data_.ui8);
96 case FDDataType::BOOL:
97 return static_cast<RT
>(data_.b);
99 FDASSERT(
false,
"Invalid enum scalar data type `%s`.",
100 Str(dtype_).c_str());
104 FDDataType dtype()
const {
return dtype_; }
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16