10000 [BE]: Update torch core lazy helpers with micropts (#152778) · pytorch/pytorch@0e98748 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0e98748

Browse files
Skylion007pytorchmergebot
authored andcommitted
[BE]: Update torch core lazy helpers with micropts (#152778)
Some minor nits I noticed. Use reserve when possible Pull Request resolved: #152778 Approved by: https://github.com/cyyever, https://github.com/albanD
1 parent fd57c16 commit 0e98748

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

torch/csrc/lazy/core/helpers.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <torch/csrc/lazy/core/helpers.h>
2+
#include <algorithm>
23

34
#include <c10/util/Half.h>
45
#include <c10/util/irange.h>
@@ -10,6 +11,7 @@ std::vector<int64_t> DropDimensions(
1011
c10::ArrayRef<int64_t> sizes,
1112
c10::ArrayRef<int64_t> drop_dims) {
1213
std::vector<int64_t> new_dims;
14+
new_dims.reserve(sizes.size() - drop_dims.size());
1315
size_t drop_index = 0;
1416
for (const auto i : c10::irange(sizes.size())) {
1517
if (drop_index < drop_dims.size() &&
@@ -45,6 +47,7 @@ std::vector<int64_t> GetCanonicalDimensionIndices(
4547
c10::ArrayRef<int64_t> dimensions,
4648
int64_t rank) {
4749
std::vector<int64_t> canonical_dim_indices;
50+
canonical_dim_indices.reserve(dimensions.size());
4851
for (int64_t dim : dimensions) {
4952
canonical_dim_indices.push_back(GetCanonicalDimensionIndex(dim, rank));
5053
}
@@ -131,8 +134,7 @@ std::vector<std::string> StrSplit(std::string_view text, char delim) {
131134
std::vector<std::string> tokens;
132135
while ((start = text.find_first_not_of(delim, end)) != std::string::npos) {
133136
end = text.find(delim, start);
134-
auto token = text.substr(start, end - start);
135-
tokens.emplace_back(token.begin(), token.end());
137+
tokens.emplace_back(text.substr(start, end - start));
136138
}
137139
return tokens;
138140
}

0 commit comments

Comments
 (0)
0