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

Replace obtain_from_generic with .as #4224

Merged

Conversation

syashakash
Copy link
Contributor

Refer #4191
This is partial wok. There are more cases that need to be re-factored.

PS The build is expected to fail terribly when interface options are set. This is because build/src/interfaces/{language}/shogun{language}wrap.cxx needs refactoring wherever obtain_from_generic is used.

@karlnapf
Copy link
Member

karlnapf commented Apr 3, 2018

Overlooking the diff, this looks good.
I dont understand why the build would break.
You are right that as is not available through the interfaces, but if you dont change the example code, then there should not be any problems (we will solve obtain_from_generic in the examples slightly differently)

@karlnapf
Copy link
Member

karlnapf commented Apr 3, 2018

Are these ALL instances of obtain_from_generic in src/shogun ?

@@ -43,23 +43,6 @@ class CGradientResult : public CEvaluationResult
*/
virtual const char* get_name() const { return "GradientResult"; }

/** helper method used to specialize a base class instance
Copy link
Member

Choose a reason for hiding this comment

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

dont remove these methods for now (the examples might stop working)

@@ -78,16 +78,4 @@ void CLatentFeatures::init()
{
SG_ADD((CSGObject**) &m_samples, "samples", "Array of examples",
MS_NOT_AVAILABLE);
}

CLatentFeatures* CLatentFeatures::obtain_from_generic(CFeatures* base_feats)
Copy link
Member

Choose a reason for hiding this comment

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

as you can see, the current obtain_from_generic methods are inconsistent: some of the increase the reference counter, and some of them dont. This one doesnt.

as does NOT increase the reference counter. This explains all the segfaults in the CI.
Unfortunately, if you replace a obtain_from_generic that increased the reference counter, you will have to add a SG_REF after the call.
However, I actually think that neither as nor obtain_from_generic should increase the reference counter at all, so the best would be just to modifz the code downstream to not decrease the reference counter downstream

}

/* since an additional reference is returned */
SG_REF(kernel);
Copy link
Member

Choose a reason for hiding this comment

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

here is an example of an increased reference counter

if (inference->get_inference_type()!=INF_FITC_REGRESSION)
SG_SERROR("Provided inference is not of type CFITCInferenceMethod!\n")

SG_REF(inference);
Copy link
Member

Choose a reason for hiding this comment

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

another increase. I think the ones that do the increase are the minority

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.

Thanks for the patch and effort.
I commented on the reference counter problems. As said, I would just remove the increasing via either as or obtain_from_generic...

@syashakash syashakash force-pushed the remove-obtain_from_generic branch 2 times, most recently from 2019210 to a8a707f Compare April 6, 2018 06:13
@syashakash
Copy link
Contributor Author

syashakash commented Apr 6, 2018

I have not deleted any declarations and definitions of obtain_from_generic so that examples work fine. Apart from that all the obtain_from_generic function calls in src/shogun have been replaced with .as<T>().
I have removed the statements that decremented the reference count wherever there were calls to obtain_from_generic that would increase the reference count.

@syashakash syashakash force-pushed the remove-obtain_from_generic branch 2 times, most recently from 57cfb43 to 1171799 Compare April 6, 2018 11:14
@@ -120,10 +120,8 @@ CBinaryLabels* CGaussianProcessClassification::apply_binary(
if (m_method->get_inference_type()== INF_FITC_LAPLACE_SINGLE)
{
#ifdef USE_GPL_SHOGUN
CSingleFITCLaplaceInferenceMethod* fitc_method=
CSingleFITCLaplaceInferenceMethod::obtain_from_generic(m_method);
Copy link
Member

Choose a reason for hiding this comment

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

CSingleFITCLaplaceInferenceMethod::obtain_from_generic method increases the reference counter, but your replacement doesnt.

Do you see what I mean here? You have written that you have dealt with this, but that is not true here

Copy link
Member

Choose a reason for hiding this comment

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

ah sorry, you in fact remove the UNREF below ...
all good!

@karlnapf
Copy link
Member

karlnapf commented Apr 9, 2018

Ok cool! thx for this!

@karlnapf karlnapf merged commit 36ccb7d into shogun-toolbox:develop Apr 9, 2018
@syashakash syashakash deleted the remove-obtain_from_generic branch April 11, 2018 17:59
@syashakash syashakash restored the remove-obtain_from_generic branch April 11, 2018 17:59
@syashakash syashakash deleted the remove-obtain_from_generic branch April 11, 2018 18:02
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