#pragma once #include #include namespace c10 { template inline void FunctionSchema::checkArg( const IValue& value, const Argument& argument, std::optional pos) const { if (value.isTensor() && argument.type() == TensorType::get()) { // Fast-path for the common case return; } if (value.isGenericDict() && value.toGenericDict().empty()) { return; } if (!value.type()->isSubtypeOf(*argument.type())) { TORCH_CHECK( false, formatTypeMismatchMsg( argument, value.type()->repr_str(), pos)); } } template inline void FunctionSchema::checkAndNormalizeInputs( std::vector& inputs, const std::unordered_map& kwargs) const { // Do we have more inputs than the schema accepts? TORCH_CHECK( inputs.size() <= arguments().size(), "Expected at most ", arguments().size(), " argument(s) for operator '", name(), "', but received ", inputs.size(), " argument(s). Declaration: ", *this); size_t consumed_kwargs = 0; for (const auto pos : c10::irange(arguments().size())) { const auto& argument = arguments()[pos]; if (pos < inputs.size()) { checkArg(inputs[pos], argument, pos); continue; } auto it = kwargs.find(argument.name()); if (it != kwargs.end()) { checkArg(it->second, argument, std::nullopt); inputs.push_back(it->second); consumed_kwargs++; continue; } if (argument.default_value()) { inputs.push_back(*argument.default_value()); continue; } TORCH_CHECK(false, name(), "() is missing value for argument '", argument.name(), "'. Declaration: ", *this); } if (consumed_kwargs != kwargs.size()) { std::vector names; names.reserve(kwargs.size()); for(const auto& k : kwargs) { names.emplace_back(k.first); } TORCH_CHECK(false, findErrorInKwargs(names)); } } } // namespace c10