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
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(
|
||||
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}),
|
||||
@ -258,7 +268,7 @@ TypePtr DynamicType::fallback() const {
|
||||
fallbacks.push_back(elem.ty->fallback());
|
||||
}
|
||||
if (name_) {
|
||||
std::vector<c10::string_view> fields;
|
||||
std::vector<std::string_view> fields;
|
||||
fields.reserve(arguments_.elems.size());
|
||||
for (const auto& elem : arguments_.elems) {
|
||||
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
|
||||
@ -382,7 +392,7 @@ TORCH_API TupleTypePtr ivalue::TupleTypeFactory<TupleType>::fallback(
|
||||
return nullptr;
|
||||
#else
|
||||
const auto& dyn = type.expectRef<DynamicType>();
|
||||
std::vector<c10::string_view> fields;
|
||||
std::vector<std::string_view> fields;
|
||||
std::vector<TypePtr> types;
|
||||
|
||||
for (const auto& elem : dyn.arguments().elems) {
|
||||
|
@ -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);
|
||||
|
||||
TypePtr containedType(size_t) const override;
|
||||
size_t containedTypeSize() const override;
|
||||
|
@ -1154,7 +1154,7 @@ struct TORCH_API TupleType : public NamedType {
|
||||
const std::vector<TypePtr>& field_types);
|
||||
|
||||
static TupleTypePtr createNamed(const std::optional<c10::QualifiedName>& name,
|
||||
const std::vector<c10::string_view>& field_names,
|
||||
const std::vector<std::string_view>& field_names,
|
||||
const std::vector<TypePtr>& field_types);
|
||||
|
||||
static TupleTypePtr create(
|
||||
@ -1190,7 +1190,7 @@ struct TORCH_API TupleType : public NamedType {
|
||||
const std::shared_ptr<FunctionSchema>& schema() const {
|
||||
return schema_;
|
||||
}
|
||||
std::optional<std::vector<c10::string_view>> names() const;
|
||||
std::optional<std::vector<std::string_view>> names() const;
|
||||
|
||||
static const TypeKind Kind = TypeKind::TupleType;
|
||||
|
||||
@ -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();
|
||||
|
@ -728,7 +728,7 @@ TupleTypePtr TupleType::createNamed(
|
||||
|
||||
TupleTypePtr TupleType::createNamed(
|
||||
const std::optional<c10::QualifiedName>& qualName,
|
||||
const std::vector<c10::string_view>& field_names,
|
||||
const std::vector<std::string_view>& field_names,
|
||||
const std::vector<TypePtr>& field_types) {
|
||||
std::vector<IValue> empty_defaults;
|
||||
return createWithSpec(qualName, field_names, field_types, empty_defaults);
|
||||
@ -784,11 +784,11 @@ TupleTypePtr TupleType::createWithSpec(const std::optional<c10::QualifiedName>&
|
||||
field_types, qualName, std::move(schema))); // NOLINT(modernize-make-shared)
|
||||
}
|
||||
|
||||
std::optional<std::vector<c10::string_view>> TupleType::names() const {
|
||||
std::optional<std::vector<std::string_view>> TupleType::names() const {
|
||||
if (!schema_) {
|
||||
return {};
|
||||
}
|
||||
std::vector<c10::string_view> ret;
|
||||
std::vector<std::string_view> ret;
|
||||
for (const auto& arg : schema_->arguments()) {
|
||||
ret.emplace_back(arg.name());
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ const std::unordered_map<std::string, c10::TypePtr>& DynamicTypeFactory::
|
||||
static const std::unordered_map<std::string, c10::TypePtr> map = {
|
||||
#define MAP_ITEM(NAME, TYPE) \
|
||||
{#NAME, c10::DynamicTypeTrait<c10::TYPE>::getBaseType()},
|
||||
FORALL_BASE_PYTHON_TYPES(MAP_ITEM)
|
||||
FORALL_BASE_PYTHON_TYPES(MAP_ITEM)
|
||||
#undef MAP_ITEM
|
||||
};
|
||||
return map;
|
||||
@ -61,7 +61,7 @@ const std::unordered_map<std::string, c10::TypePtr>& DefaultTypeFactory::
|
||||
|
||||
c10::TypePtr DefaultTypeFactory::createNamedTuple(
|
||||
const std::string& name,
|
||||
const std::vector<c10::string_view>& fields,
|
||||
const std::vector<std::string_view>& fields,
|
||||
const std::vector<c10::TypePtr>& types) {
|
||||
return c10::TupleType::createNamed(name, fields, types);
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ struct TORCH_API TypeFactoryBase<c10::DynamicType> {
|
||||
}
|
||||
static c10::DynamicTypePtr createNamedTuple(
|
||||
const std::string& name,
|
||||
const std::vector<c10::string_view>& fields,
|
||||
const std::vector<std::string_view>& fields,
|
||||
const std::vector<c10::TypePtr>& types) {
|
||||
return std::make_shared<c10::DynamicType>(
|
||||
c10::DynamicType::Tag::Tuple,
|
||||
@ -80,7 +80,7 @@ struct TORCH_API TypeFactoryBase<c10::Type> {
|
||||
}
|
||||
static c10::TypePtr createNamedTuple(
|
||||
const std::string& name,
|
||||
const std::vector<c10::string_view>& fields,
|
||||
const std::vector<std::string_view>& fields,
|
||||
const std::vector<c10::TypePtr>& types);
|
||||
template <typename T>
|
||||
C10_ERASE static c10::TypePtr createNamed(const std::string& name) {
|
||||
|
@ -9,7 +9,7 @@ TEST(SourceRangeTest, test_find) {
|
||||
strings.push_back(std::make_shared<std::string>("hello world"));
|
||||
strings.push_back(std::make_shared<std::string>("nihaoma"));
|
||||
|
||||
std::vector<c10::string_view> pieces{*strings[0], *strings[1]};
|
||||
std::vector<std::string_view> pieces{*strings[0], *strings[1]};
|
||||
|
||||
StringCordView view(pieces, strings);
|
||||
|
||||
@ -22,7 +22,7 @@ TEST(SourceRangeTest, test_substr) {
|
||||
strings.push_back(std::make_shared<std::string>("hello world"));
|
||||
strings.push_back(std::make_shared<std::string>("nihaoma"));
|
||||
|
||||
std::vector<c10::string_view> pieces{*strings[0], *strings[1]};
|
||||
std::vector<std::string_view> pieces{*strings[0], *strings[1]};
|
||||
|
||||
StringCordView view(pieces, strings);
|
||||
|
||||
@ -36,7 +36,7 @@ TEST(SourceRangeTest, test_iter) {
|
||||
strings.push_back(std::make_shared<std::string>("hello world"));
|
||||
strings.push_back(std::make_shared<std::string>("nihaoma"));
|
||||
|
||||
std::vector<c10::string_view> pieces{*strings[0], *strings[1]};
|
||||
std::vector<std::string_view> pieces{*strings[0], *strings[1]};
|
||||
|
||||
StringCordView view(pieces, strings);
|
||||
|
||||
|
@ -14,7 +14,7 @@ StringCordView::StringCordView() {
|
||||
}
|
||||
|
||||
StringCordView::StringCordView(
|
||||
std::vector<c10::string_view> inputs,
|
||||
std::vector<std::string_view> inputs,
|
||||
std::vector<std::shared_ptr<std::string>> ownerships)
|
||||
: pieces_(std::move(inputs)), owned_strings_(std::move(ownerships)) {
|
||||
accumulated_sizes_.push_back(0);
|
||||
@ -70,7 +70,7 @@ size_t StringCordView::find_regex(const std::string& tok, size_t start) const {
|
||||
}
|
||||
|
||||
StringCordView StringCordView::substr(size_t start, size_t size) const {
|
||||
std::vector<c10::string_view> pieces;
|
||||
std::vector<std::string_view> pieces;
|
||||
std::vector<std::shared_ptr<std::string>> ownerships;
|
||||
if (start >= this->size()) {
|
||||
// out of bounds
|
||||
|
@ -22,7 +22,7 @@ struct TORCH_API StringCordView {
|
||||
StringCordView(const StringCordView&) = default;
|
||||
StringCordView(StringCordView&&) noexcept = default;
|
||||
StringCordView(
|
||||
std::vector<c10::string_view> inputs,
|
||||
std::vector<std::string_view> inputs,
|
||||
std::vector<std::shared_ptr<std::string>> ownerships);
|
||||
|
||||
StringCordView& operator=(const StringCordView&) = default;
|
||||
@ -171,7 +171,7 @@ struct TORCH_API StringCordView {
|
||||
Iterator iter_for_pos(size_t pos) const;
|
||||
|
||||
private:
|
||||
std::vector<c10::string_view> pieces_;
|
||||
std::vector<std::string_view> pieces_;
|
||||
std::vector<size_t> accumulated_sizes_;
|
||||
std::vector<std::shared_ptr<std::string>> owned_strings_;
|
||||
};
|
||||
|
@ -182,7 +182,7 @@ TypePtr TypeParser::parse() {
|
||||
// ]
|
||||
// ]"
|
||||
TypePtr TypeParser::parseNamedTuple(const std::string& qualified_name) {
|
||||
std::vector<c10::string_view> field_names;
|
||||
std::vector<std::string_view> field_names;
|
||||
std::vector<TypePtr> field_types;
|
||||
expect(",");
|
||||
expect("[");
|
||||
@ -282,7 +282,7 @@ void TypeParser::expect(const char* s) {
|
||||
advance();
|
||||
}
|
||||
|
||||
// c10::string_view::operator== calls memcmp to compare against the target
|
||||
// std::string_view::operator== may call memcmp to compare against the target
|
||||
// string; we can do better if we specialize for a single character.
|
||||
void TypeParser::expectChar(char c) {
|
||||
std::string_view token = cur();
|
||||
|
@ -1905,7 +1905,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>();
|
||||
}
|
||||
|
@ -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>()) {
|
||||
|
@ -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) {
|
||||
@ -76,7 +76,7 @@ std::shared_ptr<Source> SourceRangeDeserializer::deserialize_source(
|
||||
"Text table index is out of range")
|
||||
filename = *text_table_[fnameIndex];
|
||||
|
||||
std::vector<c10::string_view> pieces;
|
||||
std::vector<std::string_view> pieces;
|
||||
std::vector<std::shared_ptr<std::string>> strs;
|
||||
|
||||
for (int64_t i : textIndex) {
|
||||
|
Reference in New Issue
Block a user