Skip to content

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Nov 17, 2022

Pull Request #1 refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

NOTE: As code is pushed to the original Pull Request, Sourcery will
re-run and update (force-push) this Pull Request with new refactorings as
necessary. If Sourcery finds no refactorings at any point, this Pull Request
will be closed automatically.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the benchmarks-Python branch, then run:

git fetch origin sourcery/benchmarks-Python
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from 1Deavon November 17, 2022 03:28
x = self.fc2(x)
output = F.log_softmax(x, dim=1)
return output
return F.log_softmax(x, dim=1)
Copy link
Author

Choose a reason for hiding this comment

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

Function Net.forward refactored with the following changes:

train_kwargs.update(cuda_kwargs)
test_kwargs.update(cuda_kwargs)
train_kwargs |= cuda_kwargs
test_kwargs |= cuda_kwargs
Copy link
Author

Choose a reason for hiding this comment

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

Function main refactored with the following changes:

in_dim = 1
else:
in_dim = 3
in_dim = 1 if grayscale else 3
Copy link
Author

Choose a reason for hiding this comment

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

Function ResNet.__init__ refactored with the following changes:

Comment on lines -144 to +143
layers = []
layers.append(block(self.inplanes, planes, stride, downsample))
layers = [block(self.inplanes, planes, stride, downsample)]
self.inplanes = planes * block.expansion
for i in range(1, blocks):
layers.append(block(self.inplanes, planes))

layers.extend(block(self.inplanes, planes) for _ in range(1, blocks))
Copy link
Author

Choose a reason for hiding this comment

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

Function ResNet._make_layer refactored with the following changes:

Comment on lines -173 to +172
model = ResNet(block=BasicBlock,
layers=[2, 2, 2, 2],
num_classes=NUM_CLASSES,
grayscale=GRAYSCALE)
return model
return ResNet(
block=BasicBlock,
layers=[2, 2, 2, 2],
num_classes=NUM_CLASSES,
grayscale=GRAYSCALE,
)
Copy link
Author

Choose a reason for hiding this comment

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

Function resnet18 refactored with the following changes:

Comment on lines -189 to +184
for i, (features, targets) in enumerate(data_loader):

for features, targets in data_loader:
Copy link
Author

Choose a reason for hiding this comment

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

Function compute_accuracy refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Nov 17, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.28%.

Quality metrics Before After Change
Complexity 3.69 ⭐ 3.58 ⭐ -0.11 👍
Method Length 115.16 🙂 114.00 🙂 -1.16 👍
Working memory 7.69 🙂 7.61 🙂 -0.08 👍
Quality 64.53% 🙂 64.81% 🙂 0.28% 👍
Other metrics Before After Change
Lines 364 357 -7
Changed files Quality Before Quality After Quality Change
Pytorch_MNIST.py 59.40% 🙂 59.23% 🙂 -0.17% 👎
Pytorch_ResNet.py 69.01% 🙂 69.85% 🙂 0.84% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
Pytorch_MNIST.py main 8 ⭐ 518 ⛔ 10 😞 42.30% 😞 Try splitting into smaller methods. Extract out complex expressions
Pytorch_ResNet.py ResNet.__init__ 5 ⭐ 251 ⛔ 8 🙂 54.53% 🙂 Try splitting into smaller methods
Pytorch_MNIST.py train 6 ⭐ 143 😞 11 😞 55.84% 🙂 Try splitting into smaller methods. Extract out complex expressions
Pytorch_MNIST.py test 1 ⭐ 132 😞 8 🙂 68.20% 🙂 Try splitting into smaller methods

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant