Skip to content

Commit 78052c8

Browse files
Ritvij Saxenafacebook-github-bot
authored andcommitted
[lint][codemod][fbcode/pytorch/vision] Applying CLANGFORMAT formatting
Summary: Removed `fbcode/pytorch/vision` from the `CLANGFORMAT` opt-outs and applied formatting with: hg files fbcode/pytorch/vision | arc lint --take CLANGFORMAT --apply-patches - Furthermore, - Added `nolint` to the files mentioned below as it contains improperly imported third-party code fbcode/pytorch/vision/torchvision/csrc/io/image/cpu/exif.h fbcode/pytorch/vision/torchvision/csrc/io/image/cpu/giflib/dgif_lib.c fbcode/pytorch/vision/torchvision/csrc/io/image/cpu/giflib/gif_hash.c fbcode/pytorch/vision/torchvision/csrc/io/image/cpu/giflib/gif_hash.h fbcode/pytorch/vision/torchvision/csrc/io/image/cpu/giflib/gif_lib.h fbcode/pytorch/vision/torchvision/csrc/io/image/cpu/giflib/gif_lib_private.h fbcode/pytorch/vision/torchvision/csrc/io/image/cpu/giflib/gifalloc.c fbcode/pytorch/vision/torchvision/csrc/io/image/cpu/giflib/openbsd-reallocarray.c fbcode/pytorch/vision/torchvision/csrc/ops/cpu/deform_conv2d_kernel.cpp fbcode/pytorch/vision/torchvision/csrc/ops/cuda/deform_conv2d_kernel.cu - Added `.clang-format` file to `fbcode/pytorch/vision/` directory to avoid formatting of non c like files. Note: Contains pre-existing build issues $ hg st --change 8e76164795 -n | buck2 uquery 'owner(%s)' - | buck2 build - Reviewed By: VladimirMakaev Differential Revision: D65142313 fbshipit-source-id: 4670a1f9c27e1eca41ac337813fc8c5ea255e5c5
1 parent 111971b commit 78052c8

26 files changed

+95
-172
lines changed

.clang-format

Lines changed: 2 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,5 @@
11
---
2-
AccessModifierOffset: -1
3-
AlignAfterOpenBracket: AlwaysBreak
4-
AlignConsecutiveAssignments: false
5-
AlignConsecutiveDeclarations: false
6-
AlignEscapedNewlinesLeft: true
7-
AlignOperands: false
8-
AlignTrailingComments: false
9-
AllowAllParametersOfDeclarationOnNextLine: false
10-
AllowShortBlocksOnASingleLine: false
11-
AllowShortCaseLabelsOnASingleLine: false
12-
AllowShortFunctionsOnASingleLine: Empty
13-
AllowShortIfStatementsOnASingleLine: false
14-
AllowShortLoopsOnASingleLine: false
15-
AlwaysBreakAfterReturnType: None
16-
AlwaysBreakBeforeMultilineStrings: true
17-
AlwaysBreakTemplateDeclarations: true
18-
BinPackArguments: false
19-
BinPackParameters: false
20-
BraceWrapping:
21-
AfterClass: false
22-
AfterControlStatement: false
23-
AfterEnum: false
24-
AfterFunction: false
25-
AfterNamespace: false
26-
AfterObjCDeclaration: false
27-
AfterStruct: false
28-
AfterUnion: false
29-
BeforeCatch: false
30-
BeforeElse: false
31-
IndentBraces: false
32-
BreakBeforeBinaryOperators: None
33-
BreakBeforeBraces: Attach
34-
BreakBeforeTernaryOperators: true
35-
BreakConstructorInitializersBeforeComma: false
36-
BreakAfterJavaFieldAnnotations: false
37-
BreakStringLiterals: false
38-
ColumnLimit: 80
39-
CommentPragmas: '^ IWYU pragma:'
40-
#CompactNamespaces: false
41-
ConstructorInitializerAllOnOneLineOrOnePerLine: true
42-
ConstructorInitializerIndentWidth: 4
43-
ContinuationIndentWidth: 4
44-
Cpp11BracedListStyle: true
45-
DerivePointerAlignment: false
46-
DisableFormat: false
47-
ForEachMacros: [ FOR_EACH_RANGE, FOR_EACH, ]
48-
IncludeCategories:
49-
- Regex: '^<.*\.h(pp)?>'
50-
Priority: 1
51-
- Regex: '^<.*'
52-
Priority: 2
53-
- Regex: '.*'
54-
Priority: 3
55-
IndentCaseLabels: true
56-
IndentWidth: 2
57-
IndentWrappedFunctionNames: false
58-
KeepEmptyLinesAtTheStartOfBlocks: false
59-
MacroBlockBegin: ''
60-
MacroBlockEnd: ''
61-
MaxEmptyLinesToKeep: 1
62-
NamespaceIndentation: None
63-
PenaltyBreakBeforeFirstCallParameter: 1
64-
PenaltyBreakComment: 300
65-
PenaltyBreakFirstLessLess: 120
66-
PenaltyBreakString: 1000
67-
PenaltyExcessCharacter: 1000000
68-
PenaltyReturnTypeOnItsOwnLine: 2000000
69-
PointerAlignment: Left
70-
ReflowComments: true
71-
SortIncludes: true
72-
SpaceAfterCStyleCast: false
73-
SpaceBeforeAssignmentOperators: true
74-
SpaceBeforeParens: ControlStatements
75-
SpaceInEmptyParentheses: false
76-
SpacesBeforeTrailingComments: 1
77-
SpacesInAngles: false
78-
SpacesInContainerLiterals: true
79-
SpacesInCStyleCastParentheses: false
80-
SpacesInParentheses: false
81-
SpacesInSquareBrackets: false
82-
Standard: Cpp11
83-
TabWidth: 8
84-
UseTab: Never
85-
---
862
Language: ObjC
87-
ColumnLimit: 120
88-
AlignAfterOpenBracket: Align
89-
ObjCBlockIndentWidth: 2
90-
ObjCSpaceAfterProperty: false
91-
ObjCSpaceBeforeProtocolList: false
3+
DisableFormat: true
4+
SortIncludes: false
925
...
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#import <UIKit/UIKit.h>
22

