8000 MNT Cleaner cython cdef loss function in SGD by lorentzenchr · Pull Request #17191 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

MNT Cleaner cython cdef loss function in SGD #17191

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

Merged
merged 2 commits into from
May 12, 2020

Conversation

lorentzenchr
Copy link
Member

What does this implement/fix? Explain your changes.

This PR simpliefies the derivative loss functions for SGD. It makes the distinction bewtween cdef dloss() nogil: for productive use and def py_dloss(): for calls in the test suite only.

@rth
Copy link
Member
rth commented May 12, 2020

Thanks! I think,

    cpdef double dloss(self, double p, double y) nogil:

might work (and allow access from pure Python) as long as the corresponding classes are decorated with cython.final to mark them as not subclassable: https://stackoverflow.com/a/37869168/1791279 Whether it's worth it I am not sure. The current solution is also acceptable.

@lorentzenchr
Copy link
Member Author

cdef class LossFunction is subclassed and we want to test the dloss of the subclasses. I guess the @cython.final trick might not work here. (But good to know that trick!)

@rth
Copy link
Member
rth commented May 12, 2020

No I mean dloss loss is defined on subclasses, right? So that's where the final decorator could also be applied (not on the base class)..

@rth
Copy link
Member
rth commented May 12, 2020

I'm not saying that we should do it though, just that it might be possible.

Any opinions @thomasjpfan @jeremiedbb ?

Copy link
Member
@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

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

Looks good

One tiny perk of using the wrapper instead of cpdef is that compilation will be slightly faster compared to duplicating all methods

Copy link
Member
@rth rth left a comment

Choose a reason for hiding this comment

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

OK, sounds good. Thanks!

@rth rth changed the title [MRG] MNT Cleaner cythn cdef loss function in SGD MNT Cleaner cythn cdef loss function in SGD May 12, 2020
@rth rth merged commit 4b92a77 into scikit-learn:master May 12, 2020
@lorentzenchr lorentzenchr changed the title MNT Cleaner cythn cdef loss function in SGD MNT Cleaner cython cdef loss function in SGD May 12, 2020
@lorentzenchr lorentzenchr deleted the sgd_clean branch May 12, 2020 21:13
gio8tisu pushed a commit to gio8tisu/scikit-learn that referenced this pull request May 15, 2020
viclafargue pushed a commit to viclafargue/scikit-learn that referenced this pull request Jun 26, 2020
jayzed82 pushed a commit to jayzed82/scikit-learn that referenced this pull request Oct 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0