def find_leaf(nodes, xi):
    """Find the leaf index containing the given features vector.

    Parameters
    ----------
    nodes : ndarray
        Array of nodes with shape (n_nodes,) with node_dtype dtype

    xi : ndarray
        Input features vector of shape (n_features,) with uint8 dtype

    Returns
    -------
    output : uintp
        Index of the leaf node containing the input features vector
    """
    idx_leaf = 0
    node = nodes[idx_leaf]
    while not node["is_leaf"]:
        if xi[node["feature"]] <= node["bin_threshold"]:
            idx_leaf = node["left_child"]
        else:
            idx_leaf = node["right_child"]
        node = nodes[idx_leaf]

    return idx_leaf