mlpack
Namespaces | Functions
print_class_defn.hpp File Reference
#include "strip_type.hpp"
Include dependency graph for print_class_defn.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

 mlpack
 Linear algebra utility functions, generally performed on matrices or vectors.
 

Functions

template<typename T >
void mlpack::bindings::python::PrintClassDefn (util::ParamData &, const typename std::enable_if<!arma::is_arma_type< T >::value >::type *=0, const typename std::enable_if<!data::HasSerialize< T >::value >::type *=0)
 Non-serializable models don't require any special definitions, so this prints nothing.
 
template<typename T >
void mlpack::bindings::python::PrintClassDefn (util::ParamData &, const typename std::enable_if< arma::is_arma_type< T >::value >::type *=0)
 Matrices don't require any special definitions, so this prints nothing.
 
template<typename T >
void mlpack::bindings::python::PrintClassDefn (util::ParamData &d, const typename std::enable_if<!arma::is_arma_type< T >::value >::type *=0, const typename std::enable_if< data::HasSerialize< T >::value >::type *=0)
 Serializable models require a special class definition. More...
 
template<typename T >
void mlpack::bindings::python::PrintClassDefn (util::ParamData &d, const void *, void *)
 Print the class definition to stdout. More...
 

Detailed Description

Author
Ryan Curtin

Print the class definition for generating a .pyx binding.

mlpack is free software; you may redistribute it and/or modify it under the terms of the 3-clause BSD license. You should have received a copy of the 3-clause BSD license along with mlpack. If not, see http://www.opensource.org/licenses/BSD-3-Clause for more information.

Function Documentation

◆ PrintClassDefn() [1/2]

template<typename T >
void mlpack::bindings::python::PrintClassDefn ( util::ParamData d,
const typename std::enable_if<!arma::is_arma_type< T >::value >::type *  = 0,
const typename std::enable_if< data::HasSerialize< T >::value >::type *  = 0 
)

Serializable models require a special class definition.

This will produce code like:

cdef class <ModelType>Type:
cdef <ModelType>* modelptr
cdef public dict scrubbed_params
def __cinit__(self):
self.modelptr = new <ModelType>()
self.scrubbed_params = dict()
def __dealloc__(self):
del self.modelptr
def __getstate__(self):
return SerializeOut(self.modelptr, "<ModelType>")
def __setstate__(self, state):
SerializeIn(self.modelptr, state, "<ModelType>")
def __reduce_ex__(self):
return (self.__class__, (), self.__getstate__())
def _get_cpp_params(self):
return SerializeOutJSON(self.modelptr, "<ModelType>")
def _set_cpp_params(self, state):
SerializeInJSON(self.modelptr, state, "<ModelType>")
def get_cpp_params(self, return_str=False):
params = self._get_cpp_params()
return process_params_out(self, params, return_str=return_str)
def set_cpp_params(self, params_dic):
params_str = process_params_in(self, params_dic)
self._set_cpp_params(params_str)

◆ PrintClassDefn() [2/2]

template<typename T >
void mlpack::bindings::python::PrintClassDefn ( util::ParamData d,
const void *  ,
void *   
)

Print the class definition to stdout.

Only serializable models require a different class definition, so anything else does nothing.

Parameters
dParameter data.
*(input) Unused parameter.
*(output) Unused parameter.