# Buggy code
def get_tree_implementation_by_config_or_depth(extra_config, max_depth, low=3, high=10):
    """
    Utility function used to pick the tree implementation based on input parameters and heurstics.
    The current heuristic is such that GEMM <= low < PerfTreeTrav <= high < TreeTrav
    Args:
        max_depth: The maximum tree-depth found in the tree model.
        low: The maximum depth below which GEMM strategy is used
        high: The maximum depth for which PerfTreeTrav strategy is used

    Returns: A tree implementation
    """
    if constants.TREE_IMPLEMENTATION not in extra_config:
        if max_depth is not None and max_depth <= low:
            return TreeImpl.gemm
        elif max_depth is not None and max_depth <= high:
            return TreeImpl.perf_tree_trav
        else:
            return TreeImpl.tree_trav

    if extra_config[constants.TREE_IMPLEMENTATION] == TreeImpl.gemm.name:
        return TreeImpl.gemm
    elif extra_config[constants.TREE_IMPLEMENTATION] == TreeImpl.tree_trav.name:
        return TreeImpl.tree_trav
    elif extra_config[constants.TREE_IMPLEMENTATION] == TreeImpl.perf_tree_trav.name:
        return TreeImpl.perf_tree_trav
    else:
        raise ValueError("Tree implementation {} not found".format(extra_config))


# Traceback (ValueError)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~/anaconda3/envs/p37/lib/python3.7/site-packages/hummingbird/ml/_topology.py in convert(topology, backend, test_input, device, extra_config)
162
--> 163             operator_map[operator.full_name] = converter(operator, device, extra_config)
164         except ValueError:

~/anaconda3/envs/p37/lib/python3.7/site-packages/hummingbird/ml/operator_converters/sklearn/decision_tree.py in convert_sklearn_random_forest_classifier(operator, device, extra_config)
45     return convert_decision_ensemble_tree_common(
---> 46         tree_infos, get_parameters_for_sklearn_common, get_parameters_for_tree_trav_sklearn, n_features, classes, extra_config
47     )

~/anaconda3/envs/p37/lib/python3.7/site-packages/hummingbird/ml/operator_converters/_tree_commons.py in convert_decision_ensemble_tree_common(tree_infos, get_parameters, get_parameters_for_tree_trav, n_features, classes, extra_config)
407         )
--> 408         for tree_param in tree_parameters
409     ]

~/anaconda3/envs/p37/lib/python3.7/site-packages/hummingbird/ml/operator_converters/_tree_commons.py in <listcomp>(.0)
407         )
--> 408         for tree_param in tree_parameters
409     ]

~/anaconda3/envs/p37/lib/python3.7/site-packages/hummingbird/ml/operator_converters/_tree_commons.py in get_parameters_for_tree_trav_sklearn(lefts, rights, features, thresholds, values, extra_config)
276
--> 277     return get_parameters_for_tree_trav_common(lefts, rights, features, thresholds, values)
278

~/anaconda3/envs/p37/lib/python3.7/site-packages/hummingbird/ml/operator_converters/_tree_commons.py in get_parameters_for_tree_trav_common(lefts, rights, features, thresholds, values, extra_config)
208         values = np.array([np.array([0.0]), values[0], values[0]])
--> 209         values.reshape(3, n_classes)
210

ValueError: cannot reshape array of size 3 into shape (3,2)

During handling of the above exception, another exception occurred:

MissingConverter                          Traceback (most recent call last)
<ipython-input-2-70faf2a01f51> in <module>
10 clf = RandomForestClassifier(random_state=seed)
11 clf.fit(X, y)
---> 12 model = hummingbird.ml.convert(clf, "torch")

~/anaconda3/envs/p37/lib/python3.7/site-packages/hummingbird/ml/convert.py in convert(model, backend, test_input, device, extra_config)
429     """
430     assert constants.REMAINDER_SIZE not in extra_config
--> 431     return _convert_common(model, backend, test_input, device, extra_config)
432
433

~/anaconda3/envs/p37/lib/python3.7/site-packages/hummingbird/ml/convert.py in _convert_common(model, backend, test_input, device, extra_config)
390         return _convert_sparkml(model, backend, test_input, device, extra_config)
391
--> 392     return _convert_sklearn(model, backend, test_input, device, extra_config)
393
394

~/anaconda3/envs/p37/lib/python3.7/site-packages/hummingbird/ml/convert.py in _convert_sklearn(model, backend, test_input, device, extra_config)
98
99     # Convert the Topology object into a PyTorch model.
--> 100     hb_model = topology_converter(topology, backend, test_input, device, extra_config=extra_config)
101     return hb_model
102

~/anaconda3/envs/p37/lib/python3.7/site-packages/hummingbird/ml/_topology.py in convert(topology, backend, test_input, device, extra_config)
165             raise MissingConverter(
166                 "Unable to find converter for {} type {} with extra config: {}.".format(
--> 167                     operator.type, type(getattr(operator, "raw_model", None)), extra_config
168                 )
169             )

MissingConverter: Unable to find converter for SklearnRandomForestClassifier type <class 'NoneType'> with extra config: {'container': True, 'n_threads': 10, 'n_trees': 100}.
It usually means the pipeline being converted contains a
transformer or a predictor with no corresponding converter implemented.
Please fill an issue at https://github.com/microsoft/hummingbird.

# Fixed code
def get_tree_implementation_by_config_or_depth(extra_config, max_depth, low=3, high=10):
    """
    Utility function used to pick the tree implementation based on input parameters and heurstics.
    The current heuristic is such that GEMM <= low < PerfTreeTrav <= high < TreeTrav
    Args:
        max_depth: The maximum tree-depth found in the tree model.
        low: The maximum depth below which GEMM strategy is used
        high: The maximum depth for which PerfTreeTrav strategy is used

    Returns: A tree implementation
    """
    if constants.TREE_IMPLEMENTATION not in extra_config:
        if max_depth is not None and max_depth <= low:
            return TreeImpl.gemm
        elif max_depth is not None and max_depth <= high:
            return TreeImpl.perf_tree_trav
        else:
            return TreeImpl.tree_trav

    if extra_config[constants.TREE_IMPLEMENTATION] == TreeImpl.gemm.name:
        return TreeImpl.gemm
    elif extra_config[constants.TREE_IMPLEMENTATION] == TreeImpl.tree_trav.name:
        return TreeImpl.tree_trav
    elif extra_config[constants.TREE_IMPLEMENTATION] == TreeImpl.perf_tree_trav.name:
        return TreeImpl.perf_tree_trav
    else:
        raise MissingConverter("Tree implementation {} not found".format(extra_config))