Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add namespace on image C++ codebase #3312

Merged
merged 6 commits into from
Jan 28, 2021
Merged

Conversation

datumbox
Copy link
Contributor

@datumbox datumbox commented Jan 27, 2021

Aligning the C++ codebase in image with the rest of the library, similar to #3311:

  • Reduce unnecessary header inclusions.
  • Add all internal functions in anonymous namespaces.
  • Add all methods in vision::image namespace.
  • Syncing public method names between C++ and Python.

@datumbox datumbox force-pushed the refactor/image branch 2 times, most recently from 8424391 to 8450858 Compare January 27, 2021 20:36
@datumbox datumbox requested a review from fmassa January 27, 2021 20:49
@datumbox datumbox changed the title [WIP] Add namespace on image C++ codebase Add namespace on image C++ codebase Jan 27, 2021
@codecov
Copy link

codecov bot commented Jan 27, 2021

Codecov Report

Merging #3312 (84616a5) into master (e95a3d2) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3312   +/-   ##
=======================================
  Coverage   73.93%   73.93%           
=======================================
  Files         104      104           
  Lines        9594     9594           
  Branches     1531     1531           
=======================================
  Hits         7093     7093           
  Misses       2024     2024           
  Partials      477      477           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e95a3d2...84616a5. Read the comment docs.

datumbox added a commit to datumbox/vision that referenced this pull request Jan 27, 2021
datumbox added a commit to datumbox/vision that referenced this pull request Jan 27, 2021
Copy link
Contributor Author

@datumbox datumbox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Git completely dropped the ball tracking which file was moved to what, so I left a couple of comments in places it gets it wrong. You can validate what I say by checking the individual commits.

namespace vision {
namespace image {

C10_EXPORT torch::Tensor decode_jpeg(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here Github fails to track the right file renames and thinks I moved png to jpeg and vice versa.

namespace vision {
namespace image {

C10_EXPORT torch::Tensor decode_png(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again Github fails to figure out which file was moved to what here.

namespace vision {
namespace image {

C10_EXPORT torch::Tensor encode_jpeg(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Git fails to track the old file.


#include <torch/types.h>

C10_EXPORT torch::Tensor encodeJPEG(const torch::Tensor& data, int64_t quality);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Git fails to track the move to the new file...

Copy link
Member

@fmassa fmassa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me, thanks!

namespace image {
namespace detail {

#if JPEG_FOUND
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we have two #if JPEG_FOUND in this file, but there doesn't seem to be any code not within JPEG_FOUND. Should we have instead a single #if JPEG_FOUND?

Copy link
Contributor Author

@datumbox datumbox Jan 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I intentionally use two because I wanted to put the headers on top and then actually have the namespace vision::image::detail because I open it from a different file. This way even if it's empty the code will still work. I think I can refactor this to make it work with one if statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

@@ -0,0 +1,13 @@
#pragma once

#include <torch/types.h>
Copy link
Member

@fmassa fmassa Jan 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to start using a smart editor. I would have just #include <torch/torch.h> and brought everything in :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately that's not a smart editor feature but I wish they had that functionality too.

@datumbox datumbox merged commit 7621a8e into pytorch:master Jan 28, 2021
@datumbox datumbox deleted the refactor/image branch January 28, 2021 10:44
@datumbox datumbox mentioned this pull request Jan 28, 2021
13 tasks
facebook-github-bot pushed a commit that referenced this pull request Feb 2, 2021
Summary:
* Moving jpegcommon inside cpu implementation

* Adding namespaces on image and moving private methods to anonymous.

* Fixing headers.

* Renaming public image methods to match the ones on python.

* Refactoring to remove the double ifs in common_jpeg.h

Reviewed By: fmassa

Differential Revision: D26197738

fbshipit-source-id: a9d3ca2d8a248504fbe4bdfda94b6cbdda2270f1
jamt9000 added a commit to jamt9000/vision that referenced this pull request Feb 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants