Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write a utility function to make a shallow copy of an SGObject #5058

Open
gf712 opened this issue Jun 7, 2020 · 14 comments
Open

Write a utility function to make a shallow copy of an SGObject #5058

gf712 opened this issue Jun 7, 2020 · 14 comments

Comments

@gf712
Copy link
Member

gf712 commented Jun 7, 2020

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).

@LiuYuHui
Copy link
Contributor

LiuYuHui commented Jun 7, 2020

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);
}

@gf712
Copy link
Member Author

gf712 commented Jun 7, 2020

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

@gf712
Copy link
Member Author

gf712 commented Jun 7, 2020

auto kernel = make_clone(m_kernel, ParameterProperties::ALL^ParameterProperties::MODEL);

@gf712
Copy link
Member Author

gf712 commented Jun 7, 2020

@karlnapf are those the flags you would expect a shallow copy to use?

@karlnapf
Copy link
Member

karlnapf commented Jun 7, 2020

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)

@5aumy4
Copy link

5aumy4 commented Jul 3, 2020

I am new to open source development.
Can I do any help?

@yiransii
Copy link

yiransii commented Nov 9, 2020

Hello! I looked at the source code, and SGObject is still missing the make_shallow_copy() method. I would like to work on this!

@yiransii
Copy link

yiransii commented Nov 9, 2020

^ 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!

@LiuYuHui
Copy link
Contributor

LiuYuHui commented Nov 9, 2020

^ 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 ..

@yiransii
Copy link

yiransii commented Nov 9, 2020

@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!

@LiuYuHui
Copy link
Contributor

LiuYuHui commented Nov 9, 2020

@yiransii you can use this link, https://gitlab.com/libeigen/eigen/-/releases/3.3.7

@jonpsy
Copy link
Contributor

jonpsy commented Jan 4, 2021

Sounds fun! (and stale), Imma do it!

@jonpsy
Copy link
Contributor

jonpsy commented Jan 5, 2021

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);
}

@jonpsy jonpsy mentioned this issue Jan 5, 2021
@aryangulati
Copy link

hey I am new to opensource How can I contribute @karlnapf @gf712

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants