shogun
shogun copied to clipboard
Write a utility function to make a shallow copy of an SGObject
Usually SGObjects are stored in shared_ptr, so when we perform a copy we just increment the control block refcount. We have a clone method to perform deep cloning, but this means we might be copying features, labels and weights, which is not always needed. This can be avoided by passing the respective ParameterProperties to the make_clone function, so it would be good to have make_shallow_copy free function that sets these flags automatically (something like ParameterProperties::ALL ^ ParameterProperties::MODEL ^ ParameterProperties::READONLY), and then just have something like make_shallow_copy(obj).
you mean like this?
template<typename T>
std::shared_ptr<SGObject> make_shallow_copy(std::shared_ptr<T> obj){
return obj->clone(ParameterProperties::ALL
^ ParameterProperties::MODEL ^ ParameterProperties::READONLY);
}
yup, and then find places where you can use it. You could also use the make_clone function instead, but it would be the same
https://github.com/shogun-toolbox/shogun/blob/78cfc5f4ef6daf196819f900234be7d5455bc3a1/src/shogun/multiclass/tree/RelaxedTree.cpp#L299
@karlnapf are those the flags you would expect a shallow copy to use?
yes, see in the xvalidation code. But I would name it differently, it is not really a "shallow" copy, as some of the subobjects would be cloned. It is more like .... mmh not sure what a good name would be. But I think it is good to have this function (shouldnt be part of swig though)
I am new to open source development. Can I do any help?
Hello! I looked at the source code, and SGObject is still missing the make_shallow_copy() method. I would like to work on this!
^ following the previous comment...
I am trying to run some python example, but I was not able to find shogun.py, as listed in https://github.com/shogun-toolbox/shogun/blob/develop/doc/readme/INTERFACES.md. Can anyone help me with this?
thanks!
^ following the previous comment...
I am trying to run some python example, but I was not able to find shogun.py, as listed in https://github.com/shogun-toolbox/shogun/blob/develop/doc/readme/INTERFACES.md. Can anyone help me with this?
thanks!
hi @yiransii, you need to enable python interfaces, like this cmake -DINTERFACE_PYTHON=ON ..
@gf712 @LiuYuHui Thanks! However, I am still having dependency issues. Namely, my machine has Eigen3.3.8, but seems like shogun only supports version <= 3.3.7 but eigen 3.3.7 source repo is no longer available (https://bitbucket.org/eigen/eigen/get/3.3.7.tar.bz2)
Any workaround this? Thanks!
-- Performing Test HAVE_STD_ALIGNED_ALLOC
-- Performing Test HAVE_STD_ALIGNED_ALLOC - Failed
-- Looking for posix_memalign
-- Looking for posix_memalign - found
CMake Error at src/shogun/CMakeLists.txt:311 (MESSAGE):
The system Eigen3 version isn't supported!
-- Configuring incomplete, errors occurred!
@yiransii you can use this link, https://gitlab.com/libeigen/eigen/-/releases/3.3.7
Sounds fun! (and stale), Imma do it!
you mean like this?
template<typename T> std::shared_ptr<SGObject> make_shallow_copy(std::shared_ptr<T> obj){ return obj->clone(ParameterProperties::ALL ^ ParameterProperties::MODEL ^ ParameterProperties::READONLY); }
Help me out a litlte, so the problem is the current copy method, copies everything which may or may not be required. So we'd like to use ParameterProperties as flags to pick and choose what we want to copy?
If that's the case I think our code should be something like
In the header file
template<T>
std::shared_ptr<SGObject> sparse_copy(std::shared_ptr<T> obj, ParameterProperties pp = ParameterProperties::ALL
> ^ ParameterProperties::MODEL ^ ParameterProperties::READONLY);
In source
template<T>
std::shared_ptr<SGObject> SGObject::sparse_copy(std::shared<T> obj, ParameterProperties pp)
{
return obj->make_clone(pp);
}
hey I am new to opensource How can I contribute @karlnapf @gf712