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

Reduce tree expand boilerplate code #4008

Merged
merged 1 commit into from
Dec 20, 2018
Merged

Conversation

RAMitchell
Copy link
Member

@RAMitchell RAMitchell commented Dec 19, 2018

This PR reduces the below code, used in various updater algorithms into a single line. This reduces boilerplate code and increases safety. Before you could add child nodes without any split in the parent node.

p_tree->AddChilds(nid);
(*p_tree)[nid].SetSplit(e.best.SplitIndex(), e.best.split_value, e.best.DefaultLeft());
// mark right child as 0, to indicate fresh leaf
(*p_tree)[(*p_tree)[nid].LeftChild()].SetLeaf(0.0f, 0);
(*p_tree)[(*p_tree)[nid].RightChild()].SetLeaf(0.0f, 0);

New code:

p_tree->ExpandNode(nid, e.best.SplitIndex(), e.best.split_value, e.best.DefaultLeft());

Copy link
Member

@trivialfis trivialfis left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@RAMitchell RAMitchell merged commit f75a21a into dmlc:master Dec 20, 2018
CodingCat pushed a commit to CodingCat/xgboost that referenced this pull request Jan 6, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Mar 20, 2019
@RAMitchell RAMitchell deleted the tree-simplify branch April 19, 2022 12:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants