-
Notifications
You must be signed in to change notification settings - Fork 0
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
Sourcery refactored main branch #1
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to GitHub API limits, only the first 60 comments can be shown.
solver = solvers.get_solver(cfg) | ||
return solver | ||
return solvers.get_solver(cfg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get_solver
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
assert load_best is True | ||
assert load_best |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get_solver_from_xp
refactored with the following changes:
- Simplify comparison to boolean (
simplify-boolean-comparison
)
destination[prefix + 'optimizer'] = self.optimizer.state_dict() | ||
destination[f'{prefix}optimizer'] = self.optimizer.state_dict() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function AdversarialLoss._save_to_state_dict
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
self.optimizer.load_state_dict(state_dict.pop(prefix + 'optimizer')) | ||
self.optimizer.load_state_dict(state_dict.pop(f'{prefix}optimizer')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function AdversarialLoss._load_from_state_dict
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
assert isinstance(logits, list) and all([isinstance(t, torch.Tensor) for t in logits]), \ | ||
f'Expecting a list of tensors as logits but {type(logits)} found.' | ||
assert isinstance(logits, list) and all( | ||
isinstance(t, torch.Tensor) for t in logits | ||
), f'Expecting a list of tensors as logits but {type(logits)} found.' | ||
assert isinstance(fmaps, list), f'Expecting a list of features maps but {type(fmaps)} found.' | ||
for fmap in fmaps: | ||
assert isinstance(fmap, list) and all([isinstance(f, torch.Tensor) for f in fmap]), \ | ||
f'Expecting a list of tensors as feature maps but {type(fmap)} found.' | ||
assert isinstance(fmap, list) and all( | ||
isinstance(f, torch.Tensor) for f in fmap | ||
), f'Expecting a list of tensors as feature maps but {type(fmap)} found.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function AdversarialLoss.get_adversary_pred
refactored with the following changes:
- Replace unneeded comprehension with generator [×2] (
comprehension-to-generator
)
max_len = max([wav.shape[-1] for wav, _ in samples]) | ||
max_len = max(wav.shape[-1] for wav, _ in samples) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function AudioDataset.collater
refactored with the following changes:
- Replace unneeded comprehension with generator (
comprehension-to-generator
)
if strategy == 'peak': | ||
if strategy == 'clip': | ||
wav = wav.clamp(-scale_peak, scale_peak) | ||
elif strategy == 'loudness': | ||
assert sample_rate is not None, "Loudness normalization requires sample rate." | ||
wav = normalize_loudness(wav, sample_rate, loudness_headroom_db, loudness_compressor) | ||
_clip_wav(wav, log_clipping=log_clipping, stem_name=stem_name) | ||
elif strategy == 'peak': | ||
rescaling = (scale_peak / wav.abs().max()) | ||
if normalize or rescaling < 1: | ||
wav = wav * rescaling | ||
elif strategy == 'clip': | ||
wav = wav.clamp(-scale_peak, scale_peak) | ||
elif strategy == 'rms': | ||
mono = wav.mean(dim=0) | ||
rescaling = scale_rms / mono.pow(2).mean().sqrt() | ||
if normalize or rescaling < 1: | ||
wav = wav * rescaling | ||
_clip_wav(wav, log_clipping=log_clipping, stem_name=stem_name) | ||
elif strategy == 'loudness': | ||
assert sample_rate is not None, "Loudness normalization requires sample rate." | ||
wav = normalize_loudness(wav, sample_rate, loudness_headroom_db, loudness_compressor) | ||
_clip_wav(wav, log_clipping=log_clipping, stem_name=stem_name) | ||
else: | ||
assert wav.abs().max() < 1 | ||
assert strategy == '' or strategy == 'none', f"Unexpected strategy: '{strategy}'" | ||
assert strategy in {'', 'none'}, f"Unexpected strategy: '{strategy}'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function normalize_audio
refactored with the following changes:
- Simplify conditional into switch-like form [×3] (
switch
) - Replace multiple comparisons of same variable with
in
operator (merge-comparisons
) - Use set when checking membership of a collection of literals (
collection-into-set
)
if len(kw_list) == 0: | ||
return None | ||
else: | ||
return kw_list | ||
return None if not kw_list else kw_list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get_keyword_list
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Simplify sequence length comparison (
simplify-len-comparison
)
preprocess_func = get_bpm | ||
return get_bpm | ||
elif attribute == 'key': | ||
preprocess_func = get_musical_key | ||
return get_musical_key | ||
elif attribute in ['moods', 'keywords']: | ||
preprocess_func = get_keyword_list | ||
return get_keyword_list | ||
elif attribute in ['genre', 'name', 'instrument']: | ||
preprocess_func = get_keyword | ||
return get_keyword | ||
elif attribute in ['title', 'artist', 'description']: | ||
preprocess_func = get_string | ||
return get_string | ||
else: | ||
preprocess_func = None | ||
return preprocess_func | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function MusicInfo.attribute_getter
refactored with the following changes:
- Lift return into if (
lift-return-into-if
)
if attribute == 'description': | ||
preprocess_func = get_keyword_or_keyword_list | ||
else: | ||
preprocess_func = None | ||
return preprocess_func | ||
return get_keyword_or_keyword_list if attribute == 'description' else None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function SoundInfo.attribute_getter
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
Branch
main
refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
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
main
branch, then run:Help us improve this pull request!