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

register factory methods for proper garbage collection #4322

Conversation

shubham808
Copy link
Contributor

@shubham808 shubham808 commented Jun 1, 2018

%newobject ecoc_encoder(const std::string& name);
%newobject ecoc_decoder(const std::string& name);
%newobject features(SGMatrix<T> mat);
%newobject features(CFile* file, EPrimitiveType primitive_type = PT_FLOAT64);
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure whether default arguments should be here

%newobject distance(const std::string& name);
%newobject evaluation(const std::string& name);
%newobject kernel(const std::string& name);
%newobject kernel(SGMatrix<T> kernel_matrix);
Copy link
Member

Choose a reason for hiding this comment

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

@shubham808 did you check whether shogun has any other %newobject cases where a templated object is returned? I wonder whether this needs some special treatment (and idk)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mmh... i thought that too but did not find any @vigsterkr any ideas ?

Copy link
Member

Choose a reason for hiding this comment

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

as far as SWIG goes it doesn't understand templates, before they are actually instantiated, say

%template SGMatrix<float32_t>
%template SGMatrix<float64_t>

that's the general guideline of SWIG... dunno how newobject works in this context but i would expect the same (consistent) behaviour?

Copy link
Member

Choose a reason for hiding this comment

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

just checked, and there is no case of %newobject in shogun that is templated.
@shubham808 i think let's just do it for float64 for now ...

@shubham808 shubham808 force-pushed the feature/garbage_collection_factory_methods branch from 830b189 to eaa368e Compare June 1, 2018 13:34
%newobject ecoc_encoder(const std::string& name);
%newobject ecoc_decoder(const std::string& name);
%newobject features(SGMatrix<T> mat);
%newobject features(CFile* file, EPrimitiveType primitive_type);
Copy link
Member

Choose a reason for hiding this comment

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

in fact we dont even need the parameter names, just the types

@shubham808 shubham808 force-pushed the feature/garbage_collection_factory_methods branch from eaa368e to 895d7da Compare June 1, 2018 14:33
%newobject multiclass_strategy(const std::string&);
%newobject ecoc_encoder(const std::string&);
%newobject ecoc_decoder(const std::string&);
%newobject features(SGMatrix<T>);
Copy link
Member

Choose a reason for hiding this comment

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

float64_t

@karlnapf
Copy link
Member

karlnapf commented Jun 1, 2018

Ok looks good now.

Now what does the garbage collector say in SWIG interfaces? works?

@shubham808
Copy link
Contributor Author

shubham808 commented Jun 1, 2018

i am not sure... should i run all examples with valgrind ?

@karlnapf
Copy link
Member

karlnapf commented Jun 4, 2018

It is pretty simple to find this out using valgrind ...

@shubham808
Copy link
Contributor Author

valgrind says 0 leaks for all meta examples in python

@vigsterkr
Copy link
Member

vigsterkr commented Jun 4, 2018 via email

@karlnapf
Copy link
Member

karlnapf commented Jun 4, 2018

Key is the delta of this before and after patch

@shubham808
Copy link
Contributor Author

i used the gcdebug log level in a python script that overwrites a kernel generated from factory.
The object is not being destroyed. :(

@karlnapf
Copy link
Member

karlnapf commented Jun 5, 2018

Yeah ok, we will need to dig into this a bit I guess.....I wonder whether it is the SG_REF thingi in the factory that causes it....

@karlnapf
Copy link
Member

karlnapf commented Aug 6, 2018

I leave this open for now as we should fix all the memory leaks in the examples and the factory at some point

@vigsterkr
Copy link
Member

"superseded" by #4604

@vigsterkr vigsterkr closed this Apr 10, 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

3 participants