mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[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:
@ -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(
|
DynamicType::Arguments::Arguments(
|
||||||
const std::vector<c10::string_view>& names,
|
const std::vector<c10::string_view>& names,
|
||||||
c10::ArrayRef<TypePtr> args)
|
c10::ArrayRef<TypePtr> args)
|
||||||
@ -105,7 +115,7 @@ DynamicTypePtr DynamicType::create(Type& other) {
|
|||||||
DynamicType::DynamicType(Tag tag, Arguments arguments)
|
DynamicType::DynamicType(Tag tag, Arguments arguments)
|
||||||
: SharedType(Kind), tag_(tag), arguments_(std::move(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),
|
: SharedType(Kind),
|
||||||
tag_(tag),
|
tag_(tag),
|
||||||
name_(std::string{name}),
|
name_(std::string{name}),
|
||||||
|
|||||||
@ -139,6 +139,7 @@ class DynamicType : public SharedType {
|
|||||||
Arguments() = default;
|
Arguments() = default;
|
||||||
Arguments(c10::ArrayRef<TypePtr>);
|
Arguments(c10::ArrayRef<TypePtr>);
|
||||||
Arguments(const std::vector<c10::string_view>&, 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;
|
std::vector<LabeledDynamicType> elems;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -156,7 +157,7 @@ class DynamicType : public SharedType {
|
|||||||
static TORCH_API DynamicTypePtr create(Type& ty);
|
static TORCH_API DynamicTypePtr create(Type& ty);
|
||||||
|
|
||||||
explicit DynamicType(Tag, Arguments);
|
explicit DynamicType(Tag, Arguments);
|
||||||
explicit DynamicType(Tag, c10::string_view, Arguments);
|
explicit DynamicType(Tag, std::string_view, Arguments);
|
||||||
|
|
||||||
DynamicType(DynamicType&& other) = delete;
|
DynamicType(DynamicType&& other) = delete;
|
||||||
DynamicType(const DynamicType&) = delete;
|
DynamicType(const DynamicType&) = delete;
|
||||||
|
|||||||
@ -1961,6 +1961,12 @@ struct getTypePtr_<c10::string_view> final {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
template <>
|
template <>
|
||||||
|
struct getTypePtr_<std::string_view> final {
|
||||||
|
static decltype(auto) call() {
|
||||||
|
return StringType::get();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template <>
|
||||||
struct getTypePtr_<at::Dimname> final {
|
struct getTypePtr_<at::Dimname> final {
|
||||||
static decltype(auto) call() {
|
static decltype(auto) call() {
|
||||||
return StringType::get();
|
return StringType::get();
|
||||||
|
|||||||
@ -43,7 +43,7 @@ const std::unordered_map<std::string, c10::TypePtr>& DynamicTypeFactory::
|
|||||||
static const std::unordered_map<std::string, c10::TypePtr> map = {
|
static const std::unordered_map<std::string, c10::TypePtr> map = {
|
||||||
#define MAP_ITEM(NAME, TYPE) \
|
#define MAP_ITEM(NAME, TYPE) \
|
||||||
{#NAME, c10::DynamicTypeTrait<c10::TYPE>::getBaseType()},
|
{#NAME, c10::DynamicTypeTrait<c10::TYPE>::getBaseType()},
|
||||||
FORALL_BASE_PYTHON_TYPES(MAP_ITEM)
|
FORALL_BASE_PYTHON_TYPES(MAP_ITEM)
|
||||||
#undef MAP_ITEM
|
#undef MAP_ITEM
|
||||||
};
|
};
|
||||||
return map;
|
return map;
|
||||||
|
|||||||
@ -1903,7 +1903,7 @@ REGISTER_OPERATOR_FUNCTOR(aten::div, aten_div, [](Node* n) -> SROperator {
|
|||||||
|
|
||||||
return [te = createDiv()](ProcessedNode* p_node) {
|
return [te = createDiv()](ProcessedNode* p_node) {
|
||||||
const auto& in0_t = p_node->Input(0).toTensor();
|
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) {
|
if (p_node->num_inputs() > 2) {
|
||||||
rounding_mode = p_node->Input(2).toOptional<c10::string_view>();
|
rounding_mode = p_node->Input(2).toOptional<c10::string_view>();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -67,7 +67,7 @@ static std::vector<Method> findAllDependentFunctions(
|
|||||||
const Module& module,
|
const Module& module,
|
||||||
Graph& graph) {
|
Graph& graph) {
|
||||||
std::vector<Method> methods;
|
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);
|
auto nodes = findAllNodes(graph, c10::prim::CallMethod, true);
|
||||||
for (Node* node : nodes) {
|
for (Node* node : nodes) {
|
||||||
if (auto iface = node->input(0)->type()->castRaw<InterfaceType>()) {
|
if (auto iface = node->input(0)->type()->castRaw<InterfaceType>()) {
|
||||||
|
|||||||
@ -43,7 +43,7 @@ class SourceRangeSerializer {
|
|||||||
int64_t store_text_and_get_index(const std::string& text_view);
|
int64_t store_text_and_get_index(const std::string& text_view);
|
||||||
|
|
||||||
std::vector<c10::IValue> texts_;
|
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) {
|
SourceRange SourceRangeDeserializer::deserialize(const c10::IValue& iv) {
|
||||||
|
|||||||
Reference in New Issue
Block a user