(node_map, leaf_sample_counts)
return new_node_map, sibling_node_map
Only keep the nodes with fewer sample and remove their siblings, for accelerating hist computation
Only keep the nodes with fewer sample and remove their siblings, for accelerating hist computation
Only keep the nodes with fewer sample and remove their siblings for accelerating hist computation
def _trim_node_map(node_map, leaf_sample_counts):

        """
        Only keep the nodes with fewer sample and remove their siblings, for accelerating hist computation
        """

        inverse_node_map = {v: k for k, v in node_map.items()}
        sibling_node_map = {}
        # if is root node, return directly
        if 0 in node_map:
            return node_map, None

        kept_node_id = []

        idx = 0
        for left_count, right_count in zip(leaf_sample_counts[0::2], leaf_sample_counts[1::2]):
            if left_count < right_count:
                kept_node_id.append(inverse_node_map[idx])
                sibling_node_map[inverse_node_map[idx]] = inverse_node_map[idx + 1]
            else:
                kept_node_id.append(inverse_node_map[idx + 1])
                sibling_node_map[inverse_node_map[idx + 1]] = inverse_node_map[idx]
            idx += 2

        new_node_map = {node_id: idx for idx, node_id in enumerate(kept_node_id)}

        return new_node_map, sibling_node_map
def _trim_node_map ( node_map , leaf_sample_counts ) : inverse_node_map = { v : k for k , v in node_map . items ( ) } sibling_node_map = { } # if is root node, return directly if 0 in node_map : return node_map , None kept_node_id = [ ] idx = 0 for left_count , right_count in zip ( leaf_sample_counts [ 0 : : 2 ] , leaf_sample_counts [ 1 : : 2 ] ) : if left_count < right_count : kept_node_id . append ( inverse_node_map [ idx ] ) sibling_node_map [ inverse_node_map [ idx ] ] = inverse_node_map [ idx + 1 ] else : kept_node_id . append ( inverse_node_map [ idx + 1 ] ) sibling_node_map [ inverse_node_map [ idx + 1 ] ] = inverse_node_map [ idx ] idx += 2 new_node_map = { node_id : idx for idx , node_id in enumerate ( kept_node_id ) } return new_node_map , sibling_node_map