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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions sklearn/utils/_weight_vector.pxd.tp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@ dtypes = [('64', 'double'),

}}

# WARNING: Do not edit this .pyx file directly, it is generated from its .pyx.tp
cimport numpy as np

{{for name_suffix, c_type in dtypes}}

cdef extern from "math.h":
cdef extern {{c_type}} sqrt({{c_type}} x)


cdef class WeightVector{{name_suffix}}(object):
cdef readonly {{c_type}}[::1] w
cdef readonly {{c_type}}[::1] aw
Expand Down
8 changes: 8 additions & 0 deletions sklearn/utils/_weight_vector.pyx.tp
Original file line number Diff line number Diff line change
Expand Up @@ -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.

# cython: cdivision=True
# cython: boundscheck=False
# cython: wraparound=False
# cython: profile=False
# cython: linetrace=False
# cython: initializedcheck=False
# cython: binding=False
# distutils: define_macros=CYTHON_TRACE_NOGIL=0
Comment on lines +25 to +29
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.

#
# Author: Peter Prettenhofer <peter.prettenhofer@gmail.com>
# Lars Buitinck
# Danny Sullivan <dsullivan7@hotmail.com>
#
# License: BSD 3 clause

# WARNING: Do not edit this .pyx file directly, it is generated from its .pyx.tp

cimport cython
from libc.limits cimport INT_MAX
from libc.math cimport sqrt
Expand Down