@@ -29,7 +29,20 @@ namespace cp = visualdl::components;
2929 CODE (double );
3030
3131PYBIND11_MODULE (core, m) {
32- m.doc () = " C++ core of VisualDL" ;
32+ m.doc () = R"pbdoc(
33+
34+ VisualDL uses PyBind to operate with the c++ framework. Users should use LogWriter to instantiate scalar/histogram/image writer
35+
36+ .. autoclass:: ScalarWriter__float
37+ :members:
38+
39+ .. autoclass:: HistogramWriter__float
40+ :members:
41+
42+ .. autoclass:: ImageWriter
43+ :members:
44+
45+ )pbdoc" ;
3346
3447 py::class_<vs::LogReader>(m, " LogReader" )
3548 .def (py::init (
@@ -115,22 +128,63 @@ PYBIND11_MODULE(core, m) {
115128#undef ADD_SCALAR_READER
116129
117130#define ADD_SCALAR_WRITER (T ) \
118- py::class_<cp::Scalar<T>>(m, " ScalarWriter__" #T) \
131+ py::class_<cp::Scalar<T>>(m, " ScalarWriter__" #T, R"pbdoc(
132+ PyBind class. Must instantiate through the LogWriter.
133+ )pbdoc" ) \
119134 .def (" set_caption" , &cp::Scalar<T>::SetCaption) \
120- .def (" add_record" , &cp::Scalar<T>::AddRecord);
135+ .def (" add_record" , &cp::Scalar<T>::AddRecord, R"pbdoc(
136+ add a record with the step and value
137+
138+ :param step: This value appears at this step in the run.
139+ :type step: integer
140+ :param value: The scalar value to be recorded.
141+ :type value: float
142+ )pbdoc" );
121143 ADD_SCALAR_WRITER (int );
122144 ADD_SCALAR_WRITER (float );
123145 ADD_SCALAR_WRITER (double );
124146#undef ADD_SCALAR_WRITER
125147
126148 // clang-format on
127- py::class_<cp::Image>(m, " ImageWriter" )
128- .def (" set_caption" , &cp::Image::SetCaption)
129- .def (" start_sampling" , &cp::Image::StartSampling)
130- .def (" is_sample_taken" , &cp::Image::IsSampleTaken)
131- .def (" finish_sampling" , &cp::Image::FinishSampling)
132- .def (" set_sample" , &cp::Image::SetSample)
133- .def (" add_sample" , &cp::Image::AddSample);
149+ py::class_<cp::Image>(m, " ImageWriter" , R"pbdoc(
150+ PyBind class. Must instantiate through the LogWriter.
151+ )pbdoc" )
152+ .def (" set_caption" , &cp::Image::SetCaption, R"pbdoc(
153+ PyBind class. Must instantiate through the LogWriter.
154+ )pbdoc" )
155+ .def (" start_sampling" , &cp::Image::StartSampling, R"pbdoc(
156+ Start a sampling period, this interface will start a new reservoir sampling phase.
157+ )pbdoc" )
158+ .def (" is_sample_taken" , &cp::Image::IsSampleTaken, R"pbdoc(
159+ Will this sample be taken, this interface is introduced to reduce the cost
160+ of copy image data, by testing whether this image will be sampled, and only
161+ copy data when it should be sampled. In that way, most of un-sampled image
162+ data need not be copied or processed at all.
163+
164+ :return: Index
165+ :rtype: integer
166+ )pbdoc" )
167+ .def (" finish_sampling" , &cp::Image::FinishSampling, R"pbdoc(
168+ End a sampling period, it will clear all states for reservoir sampling.
169+ )pbdoc" )
170+ .def (" set_sample" , &cp::Image::SetSample, R"pbdoc(
171+ Store the image shape with the flatten image data.
172+
173+ :param index:
174+ :type index: integer
175+ :param image_shape: Image size
176+ :type image_shape: tuple
177+ :param image_data: Flatten image data
178+ :type image_data: list
179+ )pbdoc" )
180+ .def (" add_sample" , &cp::Image::AddSample, R"pbdoc(
181+ A combined interface for is_sample_taken and set_sample, simpler but is less efficient.
182+
183+ :param image_shape: Image size
184+ :type image_shape: tuple
185+ :param image_data: Flatten image data
186+ :type image_data: list
187+ )pbdoc" );
134188
135189 py::class_<cp::ImageReader::ImageRecord>(m, " ImageRecord" )
136190 // TODO(ChunweiYan) make these copyless.
@@ -147,9 +201,19 @@ PYBIND11_MODULE(core, m) {
147201 .def (" record" , &cp::ImageReader::record)
148202 .def (" timestamp" , &cp::ImageReader::timestamp);
149203
150- #define ADD_HISTOGRAM_WRITER (T ) \
151- py::class_<cp::Histogram<T>>(m, " HistogramWriter__" #T) \
152- .def (" add_record" , &cp::Histogram<T>::AddRecord);
204+ #define ADD_HISTOGRAM_WRITER (T ) \
205+ py::class_<cp::Histogram<T>>(m, " HistogramWriter__" #T, R"pbdoc(
206+ PyBind class. Must instantiate through the LogWriter.
207+ )pbdoc" ) \
208+ .def (" add_record" , &cp::Histogram<T>::AddRecord, R"pbdoc(
209+ add a record with the step and histogram_value
210+
211+ :param step: This value appears at this step in the run.
212+ :type step: integer
213+ :param histogram_value: A flatten list of the distribution value. EX: [1, 2, 100, 2, 3, 200] will draw a histogram where
214+ the value between 1~2 is 100 and the value between 2~3 is 200
215+ :type histogram_value: list
216+ )pbdoc" );
153217 ADD_FULL_TYPE_IMPL (ADD_HISTOGRAM_WRITER)
154218#undef ADD_HISTOGRAM_WRITER
155219
0 commit comments