Skip to content

Formatting & formatting guidelines#27

Merged
cshewmake2 merged 22 commits intomainfrom
formatting
Jun 1, 2022
Merged

Formatting & formatting guidelines#27
cshewmake2 merged 22 commits intomainfrom
formatting

Conversation

@belsten
Copy link
Collaborator

@belsten belsten commented May 15, 2022

No description provided.

@belsten belsten requested review from 9q9q and cshewmake2 May 15, 2022 00:54
@alvinz-matician
Copy link

autopep8?

Copy link
Collaborator

@9q9q 9q9q left a comment

Choose a reason for hiding this comment

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

thanks alex!! just a few small comments

@belsten
Copy link
Collaborator Author

belsten commented May 16, 2022

@alvinz-matician I'm unfamiliar with autopep8. Would this be something that would be locally run before pushing code, or automated through github actions?

@alvinz-matician
Copy link

It's a Python auto-formatter for PEP8 standards, I just wanted to put it on your radar. I was thinking that it could be nice to add as a PR check in GitHub actions.

@9q9q
Copy link
Collaborator

9q9q commented May 20, 2022

from a quick search, it looks like flake8 wraps a few things including pyflakes (statically checks for logical errors) and pycodestyle (formerly pep8).
autopep8 does automatic formatting according to pep8.
would be cool to have both but if we have to pick one to start with maybe flake8? action: https://github.com/py-actions/flake8

@alvinzz alvinzz force-pushed the formatting branch 2 times, most recently from 936c04b to a49b3ee Compare May 23, 2022 18:37
@alvinzz alvinzz requested a review from 9q9q May 23, 2022 18:48
@belsten
Copy link
Collaborator Author

belsten commented May 24, 2022

All new changes look good to me.

Copy link
Contributor

@cshewmake2 cshewmake2 left a comment

Choose a reason for hiding this comment

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

Overall, amazing work. Review comments about broken imports from torchsmodel and the placement of the extract_patches function.


def whiten_dataset(dataset,plot=False,title='',n_comp=-1):
def whiten_dataset(dataset, plot=False, title='', n_comp=-1):
from torchsmodel import sparsecoding
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove import

Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't in the repo. I think it's code from your previous implementation @belsten. It's called later in the code too. How is it passing tests? Are you perhaps not calling this function?

def whiten_dataset(dataset,plot=False,title='',n_comp=-1):
def whiten_dataset(dataset, plot=False, title='', n_comp=-1):
from torchsmodel import sparsecoding
from utils import plotmontage
Copy link
Contributor

Choose a reason for hiding this comment

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

Move to the top with the other imports.



def nptotorch(x,device=torch.device('cpu'),dtype=np.float32):
def nptotorch(x, device=torch.device('cpu'), dtype=np.float32):
Copy link
Contributor

Choose a reason for hiding this comment

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

nptotorch -> np_to_torch

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this function?
You can also say
torch.tensor(v, device=device, dtype=dtype)

See torch.torch
https://pytorch.org/docs/stable/generated/torch.tensor.html

# NATURAL IMAGES
## ================================================================================
# ================================================================================
class naturalscenes(Dataset):
Copy link
Contributor

Choose a reason for hiding this comment

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

Class names should be capitalized.
class NaturalScenes(Dataset):
...


return self.patches[idx, :]

def extractpatches(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

This function will be generally useful beyond just NaturalScenes. We can go ahead and include this in the merge, but I think we should instead put this into a data utils module, then import it for use here rather than defining it within the NaturalScenes class.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, the name should be snake case:
def extract_patches

plotmontage(model, color=True, size=10, title=title)

# whiten
trotpatch = (nptotorch(v, device=dataset.device).t()@dataset.patches.t()).t()
Copy link
Contributor

Choose a reason for hiding this comment

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

variable names should follow snake-case convention.
t_rot_patch

@alvinz-matician
Copy link

I'm rewriting the natural scenes and patches stuff in #30 so IMO it's fine for now. At least until we have a writeup I don't think we'll have too much external traffic.

@cshewmake2
Copy link
Contributor

Yep. Realized that after I looked at #30. Thanks!

@belsten
Copy link
Collaborator Author

belsten commented May 30, 2022

Can these requests be resolved so we can merge this branch?

@cshewmake2 cshewmake2 merged commit a50ce3b into main Jun 1, 2022
@cshewmake2 cshewmake2 deleted the formatting branch June 1, 2022 21:17
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.

5 participants