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

Support clone of SGObjects' arrays #4239

Merged

Conversation

lisitsyn
Copy link
Member

No description provided.

@lisitsyn lisitsyn requested a review from karlnapf April 11, 2018 14:47
Copy link
Member

@karlnapf karlnapf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whooo!!

-> decltype((void)begin[0]->clone())
{
std::transform(
begin, end, dst, [](auto each) { return each->clone(); });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if some elements of the array are null?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

@@ -40,6 +40,20 @@ namespace shogun
namespace any_detail
{

inline CSGObject* copy_object(CSGObject* object)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe SG_FORCED_INLINE?

@karlnapf
Copy link
Member

Fine to merge from my side occe CI is happy

@karlnapf
Copy link
Member

Seems CI cannot be happy as this invalidates the cache ...

@karlnapf karlnapf merged commit 3afb987 into shogun-toolbox:develop Apr 12, 2018
@lisitsyn lisitsyn deleted the feature/sgobject-array-clone branch April 12, 2018 11:53
std::copy(begin, end, dst);
}

void copy_array(CSGObject** begin, CSGObject** end, CSGObject** dst);
Copy link
Member

@karlnapf karlnapf Apr 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a problem here:
This will only match if the pointer type is CSGObject but not for any subclass (discovered this in my own tests when writing clone). See below how to reproduce
The thing is: we decided to register the base classes directly, e.g. CKernel, without casting them to CSGObject
I think we will have to use the decltype trick you did for cloning single objects ....
Or maybe a type trait as we have done for put and get?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shared my tests here: c526de9

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually already the simple basic_checks test reveals it: double free since the object wasn't cloned:

TYPED_TEST(SGObjectClone, basic_checks)

TEST(Any, clone_array_sgobject)
{
int src_len = 3;
CSGObject** src = new CSGObject*[src_len];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you make a test where the pointer type is Object**, this will go into the std::copy branch above

ktiefe pushed a commit to ktiefe/shogun that referenced this pull request Jul 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants