10 #include <dmlc/serializer.h> 13 namespace serializer {
18 uint64_t sz =
static_cast<uint64_t
>(data.Size());
20 strm->Write(data.Data(), sz *
sizeof(T));
25 bool status = strm->Read(&sz);
30 return strm->Read(data->Data(), sz *
sizeof(T));
39 template <
typename ThresholdType,
typename LeafOutputType>
40 void Tree<ThresholdType, LeafOutputType>::ReferenceSerialize(dmlc::Stream* fo)
const {
42 fo->Write(leaf_vector_);
43 fo->Write(leaf_vector_offset_);
44 fo->Write(matching_categories_);
45 fo->Write(matching_categories_offset_);
46 uint64_t sz =
static_cast<uint64_t
>(nodes_.Size());
48 fo->Write(nodes_.Data(), sz *
sizeof(Tree::Node));
51 CHECK_EQ(nodes_.Size(), num_nodes);
52 CHECK_EQ(nodes_.Size() + 1, leaf_vector_offset_.Size());
53 CHECK_EQ(leaf_vector_offset_.Back(), leaf_vector_.Size());
54 CHECK_EQ(nodes_.Size() + 1, matching_categories_offset_.Size());
55 CHECK_EQ(matching_categories_offset_.Back(), matching_categories_.Size());
58 template <
typename ThresholdType,
typename LeafOutputType>
59 void ModelImpl<ThresholdType, LeafOutputType>::ReferenceSerialize(dmlc::Stream* fo)
const {
60 fo->Write(num_feature);
61 fo->Write(static_cast<uint8_t>(task_type));
62 fo->Write(average_tree_output);
63 fo->Write(&task_param,
sizeof(task_param));
64 fo->Write(¶m,
sizeof(param));
65 uint64_t sz =
static_cast<uint64_t
>(trees.size());
67 for (
const Tree<ThresholdType, LeafOutputType>& tree : trees) {
68 tree.ReferenceSerialize(fo);
72 template void Tree<float, uint32_t>::ReferenceSerialize(dmlc::Stream* fo)
const;
73 template void Tree<float, float>::ReferenceSerialize(dmlc::Stream* fo)
const;
74 template void Tree<double, uint32_t>::ReferenceSerialize(dmlc::Stream* fo)
const;
75 template void Tree<double, double>::ReferenceSerialize(dmlc::Stream* fo)
const;
77 template void ModelImpl<float, uint32_t>::ReferenceSerialize(dmlc::Stream* fo)
const;
78 template void ModelImpl<float, float>::ReferenceSerialize(dmlc::Stream* fo)
const;
79 template void ModelImpl<double, uint32_t>::ReferenceSerialize(dmlc::Stream* fo)
const;
80 template void ModelImpl<double, double>::ReferenceSerialize(dmlc::Stream* fo)
const;
model structure for tree ensemble