-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Conversation
|
||
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your point
Thanks! Are you going to push more kernel refactors here or shall I merge when it passes CI? |
src/shogun/kernel/ANOVAKernel.cpp
Outdated
{ | ||
register_params(); | ||
init(l, r); | ||
ASSERT(DotKernel::init(l, r)); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
src/shogun/kernel/ANOVAKernel.h
Outdated
* @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); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, removed it.
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 ? :) |
src/shogun/kernel/AUCKernel.h
Outdated
{ | ||
return C_DENSE; | ||
} | ||
inline virtual const char* get_name() const { return "AUCKernel"; } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
src/shogun/kernel/LogKernel.h
Outdated
protected: | ||
/// distance to be used | ||
std::shared_ptr<Distance> m_distance; | ||
std::shared_ptr<Distance> m_distance = NULL; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
shogun/src/shogun/kernel/Kernel.h
Line 455 in 7014676
virtual bool init(std::shared_ptr<Features> lhs, std::shared_ptr<Features> rhs); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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(); | ||
} |
There was a problem hiding this comment.
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
Thanks! :) |
Ding dong! , did anyone order cleanup? #5030
@gf712