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

Flipping Latent Pixels #15

Merged
merged 3 commits into from
Apr 24, 2024
Merged

Flipping Latent Pixels #15

merged 3 commits into from
Apr 24, 2024

Conversation

Xmaster6y
Copy link
Owner

No description provided.

Copy link
Contributor

@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.

Hey @Xmaster6y - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 5 issues found
  • 🟢 Security: all looks good
  • 🟡 Testing: 2 issues found
  • 🟢 Complexity: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

Comment on lines +145 to +148
if self.config.data is not None:
measure_data = self.config.data[name]
else:
measure_data = None
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code_refinement): Consider refactoring to avoid code duplication.

The conditional block for setting 'measure_data' is repeated in both hook definitions. Consider extracting this to a method to reduce duplication and improve maintainability.

Suggested change
if self.config.data is not None:
measure_data = self.config.data[name]
else:
measure_data = None
def get_measure_data(self, name):
if self.config.data is not None:
return self.config.data[name]
return None
def hook(module, input, output):
measure_data = self.get_measure_data(name)

Comment on lines 59 to +62
for move in board.legal_moves
]
legal_move_mask[idx, legal_moves] = 1
return legal_move_mask * board_tensor
return legal_move_mask * out_tensor
Copy link
Contributor

Choose a reason for hiding this comment

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

question (code_clarification): Variable renaming should maintain clarity.

The renaming of 'board_tensor' to 'out_tensor' should be clearly justified if it's meant to reflect a broader usage or a different kind of tensor than originally implemented.

Comment on lines 194 to +198
self.boards.append(board)
self.game_ids.append(obj["gameid"])
self.labels.append(obj["label"])
if first_n is not None and len(self.boards) >= first_n:
break
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code_refinement): Addition of 'first_n' parameter for early loop exit.

The introduction of 'first_n' to limit the number of processed items is a useful feature. Ensure that this behavior is documented, especially how it interacts with the rest of the data processing pipeline.

Suggested change
self.boards.append(board)
self.game_ids.append(obj["gameid"])
self.labels.append(obj["label"])
if first_n is not None and len(self.boards) >= first_n:
break
first_n: Optional[int] = None,
):
if file_name is None:
super().__init__(file_name, boards, game_ids)
self.boards.append(board)
self.game_ids.append(obj["gameid"])
self.labels.append(obj["label"])
if first_n is not None and len(self.boards) >= first_n:
break

Comment on lines +145 to +148
if self.config.data is not None:
measure_data = self.config.data[name]
else:
measure_data = None
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (testing): No tests covering the refactored conditional logic in hooks.

The conditional logic for setting 'measure_data' based on 'self.config.data' has been moved inside the hook definitions. This change in the control flow could affect when and how 'measure_data' is set during the execution of hooks. It's important to have tests that specifically verify that 'measure_data' is correctly assigned in both 'INPUT' and 'OUTPUT' hook modes under various configurations.

Comment on lines +182 to +184
raise NotImplementedError(
"Input hook not implemented for ModifyHook"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (testing): Test needed for NotImplementedError in ModifyHook.

The addition of a NotImplementedError when 'HookMode.INPUT' is selected in 'ModifyHook' is a significant change. There should be a test to ensure that this exception is raised as expected when the input hook mode is used, which helps in validating that the system behaves correctly in response to unsupported configurations.

Comment on lines +57 to +60
if modify_data is None:
return output
else:
return output * modify_data
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code-quality): Replace if statement with if expression (assign-if-exp)

Suggested change
if modify_data is None:
return output
else:
return output * modify_data
return output if modify_data is None else output * modify_data

if self.config.hook_mode is HookMode.INPUT:

def hook(module, input, output):
if self.config.data is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): Replace if statement with if expression [×2] (assign-if-exp)

Comment on lines +189 to +192
if self.config.data is not None:
modify_data = self.config.data[name]
else:
modify_data = None
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code-quality): Replace if statement with if expression (assign-if-exp)

Suggested change
if self.config.data is not None:
modify_data = self.config.data[name]
else:
modify_data = None
modify_data = self.config.data[name] if self.config.data is not None else None

@Xmaster6y Xmaster6y merged commit d6c5011 into main Apr 24, 2024
1 check passed
@Xmaster6y Xmaster6y deleted the flipping branch April 24, 2024 15:43
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