@@ -131,9 +131,7 @@ FunctionParameter::FunctionParameter(const std::string& fmt, bool keyword_only)
131
131
size(0 ),
132
132
default_scalar(0 ) {
133
133
auto space = fmt.find (' ' );
134
- if (space == std::string::npos) {
135
- TORCH_CHECK (false , " FunctionParameter(): missing type: " + fmt);
136
- }
134
+ TORCH_CHECK (space != std::string::npos, " FunctionParameter(): missing type: " + fmt);
137
135
138
136
auto type_str = fmt.substr (0 , space);
139
137
@@ -154,9 +152,7 @@ FunctionParameter::FunctionParameter(const std::string& fmt, bool keyword_only)
154
152
155
153
auto name_str = fmt.substr (space + 1 );
156
154
auto it = type_map.find (type_str);
157
- if (it == type_map.end ()) {
158
- TORCH_CHECK (false , " FunctionParameter(): invalid type string: " + type_str);
159
- }
155
+ TORCH_CHECK (it != type_map.end (), " FunctionParameter(): invalid type string: " + type_str);
160
156
type_ = it->second ;
161
157
162
158
auto eq = name_str.find (' =' );
@@ -1226,9 +1222,7 @@ void FunctionParameter::set_default_str(const std::string& str) {
1226
1222
}
1227
1223
if (type_ == ParameterType::TENSOR ||
1228
1224
type_ == ParameterType::DISPATCH_KEY_SET) {
1229
- if (str != " None" ) {
1230
- TORCH_CHECK (false , " default value for Tensor must be none, got: " + str);
1231
- }
1225
+ TORCH_CHECK (str == " None" , " default value for Tensor must be none, got: " + str);
1232
1226
} else if (type_ == ParameterType::INT64 || type_ == ParameterType::SYM_INT) {
1233
1227
default_int = atol (str.c_str ());
1234
1228
} else if (type_ == ParameterType::BOOL) {
@@ -1252,9 +1246,7 @@ void FunctionParameter::set_default_str(const std::string& str) {
1252
1246
default_intlist = parse_intlist_args (str, size);
1253
1247
}
1254
1248
} else if (type_ == ParameterType::FLOAT_LIST) {
1255
- if (str != " None" ) {
1256
- TORCH_CHECK (false , " Defaults not supported for float[]" );
1257
- }
1249
+ TORCH_CHECK (str == " None" , " Defaults not supported for float[]" );
1258
1250
} else if (type_ == ParameterType::SCALARTYPE) {
1259
1251
if (str == " None" ) {
1260
1252
default_scalartype = at::ScalarType::Undefined;
@@ -1274,13 +1266,9 @@ void FunctionParameter::set_default_str(const std::string& str) {
1274
1266
TORCH_CHECK (false , " invalid default value for layout: " + str);
1275
1267
}
1276
1268
} else if (type_ == ParameterType::DEVICE) {
1277
- if (str != " None" ) {
1278
- TORCH_CHECK (false , " invalid device: " + str);
1279
- }
1269
+ TORCH_CHECK (str == " None" , " invalid device: " + str);
1280
1270
} else if (type_ == ParameterType::STREAM) {
1281
- if (str != " None" ) {
1282
- TORCH_CHECK (false , " invalid stream: " + str);
1283
- }
1271
+ TORCH_CHECK (str == " None" , " invalid stream: " + str);
1284
1272
} else if (type_ == ParameterType::STRING) {
1285
1273
if (str != " None" ) {
1286
1274
default_string = parse_string_literal (str);
@@ -1346,12 +1334,8 @@ FunctionSignature::FunctionSignature(const std::string& fmt, int index)
1346
1334
break ;
1347
1335
}
1348
1336
}
1349
- if (offset == std::string::npos) {
1350
- TORCH_CHECK (false , " missing closing parenthesis: " + fmt);
1351
- }
1352
- if (offset == last_offset) {
1353
- TORCH_CHECK (false , " malformed signature: " + fmt);
1354
- }
1337
+ TORCH_CHECK (offset != std::string::npos, " missing closing parenthesis: " + fmt);
1338
+ TORCH_CHECK (offset != last_offset, " malformed signature: " + fmt);
1355
1339
1356
1340
auto param_str = fmt.substr (last_offset, offset - last_offset);
1357
1341
last_offset = next_offset;
0 commit comments