Conversation
| 'Number: {} -- Actual: {} -- Prediction: {}'.format( | ||
| num, check_fizbuz(num), outli[hyp[i].max(0)[1].item()])) | ||
| f'Number: {num} -- Actual: {check_fizbuz(num)} -- Prediction: {outli[hyp[i].max(0)[1].item()]}' | ||
| ) |
There was a problem hiding this comment.
Lines 80-81 refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| b2 = torch.zeros(1, output_size, requires_grad=True, device=device, dtype=dtype) | ||
|
|
||
| no_of_batches = int(len(trX) / batches) | ||
| no_of_batches = len(trX) // batches |
There was a problem hiding this comment.
Lines 35-110 refactored with the following changes:
- Simplify division expressions (
simplify-division) - Replace call to format with f-string (
use-fstring-for-formatting)
| x_ = x[0:10] | ||
| y_ = y[0:10] | ||
| x_ = x[:10] | ||
| y_ = y[:10] |
There was a problem hiding this comment.
Lines 92-93 refactored with the following changes:
- Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] [×2] (
remove-redundant-slice-index)
| x_ = x[0:10] | ||
| y_ = y[0:10] | ||
| x_ = x[:10] | ||
| y_ = y[:10] |
There was a problem hiding this comment.
Lines 94-95 refactored with the following changes:
- Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] [×2] (
remove-redundant-slice-index)
| raise FileNotFoundError("Couldn't find 'labels' folder in {}".format(path)) | ||
| raise FileNotFoundError(f"Couldn't find 'labels' folder in {path}") | ||
| self.files = [] | ||
| for file in input_files: | ||
| name, ext = os.path.splitext(file) | ||
| input_file = os.path.join(inputdir_path, file) | ||
| label_file = os.path.join(labledir_path, '{}_L{}'.format(name, ext)) | ||
| label_file = os.path.join(labledir_path, f'{name}_L{ext}') |
There was a problem hiding this comment.
Function CamvidDataSet.__init__ refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting)
|
|
||
| model.train() | ||
| for epoch in range(epochs): | ||
| for _ in range(epochs): |
There was a problem hiding this comment.
Lines 76-101 refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore) - Remove unnecessary calls to
enumeratewhen the index is not used (remove-unused-enumerate)
| super().__init__() | ||
| self.res_blocks = torch.nn.ModuleList() | ||
| for s in range(stack_size): | ||
| for _ in range(stack_size): |
There was a problem hiding this comment.
Function ResidualStack.__init__ refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| decoded = np.argmax(data, axis=axis) | ||
|
|
||
| return decoded | ||
| return np.argmax(data, axis=axis) |
There was a problem hiding this comment.
Function one_hot_decode refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| waveform = np.sign(expanded) * (np.exp(np.abs(expanded) * np.log(mu + 1)) - 1) / mu | ||
|
|
||
| return waveform | ||
| return np.sign(expanded) * (np.exp(np.abs(expanded) * np.log(mu + 1)) - 1) / mu |
There was a problem hiding this comment.
Function mu_law_decode refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| self.filenames = [x for x in sorted(os.listdir(data_dir))] | ||
| self.filenames = list(sorted(os.listdir(data_dir))) |
There was a problem hiding this comment.
Function Dataset.__init__ refactored with the following changes:
- Replace identity comprehension with call to collection constructor (
identity-comprehension)
| return self.sample_size if len(audio[0]) >= self.sample_size\ | ||
| else len(audio[0]) | ||
| return min(len(audio[0]), self.sample_size) |
There was a problem hiding this comment.
Function DataLoader.calc_sample_size refactored with the following changes:
- Replace comparison with min/max call (
min-max-identity)
| self.files_A = sorted(glob.glob(os.path.join(root, '%sA' % mode) + '/*.*')) | ||
| self.files_B = sorted(glob.glob(os.path.join(root, '%sB' % mode) + '/*.*')) | ||
| self.files_A = sorted(glob.glob(f"{os.path.join(root, f'{mode}A')}/*.*")) | ||
| self.files_B = sorted(glob.glob(f"{os.path.join(root, f'{mode}B')}/*.*")) |
There was a problem hiding this comment.
Function ImageDataset.__init__ refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation) - Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring)
| elif random.uniform(0, 1) > 0.5: | ||
| i = random.randint(0, self.max_size - 1) | ||
| to_return.append(self.data[i].clone()) | ||
| self.data[i] = element | ||
| else: | ||
| if random.uniform(0, 1) > 0.5: | ||
| i = random.randint(0, self.max_size - 1) | ||
| to_return.append(self.data[i].clone()) | ||
| self.data[i] = element | ||
| else: | ||
| to_return.append(element) | ||
| to_return.append(element) |
There was a problem hiding this comment.
Function ReplayBuffer.push_and_pop refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif)
| for epoch in range(opt.epoch, opt.n_epochs): | ||
| for i, batch in enumerate(dataloader): | ||
| for _ in range(opt.epoch, opt.n_epochs): | ||
| for batch in dataloader: |
There was a problem hiding this comment.
Lines 319-320 refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore) - Remove unnecessary calls to
enumeratewhen the index is not used (remove-unused-enumerate)
| parser.add_argument('--size', type=int, default=256, help='crop to this size') | ||
| args = parser.parse_args(args=[]) | ||
| return args | ||
| return parser.parse_args(args=[]) |
There was a problem hiding this comment.
Function get_args refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| data_names = [] | ||
| data_shapes = [] |
There was a problem hiding this comment.
Function MXNetModelService.initialize refactored with the following changes:
- Move assignment closer to its usage within a block [×2] (
move-assign-in-block) - Replace call to format with f-string (
use-fstring-for-formatting) - Merge append into list declaration [×2] (
merge-list-append)
| data = batch[0].get('body').get(param_name) | ||
| if data: | ||
| if data := batch[0].get('body').get(param_name): | ||
| self.input = data + 1 | ||
| tensor = mx.nd.array([self.binary_encoder(self.input, input_size=10)]) | ||
| return tensor | ||
| return mx.nd.array([self.binary_encoder(self.input, input_size=10)]) |
There was a problem hiding this comment.
Function MXNetModelService.preprocess refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| out = [{'next_number': prediction}] | ||
| return out | ||
| return [{'next_number': prediction}] |
There was a problem hiding this comment.
Function MXNetModelService.postprocess refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| return input_num | ||
| else: | ||
| return input_output_map[prediction] | ||
| return input_num if prediction == 3 else input_output_map[prediction] |
There was a problem hiding this comment.
Function get_readable_output refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| output_dist = output.squeeze().div(0.8).exp() | ||
| prob = torch.multinomial(output_dist, 2) | ||
| return prob | ||
| return torch.multinomial(output_dist, 2) |
There was a problem hiding this comment.
Function post_processing refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
Branch
masterrefactored 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
masterbranch, then run:Help us improve this pull request!