Skip to content

MNT Removing Cython compilation warnings in WeightVector template #20739

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 4 commits into from
Aug 13, 2021

Conversation

jjerphan
Copy link
Member

Reference Issues/PRs

Fixup for #20481

What does this implement/fix? Explain your changes.

Cython raises a warning at compile time because the WeightVector template imports sqrt from libc.math twice with different signatures.

This import sqrt once, removing the warning.

Any other comments?

Shouldn't we be stricter and we make the CI fail on Cython (but not on C or C++) compilation warnings?

@jjerphan jjerphan requested review from ogrisel and glemaitre and removed request for ogrisel August 11, 2021 16:01
This removes spurious checks in Cython which can slow
down the execution.
Copy link
Member

@lorentzenchr lorentzenchr left a comment

Choose a reason for hiding this comment

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

LGTM

Co-authored-by: Christian Lorentzen <lorentzen.ch@gmail.com>
Comment on lines +25 to +29
# cython: profile=False
# cython: linetrace=False
# cython: initializedcheck=False
# cython: binding=False
# distutils: define_macros=CYTHON_TRACE_NOGIL=0
Copy link
Member

Choose a reason for hiding this comment

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

The profiling and linetracing is false by default.

Suggested change
# cython: profile=False
# cython: linetrace=False
# cython: initializedcheck=False
# cython: binding=False
# distutils: define_macros=CYTHON_TRACE_NOGIL=0
# cython: initializedcheck=False
# cython: binding=False

Is binding=False required here?

Copy link
Member Author

Choose a reason for hiding this comment

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

The purpose of setting directives explicitly for files is that it allows generating code for given file (using cythonize for instance), but they aren't needed.

We should probably remove them anyway, yes.

The binding directive is False by default but will change to True in Cython 3 according to the docs.

Copy link
Member Author

Choose a reason for hiding this comment

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

If it is relevant setting binding's value, it's probably better to do so in scikit-learn/sklearn/_build_utils/__init__.py .

Copy link
Member

Choose a reason for hiding this comment

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

Okay lets keep binding=False.

@@ -18,16 +18,24 @@ dtypes = [('64', 'double', 1e-9),

}}

# cython: language_level=3
Copy link
Member

Choose a reason for hiding this comment

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

Hmm we do set language_level globally here:

compiler_directives={"language_level": 3},

but it is a little nicer to set it explicitly.

Copy link
Member Author

@jjerphan jjerphan Aug 13, 2021

Choose a reason for hiding this comment

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

As per indicated in the other thread, it helps generating code for this file solely if needed, but probably this should be removed.

Co-authored-by: Thomas J. Fan <thomasjpfan@gmail.com>
@jjerphan jjerphan changed the title MNT Import sqrt once from libc.math in WeightVector template MNT Removing Cython compilation warnings in WeightVector template Aug 13, 2021
Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

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

LGTM

@thomasjpfan thomasjpfan merged commit 0b57005 into scikit-learn:main Aug 13, 2021
@jjerphan jjerphan deleted the improve-weight-vector-tempita branch August 13, 2021 18:53
samronsin pushed a commit to samronsin/scikit-learn that referenced this pull request Nov 30, 2021
…ikit-learn#20739)

Co-authored-by: Christian Lorentzen <lorentzen.ch@gmail.com>
Co-authored-by: Thomas J. Fan <thomasjpfan@gmail.com>
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