[2/N] Replace c10::sv with std::sv (#139456)

Follows  #139453

Pull Request resolved: https://github.com/pytorch/pytorch/pull/139456
Approved by: https://github.com/ezyang, https://github.com/malfet
This commit is contained in:
cyy
2024-11-08 01:48:00 +00:00
committed by PyTorch MergeBot
parent 81d077cca2
commit da1e120dfd
7 changed files with 23 additions and 6 deletions

View File

@ -59,6 +59,16 @@ DynamicType::Arguments::Arguments(c10::ArrayRef<TypePtr> args) {
}
}
DynamicType::Arguments::Arguments(
const std::vector<std::string_view>& names,
c10::ArrayRef<TypePtr> args)
: Arguments(args) {
TORCH_INTERNAL_ASSERT(names.size() == args.size());
for (size_t i = 0; i < args.size(); i++) {
elems[i].label = std::string{names[i]};
}
}
DynamicType::Arguments::Arguments(
const std::vector<c10::string_view>& names,
c10::ArrayRef<TypePtr> args)
@ -105,7 +115,7 @@ DynamicTypePtr DynamicType::create(Type& other) {
DynamicType::DynamicType(Tag tag, Arguments arguments)
: SharedType(Kind), tag_(tag), arguments_(std::move(arguments)) {}
DynamicType::DynamicType(Tag tag, c10::string_view name, Arguments arguments)
DynamicType::DynamicType(Tag tag, std::string_view name, Arguments arguments)
: SharedType(Kind),
tag_(tag),
name_(std::string{name}),

View File

@ -139,6 +139,7 @@ class DynamicType : public SharedType {
Arguments() = default;
Arguments(c10::ArrayRef<TypePtr>);
Arguments(const std::vector<c10::string_view>&, c10::ArrayRef<TypePtr>);
Arguments(const std::vector<std::string_view>&, c10::ArrayRef<TypePtr>);
std::vector<LabeledDynamicType> elems;
};
@ -156,7 +157,7 @@ class DynamicType : public SharedType {
static TORCH_API DynamicTypePtr create(Type& ty);
explicit DynamicType(Tag, Arguments);
explicit DynamicType(Tag, c10::string_view, Arguments);
explicit DynamicType(Tag, std::string_view, Arguments);
DynamicType(DynamicType&& other) = delete;
DynamicType(const DynamicType&) = delete;

View File

@ -1961,6 +1961,12 @@ struct getTypePtr_<c10::string_view> final {
}
};
template <>
struct getTypePtr_<std::string_view> final {
static decltype(auto) call() {
return StringType::get();
}
};
template <>
struct getTypePtr_<at::Dimname> final {
static decltype(auto) call() {
return StringType::get();

View File

@ -1903,7 +1903,7 @@ REGISTER_OPERATOR_FUNCTOR(aten::div, aten_div, [](Node* n) -> SROperator {
return [te = createDiv()](ProcessedNode* p_node) {
const auto& in0_t = p_node->Input(0).toTensor();
std::optional<c10::string_view> rounding_mode = std::nullopt;
std::optional<std::string_view> rounding_mode = std::nullopt;
if (p_node->num_inputs() > 2) {
rounding_mode = p_node->Input(2).toOptional<c10::string_view>();
}

View File

@ -67,7 +67,7 @@ static std::vector<Method> findAllDependentFunctions(
const Module& module,
Graph& graph) {
std::vector<Method> methods;
std::unordered_set<c10::string_view> called_method_names;
std::unordered_set<std::string_view> called_method_names;
auto nodes = findAllNodes(graph, c10::prim::CallMethod, true);
for (Node* node : nodes) {
if (auto iface = node->input(0)->type()->castRaw<InterfaceType>()) {

View File

@ -43,7 +43,7 @@ class SourceRangeSerializer {
int64_t store_text_and_get_index(const std::string& text_view);
std::vector<c10::IValue> texts_;
std::unordered_map<c10::string_view, int64_t> text_to_idx_;
std::unordered_map<std::string_view, int64_t> text_to_idx_;
};
SourceRange SourceRangeDeserializer::deserialize(const c10::IValue& iv) {