3-
@interface AppDelegate : UIResponder <UIApplicationDelegate>
3+
@interface AppDelegate : UIResponder<UIApplicationDelegate>
44

5-
@property(strong, nonatomic) UIWindow *window;
5+
@property(strong, nonatomic) UIWindow* window;
66

77
@end

ios/VisionTestApp/VisionTestApp/ModelRunner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ NS_ASSUME_NONNULL_BEGIN
55

66
@interface ModelRunner : NSObject
77

8-
+ (NSString* )run;
8+
+ (NSString*)run;
99
+ (BOOL)setUp;
1010

1111
@end

ios/VisionTestApp/VisionTestApp/ViewController.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33

44
@interface ViewController : UIViewController
55

6-
76
@end

test/cpp/test_custom_operators.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
TEST(test_custom_operators, nms) {
99
// make sure that the torchvision ops are visible to the jit interpreter
10-
auto& ops = torch::jit::getAllOperatorsFor(torch::jit::Symbol::fromQualString("torchvision::nms"));
10+
auto& ops = torch::jit::getAllOperatorsFor(
11+
torch::jit::Symbol::fromQualString("torchvision::nms"));
1112
ASSERT_EQ(ops.size(), 1);
1213

1314
auto& op = ops.front();
@@ -24,29 +25,35 @@ TEST(test_custom_operators, nms) {
2425

2526
at::Tensor output = vision::ops::nms(boxes, scores, thresh);
2627
ASSERT_TRUE(output_jit.allclose(output));
27-
2828
}
2929

3030
TEST(test_custom_operators, roi_align_visible) {
31-
// make sure that the torchvision ops are visible to the jit interpreter even if
32-
// not explicitly included
33-
auto& ops = torch::jit::getAllOperatorsFor(torch::jit::Symbol::fromQualString("torchvision::roi_align"));
31+
// make sure that the torchvision ops are visible to the jit interpreter even
32+
// if not explicitly included
33+
auto& ops = torch::jit::getAllOperatorsFor(
34+
torch::jit::Symbol::fromQualString("torchvision::roi_align"));
3435
ASSERT_EQ(ops.size(), 1);
3536

3637
auto& op = ops.front();
3738
ASSERT_EQ(op->schema().name(), "torchvision::roi_align");
3839

3940
torch::jit::Stack stack;
40-
float roi_data[] = {
41-
0., 0., 0., 5., 5.,
42-
0., 5., 5., 10., 10.
43-
};
44-
at::Tensor input = at::rand({1, 2, 10, 10}), rois = at::from_blob(roi_data, {2, 5});
41+
float roi_data[] = {0., 0., 0., 5., 5., 0., 5., 5., 10., 10.};
42+
at::Tensor input = at::rand({1, 2, 10, 10}),
43+
rois = at::from_blob(roi_data, {2, 5});
4544
double spatial_scale = 1.0;
4645
int64_t pooled_height = 3, pooled_width = 3, sampling_ratio = -1;
4746
bool aligned = true;
4847

49-
torch::jit::push(stack, input, rois, spatial_scale, pooled_height, pooled_width, sampling_ratio, aligned);
48+
torch::jit::push(
49+
stack,
50+
input,
51+
rois,
52+
spatial_scale,
53+
pooled_height,
54+
pooled_width,
55+
sampling_ratio,
56+
aligned);
5057
op->getOperation()(stack);
5158
at::Tensor output_jit;
5259
torch::jit::pop(stack, output_jit);

torchvision/csrc/io/decoder/decoder.cpp

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -387,16 +387,21 @@ bool Decoder::init(
387387
for (unsigned int i = 0; i < inputCtx_->nb_streams; i++) {
388388
if (
389389
#if LIBAVUTIL_VERSION_MAJOR < 56 // Before FFMPEG 4.0
390-
inputCtx_->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO
390+
inputCtx_->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO
391391
#else // FFMPEG 4.0+
392-
inputCtx_->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO
392+
inputCtx_->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO
393393
#endif
394-
&& inputCtx_->streams[i]->duration > 0
395-
) {
396-
// There is at least two 1/r_frame_rates from the frame before the last one until the video duration,
397-
// let's prefer to set duration after the frame before the last one, but as early as possible
398-
double correction = 2 * inputCtx_->streams[i]->r_frame_rate.den / (double) inputCtx_->streams[i]->r_frame_rate.num - 1 / (double) AV_TIME_BASE;
399-
videoDurationMs_ = 1000 * inputCtx_->streams[i]->duration * inputCtx_->streams[i]->time_base.num / (double) inputCtx_->streams[i]->time_base.den - 1000 * correction;
394+
&& inputCtx_->streams[i]->duration > 0) {
395+
// There is at least two 1/r_frame_rates from the frame before the last
396+
// one until the video duration, let's prefer to set duration after the
397+
// frame before the last one, but as early as possible
398+
double correction = 2 * inputCtx_->streams[i]->r_frame_rate.den /
399+
(double)inputCtx_->streams[i]->r_frame_rate.num -
400+
1 / (double)AV_TIME_BASE;
401+
videoDurationMs_ = 1000 * inputCtx_->streams[i]->duration *
402+
inputCtx_->streams[i]->time_base.num /
403+
(double)inputCtx_->streams[i]->time_base.den -
404+
1000 * correction;
400405
break;
401406
}
402407
}
@@ -568,7 +573,6 @@ int Decoder::getFrame(size_t workingTimeInMs) {
568573
continue;
569574
}
570575

571-
572576
size_t numConsecutiveNoBytes = 0;
573577
// it can be only partial decoding of the package bytes
574578
do {
@@ -614,20 +618,27 @@ int Decoder::getFrame(size_t workingTimeInMs) {
614618

615619
if (params_.uniformSampling > 1) {
616620
if (doSeek_) {
617-
double duration = videoDurationMs_ > 0 ? videoDurationMs_ : params_.expectedDuration;
618-
double step = (duration * AV_TIME_BASE) / (1000 * (params_.uniformSampling - 1));
619-
avformat_seek_file(inputCtx_, -1, static_cast<int64_t>(step * kFramesDecoded_) + 1, static_cast<int64_t>(step * (kFramesDecoded_ + 1)), static_cast<int64_t>(step * (kFramesDecoded_ + 1)), 0);
621+
double duration =
622+
videoDurationMs_ > 0 ? videoDurationMs_ : params_.expectedDuration;
623+
double step =
624+
(duration * AV_TIME_BASE) / (1000 * (params_.uniformSampling - 1));
625+
avformat_seek_file(
626+
inputCtx_,
627+
-1,
628+
static_cast<int64_t>(step * kFramesDecoded_) + 1,
629+
static_cast<int64_t>(step * (kFramesDecoded_ + 1)),
630+
static_cast<int64_t>(step * (kFramesDecoded_ + 1)),
631+
0);
620632
++kFramesDecoded_;
621633
doSeek_ = false;
622634
}
623635
}
624636
}
625637

626638
av_packet_free(&avPacket);
627-
VLOG(2) << "Interrupted loop"
628-
<< ", interrupted_ " << interrupted_ << ", inRange_.any() "
629-
<< inRange_.any() << ", decodedFrame " << decodedFrame << ", result "
630-
<< result;
639+
VLOG(2) << "Interrupted loop" << ", interrupted_ " << interrupted_
640+
<< ", inRange_.any() " << inRange_.any() << ", decodedFrame "
641+
<< decodedFrame << ", result " << result;
631642

632643
// loop can be terminated, either by:
633644
// 1. explicitly interrupted
@@ -691,7 +702,7 @@ int Decoder::processPacket(
691702
startCondition = msg.header.pts >= params_.startOffset;
692703
}
693704
if (endInRange && startCondition) {
694-
*hasMsg = pushMsg(std::move(msg));
705+
*hasMsg = pushMsg(std::move(msg));
695706
}
696707
}
697708
return result;
@@ -706,9 +717,12 @@ bool Decoder::pushMsg(DecoderOutputMessage&& msg) {
706717
return true;
707718
}
708719

709-
double duration = videoDurationMs_ > 0 ? videoDurationMs_ : params_.expectedDuration;
710-
double step = (duration * AV_TIME_BASE) / (1000 * (params_.uniformSampling - 1));
711-
if (pastDecodedPTS_ < step * kFramesDecoded_ && step * kFramesDecoded_ <= currentDecodedPTS_) {
720+
double duration =
721+
videoDurationMs_ > 0 ? videoDurationMs_ : params_.expectedDuration;
722+
double step =
723+
(duration * AV_TIME_BASE) / (1000 * (params_.uniformSampling - 1));
724+
if (pastDecodedPTS_ < step * kFramesDecoded_ &&
725+
step * kFramesDecoded_ <= currentDecodedPTS_) {
712726
push(std::move(msg));
713727
doSeek_ = true;
714728
return true;

torchvision/csrc/io/decoder/decoder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ class Decoder : public MediaDecoder {
7777
bool fastSeek = false);
7878
void flushStreams();
7979
void cleanUp();
80-
bool pushMsg(DecoderOutputMessage&& msg); // returns whether frame is passed to downstream
80+
bool pushMsg(DecoderOutputMessage&&
81+
msg); // returns whether frame is passed to downstream
8182

8283
protected:
8384
DecoderParameters params_;
8485

85-
8686
private:
8787
SeekableBuffer seekableBuffer_;
8888
int printPrefix{1};

torchvision/csrc/io/decoder/defs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ struct DecoderParameters {
220220
// integer not lesser than 32. It is 5000000 by default.
221221
int64_t probeSize{5000000};
222222

223-
// Expected duration of the video to be decoded, mainly used with uniform sampling
223+
// Expected duration of the video to be decoded, mainly used with uniform
224+
// sampling
224225
float expectedDuration{0.0f};
225226

226227
// Sample N key-frames from the video roughly uniformly across the timeline

torchvision/csrc/io/decoder/gpu/gpu_decoder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ void GPUDecoder::seek(double timestamp, bool keyframes_only) {
4646
demuxer.seek(timestamp, flag);
4747
}
4848

49-
c10::Dict<std::string, c10::Dict<std::string, double>> GPUDecoder::
50-
get_metadata() const {
49+
c10::Dict<std::string, c10::Dict<std::string, double>>
50+
GPUDecoder::get_metadata() const {
5151
c10::Dict<std::string, c10::Dict<std::string, double>> metadata;
5252
c10::Dict<std::string, double> video_metadata;
5353
video_metadata.insert("duration", demuxer.get_duration());

torchvision/csrc/io/decoder/sync_decoder_test.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ void runDecoder(SyncDecoder& decoder) {
158158
AVSubtitle sub;
159159
memset(&sub, 0, sizeof(sub));
160160
EXPECT_TRUE(Util::deserialize(*out.payload, &sub));
161-
LOG(INFO) << "Found subtitles"
162-
<< ", num rects: " << sub.num_rects;
161+
LOG(INFO) << "Found subtitles" << ", num rects: " << sub.num_rects;
163162
for (int i = 0; i < sub.num_rects; ++i) {
164163
std::string text = "picture";
165164
if (sub.rects[i]->type == SUBTITLE_TEXT) {
@@ -210,9 +209,9 @@ TEST(SyncDecoder, TestSyncDecoderPerformance) {
210209
auto new8x8 = measurePerformanceUs(stats, kRounds, 8, 8);
211210
auto new16x8 = measurePerformanceUs(stats, kRounds, 16, 8);
212211
auto new32x4 = measurePerformanceUs(stats, kRounds, 32, 4);
213-
LOG(INFO) << "Clip decoding (us)"
214-
<< ", new(4x2): " << new4x2 << ", new(8x8): " << new8x8
215-
<< ", new(16x8): " << new16x8 << ", new(32x4): " << new32x4;
212+
LOG(INFO) << "Clip decoding (us)" << ", new(4x2): " << new4x2
213+
<< ", new(8x8): " << new8x8 << ", new(16x8): " << new16x8
214+
<< ", new(32x4): " << new32x4;
216215
}
217216

218217
TEST(SyncDecoder, Test) {

0 commit comments

Comments
 (0)