Skip to content

Commit

Permalink
Add back Clone() method to the Tree class (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
hcho3 authored Dec 17, 2020
1 parent 9fb79c3 commit deed6c7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/treelite/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ class Tree {
Tree(Tree&&) noexcept = default;
Tree& operator=(Tree&&) noexcept = default;

inline Tree<ThresholdType, LeafOutputType> Clone() const;

inline const char* GetFormatStringForNode();
inline void GetPyBuffer(std::vector<PyBufferFrame>* dest);
inline void InitFromPyBuffer(std::vector<PyBufferFrame>::iterator begin,
Expand Down
13 changes: 13 additions & 0 deletions include/treelite/tree_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,19 @@ inline void InitScalarFromPyBuffer(T* scalar, PyBufferFrame buffer) {
*scalar = *t;
}

template <typename ThresholdType, typename LeafOutputType>
inline Tree<ThresholdType, LeafOutputType>
Tree<ThresholdType, LeafOutputType>::Clone() const {
Tree<ThresholdType, LeafOutputType> tree;
tree.num_nodes = num_nodes;
tree.nodes_ = nodes_.Clone();
tree.leaf_vector_ = leaf_vector_.Clone();
tree.leaf_vector_offset_ = leaf_vector_offset_.Clone();
tree.matching_categories_ = matching_categories_.Clone();
tree.matching_categories_offset_ = matching_categories_offset_.Clone();
return tree;
}

template <typename ThresholdType, typename LeafOutputType>
inline const char*
Tree<ThresholdType, LeafOutputType>::GetFormatStringForNode() {
Expand Down

0 comments on commit deed6c7

Please sign in to comment.