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

#5031, Kernel constructor cleanup #5036

Merged
merged 1 commit into from
May 17, 2020
Merged

Conversation

jonpsy
Copy link
Contributor

@jonpsy jonpsy commented May 15, 2020

Ding dong! , did anyone order cleanup? #5030
@gf712


private:
float64_t compute_recursive1(float64_t* avec, float64_t* bvec, int32_t len);
float64_t compute_recursive2(float64_t* avec, float64_t* bvec, int32_t len);

protected:
virtual float64_t compute(int32_t idx_a, int32_t idx_b);
Copy link
Member

Choose a reason for hiding this comment

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

minor, but might be worth leaving compute where it was? So that the class members are separate from the class functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see your point

@gf712
Copy link
Member

gf712 commented May 15, 2020

Thanks! Are you going to push more kernel refactors here or shall I merge when it passes CI?

{
register_params();
init(l, r);
ASSERT(DotKernel::init(l, r));
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 curious, why is that changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just removed init(l,r) and pasted its code here. Also DotKernel::init(l,r) returns a bool, so I asserted that.

* @return casted CANOVAKernel object, NULL if input was NULL
/** Casts the given kernel to ANOVAKernel.
* @param kernel Kernel to cast. Must be ANOVAKernel. Might be NULL
* @return casted ANOVAKernel object, NULL if input was NULL
*/
static std::shared_ptr<ANOVAKernel> obtain_from_generic(const std::shared_ptr<Kernel>& kernel);
Copy link
Member

Choose a reason for hiding this comment

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

I think these are not used anymore, so can be remove (see what happens if you do that)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, removed it.

@jonpsy
Copy link
Contributor Author

jonpsy commented May 15, 2020

Thanks! Are you going to push more kernel refactors here or shall I merge when it passes CI?

There are a lot of kernels, some of them offer subtle complications. Also that I'm cleaning the docs too and the internal member names as well, so that'd be difficult for you guys to review(in case something bad goes down). I was instead planning on sending these in rounds.

EDIT: I'll add a few more simple cases, I'll @ you when I'm done ? :)
EDIT2: Please merge? @gf712 :D

{
return C_DENSE;
}
inline virtual const char* get_name() const { return "AUCKernel"; }
Copy link
Member

Choose a reason for hiding this comment

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

inline can be removed, it does nothing for us.
if you want to force use SG_FORCE_INLINE but I dont think that is needed here

Copy link
Member

Choose a reason for hiding this comment

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

Yea, the compiler will do that for you since it’s such a small cost to inline it

protected:
/// distance to be used
std::shared_ptr<Distance> m_distance;
std::shared_ptr<Distance> m_distance = NULL;
Copy link
Member

Choose a reason for hiding this comment

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

No need to set a shared ptr to NULL, the default constructor sets the pointer to nullptr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I modified the default constructor to do only SG_ADD. So I guess I'd need to set default values to internal members no?

Copy link
Member

Choose a reason for hiding this comment

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

No need for shared ptr, it will by default own a nullptr

Copy link
Member

Choose a reason for hiding this comment

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

But primitive types require initialisation yes, otherwise it’s undefined behaviour

{
Kernel::init(l,r);
ASSERT(m_distance->init(l,r));
init_normalizer();
Copy link
Member

Choose a reason for hiding this comment

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

Where did this come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removing its init(l,r) method (used only inside LogKernel constructor and pasted the code here.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, but you need to keep the init(l,r) method so I guess just leave it there

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we absolutely need to? I removed init(l,r) from other classes as well.

Copy link
Member

Choose a reason for hiding this comment

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

Yes

virtual bool init(std::shared_ptr<Features> lhs, std::shared_ptr<Features> rhs);

Copy link
Member

Choose a reason for hiding this comment

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

Actually it isn’t pure virtual so I guess you don’t need to

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very well, so I'll restore the init(l,r) methods. Maybe we can do something about them in future

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually it isn’t pure virtual so I guess you don’t need to

Yes but there are some methods (other than constructors) which are calling init(l,r).

Copy link
Member

Choose a reason for hiding this comment

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

Ah ok, then yes keep it

Kernel::init(l,r);
m_distance->init(l,r);
return init_normalizer();
}
Copy link
Member

Choose a reason for hiding this comment

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

Deleting this is getting you the build error. This is implementing a pure virtual method from kernel

* ANOVA
* AUC
* Const
* Log
* DIag
@gf712 gf712 merged commit e29377d into shogun-toolbox:develop May 17, 2020
@gf712
Copy link
Member

gf712 commented May 17, 2020

Thanks! :)

@jonpsy jonpsy deleted the delegate branch May 17, 2020 13:25
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.

3 participants