Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

MiniGo style pass and and minor logic enhancements. #131

Merged
merged 7 commits into from
Apr 29, 2019

Conversation

rxwei
Copy link
Contributor

@rxwei rxwei commented Apr 28, 2019

Logic changes:

  • In LibertyTracker.swift, use dictionary indices to avoid force unwrapping. Removed a lot of bangs!
  • Make ModelConfiguration.boardSize public since the initializer takes a boardSize for better transparency. It's a little weird for an initializer to take a constant, store it and make it private.
  • Reduce nesting in LibertyTracker.updateLibertiesAfterRemovingCapturedStones(_:) with compactMap(_:).
  • Simplify assignNewGroupID() with a defer block.

Formatting changes:

  • Make every file end with exactly 1 empty line.
  • Add some minor comments.
  • Remove empty lines between the start of a type declaration or extension and the first declaration for consistency.
  • Make GoModel code fit within 100 columns.

rxwei added 2 commits April 28, 2019 05:02
- Rename `InferenceModel`'s `prediction(input:)` to `prediction(for:)`.
- Rename `GoModel._vjpApplied(to:)` to `GoModel._vjpCall(_:)`.
- Minor formatting changes.
@rxwei rxwei added the enhancement New feature or request label Apr 28, 2019
@rxwei rxwei requested review from xiejw and jekbradbury April 28, 2019 20:52
@rxwei
Copy link
Contributor Author

rxwei commented Apr 29, 2019

Thanks, merging now. @xiejw, let me know if you have any comments!

@rxwei rxwei merged commit a7e4c7a into tensorflow:master Apr 29, 2019
@rxwei rxwei deleted the minigo-cleanup branch April 29, 2019 01:52
Copy link
Contributor

@xiejw xiejw left a comment

Choose a reason for hiding this comment

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

Thanks rxwei@. Mostly look good to me.

Just few style nits to discuss.

borders.allSatisfy { self.color(at: $0) != nil },
"borders cannot have empty positions.")
precondition(territory.allSatisfy { self.color(at: $0) == nil },
"territory must be all empty (no stones).")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I am personally OK with this style. But Google swift style guide does not allow this (I maybe misread the guide).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's a very reasonable style, and I don't think the Google Swift Style Guide explicitly bans this (https://google.github.io/swift/#function-calls).

@@ -51,7 +48,8 @@ let mctsConfiguration = MCTSConfiguration(
try playOneGame(
gameConfiguration: gameConfiguration,
participants: [
MCTSPolicy(participantName: "black", predictor: predictor, configuration: mctsConfiguration),
MCTSPolicy(participantName: "white", predictor: predictor, configuration: mctsConfiguration),
MCTSPolicy(participantName: "black", predictor: predictor,
Copy link
Contributor

Choose a reason for hiding this comment

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

is one argument per line better and more readable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was mainly making things fit within 100 columns, so configuration: got wrapped. Since the code is pretty compact, one argument per line could be better but probably won't make a huge difference.

// the value in the groups is struct. We need the force unwrap to do
// mutation in place.
groups[neighborGroupdID]!.liberties.insert(capturedStone)
for neighborGroupID in capturedStone.neighbors(boardSize: size).compactMap(groupIndex) {
Copy link
Contributor

Choose a reason for hiding this comment

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

just curious: groupIndex is a function expecting argument "for:". But compactMap expects a transform with argument "_", right? How does that work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Argument labels are not formally part of a function's type signature. This is the result of SE-0111.

@rxwei
Copy link
Contributor Author

rxwei commented Apr 30, 2019

Thanks @xiejw for reviewing!

pschuh pushed a commit to pschuh/swift-models that referenced this pull request Jul 30, 2019
Broadcasting does not support 8-D tensors.
Copy Keras implementation: simulating broadcasting via splitting, duplication, and concatenation.

Resolves [TF-525](https://bugs.swift.org/browse/TF-525).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants