This commit is contained in:
tqchen 2014-05-04 00:09:16 -07:00
parent 2057dda560
commit 21f93ffd6a
3 changed files with 10 additions and 0 deletions

View File

@ -96,6 +96,8 @@ class Booster:
dmats = ( ctypes.c_void_p * len(cache) )(*[ ctypes.c_void_p(d.handle) for d in cache]) dmats = ( ctypes.c_void_p * len(cache) )(*[ ctypes.c_void_p(d.handle) for d in cache])
self.handle = xglib.XGBoosterCreate( dmats, len(cache) ) self.handle = xglib.XGBoosterCreate( dmats, len(cache) )
self.set_param( params ) self.set_param( params )
def __del__(self):
xglib.XGBoosterFree(self.handle)
def set_param(self, params,pv=None): def set_param(self, params,pv=None):
if isinstance(params,dict): if isinstance(params,dict):
for k, v in params.iteritems(): for k, v in params.iteritems():

View File

@ -170,6 +170,9 @@ extern "C"{
} }
return new Booster( mats ); return new Booster( mats );
} }
void XGBoosterFree( void *handle ){
delete static_cast<Booster*>(handle);
}
void XGBoosterSetParam( void *handle, const char *name, const char *value ){ void XGBoosterSetParam( void *handle, const char *name, const char *value ){
static_cast<Booster*>(handle)->SetParam( name, value ); static_cast<Booster*>(handle)->SetParam( name, value );
} }

View File

@ -109,6 +109,11 @@ extern "C"{
* \param create a booster * \param create a booster
*/ */
void *XGBoosterCreate( void* dmats[], size_t len ); void *XGBoosterCreate( void* dmats[], size_t len );
/*!
* \brief free obj in handle
* \param handle handle to be freed
*/
void XGBoosterFree( void* handle );
/*! /*!
* \brief set parameters * \brief set parameters
* \param handle handle * \param handle handle