mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
[BE][Ez]: Enable ClangFormat aten/src/core/Formatting.cpp (#154719)
Follow up to #152830 . Noticed the file was excluded from fromatting, opt in to clang-format since it's really close anyway. Pull Request resolved: https://github.com/pytorch/pytorch/pull/154719 Approved by: https://github.com/jansel
This commit is contained in:
parent
f57754e815
commit
2f03673ebf
|
|
@ -64,6 +64,7 @@ include_patterns = [
|
|||
'aten/src/ATen/xpu/**/*.cpp',
|
||||
'aten/src/ATen/core/boxing/**/*.h',
|
||||
'aten/src/ATen/core/dispatch/**/*.h',
|
||||
'aten/src/ATen/core/Formatting.cpp',
|
||||
'aten/src/ATen/native/mps/**/*.metal',
|
||||
'aten/src/ATen/native/mps/**/*.mm',
|
||||
'aten/src/ATen/native/mps/**/*.h',
|
||||
|
|
|
|||
|
|
@ -168,7 +168,11 @@ static void printValue(std::ostream& stream, double v, const PrintFormat& pf) {
|
|||
}
|
||||
}
|
||||
|
||||
static void __printMatrix(std::ostream& stream, const Tensor& self, int64_t linesize, int64_t indent) {
|
||||
static void __printMatrix(
|
||||
std::ostream& stream,
|
||||
const Tensor& self,
|
||||
int64_t linesize,
|
||||
int64_t indent) {
|
||||
auto printFmt = __printFormat(self);
|
||||
|
||||
int64_t nColumnPerLine = (linesize - indent) / (printFmt.width + 1);
|
||||
|
|
@ -197,8 +201,7 @@ static void __printMatrix(std::ostream& stream, const Tensor& self, int64_t line
|
|||
}
|
||||
|
||||
if (printFmt.scale != 1) {
|
||||
fmt::print(stream, "{} *\n{:>{}s}",
|
||||
printFmt.scale, "", indent);
|
||||
fmt::print(stream, "{} *\n{:>{}s}", printFmt.scale, "", indent);
|
||||
}
|
||||
|
||||
for (const auto l : c10::irange(self.size(0))) {
|
||||
|
|
@ -226,7 +229,10 @@ static void __printMatrix(std::ostream& stream, const Tensor& self, int64_t line
|
|||
}
|
||||
}
|
||||
|
||||
static void __printTensor(std::ostream& stream, Tensor& self, int64_t linesize) {
|
||||
static void __printTensor(
|
||||
std::ostream& stream,
|
||||
Tensor& self,
|
||||
int64_t linesize) {
|
||||
std::vector<int64_t> counter(self.ndimension() - 2, 0);
|
||||
counter[0] = -1;
|
||||
|
||||
|
|
@ -270,7 +276,10 @@ void print(const Tensor & t, int64_t linesize) {
|
|||
print(std::cout, t, linesize);
|
||||
}
|
||||
|
||||
std::ostream& print(std::ostream& stream, const Tensor & tensor_, int64_t linesize) {
|
||||
std::ostream& print(
|
||||
std::ostream& stream,
|
||||
const Tensor& tensor_,
|
||||
int64_t linesize) {
|
||||
if (!tensor_.defined()) {
|
||||
fmt::print(stream, "[ Tensor (undefined) ]");
|
||||
return stream;
|
||||
|
|
@ -300,7 +309,8 @@ std::ostream& print(std::ostream& stream, const Tensor & tensor_, int64_t linesi
|
|||
}
|
||||
|
||||
if (tensor.ndimension() == 0) {
|
||||
fmt::print(stream,
|
||||
fmt::print(
|
||||
stream,
|
||||
"{}\n[ {}{{}}",
|
||||
tensor.const_data_ptr<double>()[0],
|
||||
tensor_.toString());
|
||||
|
|
@ -321,8 +331,12 @@ std::ostream& print(std::ostream& stream, const Tensor & tensor_, int64_t linesi
|
|||
if (tensor.numel() > 0) {
|
||||
__printMatrix(stream, tensor, linesize, 0);
|
||||
}
|
||||
fmt::print(stream, "[ {}{{{},{}}}",
|
||||
tensor_.toString(), tensor.size(0), tensor.size(1));
|
||||
fmt::print(
|
||||
stream,
|
||||
"[ {}{{{},{}}}",
|
||||
tensor_.toString(),
|
||||
tensor.size(0),
|
||||
tensor.size(1));
|
||||
} else {
|
||||
if (tensor.numel() > 0) {
|
||||
__printTensor(stream, tensor, linesize);
|
||||
|
|
@ -338,9 +352,13 @@ std::ostream& print(std::ostream& stream, const Tensor & tensor_, int64_t linesi
|
|||
if (tensor_.is_quantized()) {
|
||||
fmt::print(stream, ", qscheme: {}", toString(tensor_.qscheme()));
|
||||
if (tensor_.qscheme() == c10::kPerTensorAffine) {
|
||||
fmt::print(stream, ", scale: {}, zero_point: {}",
|
||||
tensor_.q_scale(), tensor_.q_zero_point());
|
||||
} else if (tensor_.qscheme() == c10::kPerChannelAffine ||
|
||||
fmt::print(
|
||||
stream,
|
||||
", scale: {}, zero_point: {}",
|
||||
tensor_.q_scale(),
|
||||
tensor_.q_zero_point());
|
||||
} else if (
|
||||
tensor_.qscheme() == c10::kPerChannelAffine ||
|
||||
tensor_.qscheme() == c10::kPerChannelAffineFloatQParams) {
|
||||
fmt::print(stream, ", scales: ");
|
||||
print(stream, tensor_.q_per_channel_scales(), linesize);
|
||||
|
|
@ -363,4 +381,4 @@ std::ostream& print(std::ostream& stream, const Tensor & tensor_, int64_t linesi
|
|||
return stream;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace at
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user