Skip to content

Commit 5605fce

Browse files
cyyeverpytorchmergebot
authored andcommitted
Improve char printing (pytorch#167899)
This PR outputs chars to stream without building temporary strings. They were modified by (on fish) ``` sed -i -e 's/<< "\([^\\\']\)"/<< \'\1\'/g' (grep '<< "."' -r torch c10 aten -l) ``` and revert some invalid changes. Pull Request resolved: pytorch#167899 Approved by: https://github.com/Skylion007
1 parent 2f023bf commit 5605fce

File tree

209 files changed

+920
-927
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

209 files changed

+920
-927
lines changed

aten/src/ATen/LegacyBatchedTensorImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ inline std::bitset<kVmapNumLevels> createVmapLevelsBitset(BatchDimsRef bdims) {
144144
}
145145

146146
inline std::ostream& operator<<(std::ostream& out, const BatchDim& bdim) {
147-
out << "(lvl=" << bdim.level() << ", dim=" << bdim.dim() << ")";
147+
out << "(lvl=" << bdim.level() << ", dim=" << bdim.dim() << ')';
148148
return out;
149149
}
150150

aten/src/ATen/TensorIndexing.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace indexing {
99
const EllipsisIndexType Ellipsis = EllipsisIndexType();
1010

1111
std::ostream& operator<<(std::ostream& stream, const Slice& slice) {
12-
stream << slice.start() << ":" << slice.stop() << ":" << slice.step();
12+
stream << slice.start() << ':' << slice.stop() << ':' << slice.step();
1313
return stream;
1414
}
1515

@@ -31,12 +31,12 @@ std::ostream& operator<<(std::ostream& stream, const TensorIndex& tensor_index)
3131
}
3232

3333
std::ostream& operator<<(std::ostream& stream, const std::vector<TensorIndex>& tensor_indices) {
34-
stream << "(";
34+
stream << '(';
3535
for (const auto i : c10::irange(tensor_indices.size())) {
3636
stream << tensor_indices[i];
3737
if (i < tensor_indices.size() - 1) stream << ", ";
3838
}
39-
stream << ")";
39+
stream << ')';
4040
return stream;
4141
}
4242

aten/src/ATen/TensorNames.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void TensorNames::checkUnique(const char* op_name) const {
113113
std::ostream& operator<<(std::ostream& out, const TensorName& tensorname) {
114114
out << tensorname.name_ << " (index ";
115115
out << tensorname.origin_idx_ << " of ";
116-
out << tensorname.origin_ << ")";
116+
out << tensorname.origin_ << ')';
117117
return out;
118118
}
119119

aten/src/ATen/TensorUtils.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ std::ostream& operator<<(std::ostream & out, const TensorGeometryArg& t) {
1313
if (t.pos == 0) {
1414
// 0 is distinguished; it usually indicates 'self' or the return
1515
// tensor
16-
out << "'" << t.name << "'";
16+
out << '\'' << t.name << '\'';
1717
} else {
18-
out << "argument #" << t.pos << " '" << t.name << "'";
18+
out << "argument #" << t.pos << " '" << t.name << '\'';
1919
}
2020
return out;
2121
}
@@ -154,7 +154,7 @@ void checkSameGPU(CheckedFrom c, const TensorArg& t1, const TensorArg& t2) {
154154
oss << "Tensor for " << t2 << " is on CPU, ";
155155
}
156156
oss << "but expected " << ((!t1->is_cpu() && !t2->is_cpu()) ? "them" : "it")
157-
<< " to be on GPU (while checking arguments for " << c << ")";
157+
<< " to be on GPU (while checking arguments for " << c << ')';
158158
TORCH_CHECK(false, oss.str());
159159
}
160160
TORCH_CHECK(
@@ -199,7 +199,7 @@ void checkScalarTypes(CheckedFrom c, const TensorArg& t,
199199
i++;
200200
}
201201
oss << "; but got " << t->toString()
202-
<< " instead (while checking arguments for " << c << ")";
202+
<< " instead (while checking arguments for " << c << ')';
203203
TORCH_CHECK(false, oss.str());
204204
}
205205
}

