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

Sourcery refactored main branch #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Aug 5, 2023

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:

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

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from ludoplex August 5, 2023 09:44
Copy link
Author

@sourcery-ai sourcery-ai bot left a 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)
Copy link
Author

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:

Comment on lines -78 to +77
assert load_best is True
assert load_best
Copy link
Author

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:

destination[prefix + 'optimizer'] = self.optimizer.state_dict()
destination[f'{prefix}optimizer'] = self.optimizer.state_dict()
Copy link
Author

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:

self.optimizer.load_state_dict(state_dict.pop(prefix + 'optimizer'))
self.optimizer.load_state_dict(state_dict.pop(f'{prefix}optimizer'))
Copy link
Author

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:

Comment on lines -81 to +88
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.'
Copy link
Author

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:

Comment on lines -473 to +467
max_len = max([wav.shape[-1] for wav, _ in samples])
max_len = max(wav.shape[-1] for wav, _ in samples)
Copy link
Author

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:

Comment on lines -126 to +144
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}'"
Copy link
Author

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
Copy link
Author

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:

Comment on lines -78 to +88
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
Copy link
Author

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:

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
Copy link
Author

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:

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.

0 participants