aten/src/ATen/Version.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ std::string get_mkldnn_version() {
4343
// https://github.com/intel/ideep/issues/29
4444
{
4545
const dnnl_version_t* ver = dnnl_version();
46-
ss << "Intel(R) MKL-DNN v" << ver->major << "." << ver->minor << "." << ver->patch
47-
<< " (Git Hash " << ver->hash << ")";
46+
ss << "Intel(R) MKL-DNN v" << ver->major << '.' << ver->minor << '.' << ver->patch
47+
<< " (Git Hash " << ver->hash << ')';
4848
}
4949
#else
5050
ss << "MKLDNN not found";
@@ -81,7 +81,7 @@ std::string get_openmp_version() {
8181
break;
8282
}
8383
if (ver_str) {
84-
ss << " (a.k.a. OpenMP " << ver_str << ")";
84+
ss << " (a.k.a. OpenMP " << ver_str << ')';
8585
}
8686
}
8787
#else
@@ -135,38 +135,38 @@ std::string show_config() {
135135

136136
#if defined(__GNUC__)
137137
{
138-
ss << " - GCC " << __GNUC__ << "." << __GNUC_MINOR__ << "\n";
138+
ss << " - GCC " << __GNUC__ << '.' << __GNUC_MINOR__ << '\n';
139139
}
140140
#endif
141141

142142
#if defined(__cplusplus)
143143
{
144-
ss << " - C++ Version: " << __cplusplus << "\n";
144+
ss << " - C++ Version: " << __cplusplus << '\n';
145145
}
146146
#endif
147147

148148
#if defined(__clang_major__)
149149
{
150-
ss << " - clang " << __clang_major__ << "." << __clang_minor__ << "." << __clang_patchlevel__ << "\n";
150+
ss << " - clang " << __clang_major__ << '.' << __clang_minor__ << '.' << __clang_patchlevel__ << '\n';
151151
}
152152
#endif
153153

154154
#if defined(_MSC_VER)
155155
{
156-
ss << " - MSVC " << _MSC_FULL_VER << "\n";
156+
ss << " - MSVC " << _MSC_FULL_VER << '\n';
157157
}
158158
#endif
159159

160160
#if AT_MKL_ENABLED()
161-
ss << " - " << get_mkl_version() << "\n";
161+
ss << " - " << get_mkl_version() << '\n';
162162
#endif
163163

164164
#if AT_MKLDNN_ENABLED()
165-
ss << " - " << get_mkldnn_version() << "\n";
165+
ss << " - " << get_mkldnn_version() << '\n';
166166
#endif
167167

168168
#ifdef _OPENMP
169-
ss << " - " << get_openmp_version() << "\n";
169+
ss << " - " << get_openmp_version() << '\n';
170170
#endif
171171

172172
#if AT_BUILD_WITH_LAPACK()
@@ -183,7 +183,7 @@ std::string show_config() {
183183
ss << " - Cross compiling on MacOSX\n";
184184
#endif
185185

186-
ss << " - "<< used_cpu_capability() << "\n";
186+
ss << " - "<< used_cpu_capability() << '\n';
187187

188188
if (hasCUDA()) {
189189
ss << detail::getCUDAHooks().showConfig();
@@ -200,10 +200,10 @@ std::string show_config() {
200200
ss << " - Build settings: ";
201201
for (const auto& pair : caffe2::GetBuildOptions()) {
202202
if (!pair.second.empty()) {
203-
ss << pair.first << "=" << pair.second << ", ";
203+
ss << pair.first << '=' << pair.second << ", ";
204204
}
205205
}
206-
ss << "\n";
206+
ss << '\n';
207207

208208
// TODO: do HIP
209209
// TODO: do XLA

aten/src/ATen/code_template.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ struct CodeTemplate {
209209
// to indent correctly in the context.
210210
void emitIndent(std::ostream& out, size_t indent) const {
211211
for ([[maybe_unused]] const auto i : c10::irange(indent)) {
212-
out << " ";
212+
out << ' ';
213213
}
214214
}
215215
void emitStringWithIndents(

aten/src/ATen/core/Dimname.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ std::ostream& operator<<(std::ostream& out, const Dimname& dimname) {
1010
if (dimname.type() == NameType::WILDCARD) {
1111
out << "None";
1212
} else {
13-
out << "'" << dimname.symbol().toUnqualString() << "'";
13+
out << '\'' << dimname.symbol().toUnqualString() << '\'';
1414
}
1515
return out;
1616
}

aten/src/ATen/core/Range.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace at {
66

77
std::ostream& operator<<(std::ostream& out, const Range& range) {
8-
out << "Range[" << range.begin << ", " << range.end << "]";
8+
out << "Range[" << range.begin << ", " << range.end << ']';
99
return out;
1010
}
1111

aten/src/ATen/core/Tensor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void TensorBase::enforce_invariants() {
7171

7272
void TensorBase::print() const {
7373
if (defined()) {
74-
std::cerr << "[" << toString() << " " << sizes() << "]" << '\n';
74+
std::cerr << '[' << toString() << ' ' << sizes() << ']' << '\n';
7575
} else {
7676
std::cerr << "[UndefinedTensor]" << '\n';
7777
}

aten/src/ATen/core/Vitals.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ APIVitals VitalsAPI;
99

1010
std::ostream& operator<<(std::ostream& os, TorchVital const& tv) {
1111
for (const auto& m : tv.attrs) {
12-
os << "[TORCH_VITAL] " << tv.name << "." << m.first << "\t\t "
13-
<< m.second.value << "\n";
12+
os << "[TORCH_VITAL] " << tv.name << '.' << m.first << "\t\t "
13+
<< m.second.value << '\n';
1414
}
1515
return os;
1616
}

0 commit comments

Comments
 (0)