Skip to content

Commit

Permalink
BLD: add language_level=3 to .pyx files.
Browse files Browse the repository at this point in the history
Silences useless build warnings, and should generate more appropriate
code.
  • Loading branch information
rgommers committed Dec 8, 2018
1 parent a30a99a commit a70886d
Show file tree
Hide file tree
Showing 46 changed files with 113 additions and 12 deletions.
2 changes: 2 additions & 0 deletions scipy/_lib/_ccallback_c.pxd
@@ -1,3 +1,5 @@
# cython: language_level=3

#
# Test function exports
#
Expand Down
2 changes: 2 additions & 0 deletions scipy/_lib/_ccallback_c.pyx
@@ -1,3 +1,5 @@
# cython: language_level=3

from __future__ import absolute_import

from cpython.pycapsule cimport (
Expand Down
2 changes: 2 additions & 0 deletions scipy/_lib/messagestream.pxd
@@ -1,3 +1,5 @@
# cython: language_level=3

cimport cython
from libc cimport stdio, stdlib

Expand Down
2 changes: 2 additions & 0 deletions scipy/_lib/messagestream.pyx
@@ -1,3 +1,5 @@
# cython: language_level=3

cimport cython
from libc cimport stdio, stdlib
from cpython cimport PyBytes_FromStringAndSize, PY_VERSION_HEX
Expand Down
2 changes: 1 addition & 1 deletion scipy/cluster/_hierarchy.pyx
@@ -1,4 +1,4 @@
# cython: boundscheck=False, wraparound=False, cdivision=True
# cython: language_level=3, boundscheck=False, wraparound=False, cdivision=True
from __future__ import absolute_import

import numpy as np
Expand Down
3 changes: 2 additions & 1 deletion scipy/cluster/_optimal_leaf_ordering.pyx
@@ -1,3 +1,4 @@
# cython: language_level=3
# cython: profile=False
# cython: linetrace=False
# distutils: define_macros=CYTHON_TRACE_NOGIL=1
Expand Down Expand Up @@ -88,7 +89,7 @@ cdef int _simultaneous_sort(float* dist, int* idx,
# The smallest of the three is moved to the beginning of the array,
# the middle (the pivot value) is moved to the end, and the largest
# is moved to the pivot index.
pivot_idx = size / 2
pivot_idx = size // 2
if dist[0] > dist[size - 1]:
dual_swap(dist, idx, 0, size - 1)
if dist[size - 1] > dist[pivot_idx]:
Expand Down
2 changes: 2 additions & 0 deletions scipy/cluster/_vq.pyx
@@ -1,3 +1,5 @@
# cython: language_level=3

"""
Cython rewrite of the vector quantization module, originally written
in C at src/vq.c and the wrapper at src/vq_module.c. This should be
Expand Down
2 changes: 2 additions & 0 deletions scipy/interpolate/_bspl.pyx
@@ -1,3 +1,5 @@
# cython: language_level=3

"""
Routines for evaluating and manipulating B-splines.
Expand Down
2 changes: 2 additions & 0 deletions scipy/interpolate/_ppoly.pyx
@@ -1,3 +1,5 @@
# cython: language_level=3

"""
Routines for evaluating and manipulating piecewise polynomials in
local power basis.
Expand Down
2 changes: 2 additions & 0 deletions scipy/interpolate/interpnd.pyx
@@ -1,3 +1,5 @@
# cython: language_level=3

"""
Simple N-D interpolation
Expand Down
2 changes: 2 additions & 0 deletions scipy/io/matlab/mio5_utils.pyx
@@ -1,3 +1,5 @@
# cython: language_level=3

''' Cython mio5 utility routines (-*- python -*- like)
'''
Expand Down
2 changes: 2 additions & 0 deletions scipy/io/matlab/mio_utils.pxd
@@ -1,3 +1,5 @@
# cython: language_level=3

cimport numpy as np

cpdef object squeeze_element(np.ndarray)
Expand Down
3 changes: 3 additions & 0 deletions scipy/io/matlab/mio_utils.pyx
@@ -1,4 +1,7 @@
# -*- python -*- like file

# cython: language_level=3

''' Utilities for generic processing of return arrays from read
'''

Expand Down
2 changes: 2 additions & 0 deletions scipy/io/matlab/streams.pxd
@@ -1,5 +1,7 @@
# -*- python -*- or rather like

# cython: language_level=3

cdef class GenericStream:
cdef object fobj

Expand Down
2 changes: 2 additions & 0 deletions scipy/linalg/_decomp_update.pyx.in
@@ -1,3 +1,5 @@
# cython: language_level=3

"""
Routines for updating QR decompositions

Expand Down
16 changes: 12 additions & 4 deletions scipy/linalg/_generate_pyx.py
Expand Up @@ -110,7 +110,8 @@ def pyx_decl_sub(name, args, header_name):
argnames=argnames, header_name=header_name)


blas_pyx_preamble = '''# cython: boundscheck = False
blas_pyx_preamble = '''# cython: language_level=3
# cython: boundscheck = False
# cython: wraparound = False
# cython: cdivision = True
Expand Down Expand Up @@ -158,7 +159,10 @@ def make_blas_pyx_preamble(all_sigs):
return blas_pyx_preamble.format("\n- ".join(names))


lapack_pyx_preamble = '''"""
lapack_pyx_preamble = '''# cython: language_level=3
"""
LAPACK functions for Cython
===========================
Expand Down Expand Up @@ -470,7 +474,9 @@ def pxd_decl(name, ret_type, args):
return pxd_template.format(name=name, ret_type=ret_type, args=args)


blas_pxd_preamble = """# Within scipy, these wrappers can be used via relative or absolute cimport.
blas_pxd_preamble = """# cython: language_level=3
# Within scipy, these wrappers can be used via relative or absolute cimport.
# Examples:
# from ..linalg cimport cython_blas
# from scipy.linalg cimport cython_blas
Expand All @@ -494,7 +500,9 @@ def generate_blas_pxd(all_sigs):
return blas_pxd_preamble + body


lapack_pxd_preamble = """# Within scipy, these wrappers can be used via relative or absolute cimport.
lapack_pxd_preamble = """# cython: language_level=3
# Within scipy, these wrappers can be used via relative or absolute cimport.
# Examples:
# from ..linalg cimport cython_lapack
# from scipy.linalg cimport cython_lapack
Expand Down
2 changes: 1 addition & 1 deletion scipy/linalg/_solve_toeplitz.pyx
@@ -1,6 +1,6 @@
# Author: Robert T. McGibbon, December 2014
#
# cython: boundscheck=False, wraparound=False, cdivision=True
# cython: language_level=3, boundscheck=False, wraparound=False, cdivision=True
from __future__ import absolute_import

from numpy import zeros, asarray, complex128, float64
Expand Down
2 changes: 2 additions & 0 deletions scipy/ndimage/src/_cytest.pxd
@@ -1,3 +1,5 @@
# cython: language_level=3

from numpy cimport npy_intp as intp

cdef int _filter1d(double *input_line, intp input_length, double *output_line,
Expand Down
2 changes: 2 additions & 0 deletions scipy/ndimage/src/_cytest.pyx
@@ -1,3 +1,5 @@
# cython: language_level=3

from __future__ import absolute_import

from cpython.mem cimport PyMem_Malloc, PyMem_Free
Expand Down
2 changes: 2 additions & 0 deletions scipy/ndimage/src/_ni_label.pyx
@@ -1,3 +1,5 @@
# cython: language_level=3

######################################################################
# Cython version of scipy.ndimage.measurements.label().
# Requires Cython version 0.17 or greater due to type templating.
Expand Down
2 changes: 2 additions & 0 deletions scipy/optimize/_group_columns.pyx
@@ -1,3 +1,5 @@
# cython: language_level=3

"""
Cython implementation of columns grouping for finite difference Jacobian
estimation. Used by ._numdiff.group_columns.
Expand Down
2 changes: 2 additions & 0 deletions scipy/optimize/_lsq/givens_elimination.pyx
@@ -1,3 +1,5 @@
# cython: language_level=3

from __future__ import absolute_import

cimport cython
Expand Down
4 changes: 3 additions & 1 deletion scipy/optimize/_trlib/_trlib.pyx
@@ -1,6 +1,8 @@
# cython: language_level=3

from scipy.optimize._trustregion import (_minimize_trust_region, BaseQuadraticSubproblem)
import numpy as np
cimport ctrlib
from . cimport ctrlib
cimport libc.stdio
cimport numpy as np

Expand Down
2 changes: 2 additions & 0 deletions scipy/optimize/_trlib/ctrlib.pxd
@@ -1,3 +1,5 @@
# cython: language_level=3

# MIT License
#
# Copyright (c) 2016--2017 Felix Lenders
Expand Down
2 changes: 2 additions & 0 deletions scipy/signal/_max_len_seq_inner.pyx
@@ -1,3 +1,5 @@
# cython: language_level=3

# Author: Eric Larson
# 2014

Expand Down
7 changes: 4 additions & 3 deletions scipy/signal/_peak_finding_utils.pyx
@@ -1,6 +1,7 @@
#cython: wraparound=False
#cython: boundscheck=False
#cython: nonecheck=False
# cython: language_level=3
# cython: wraparound=False
# cython: boundscheck=False
# cython: nonecheck=False

"""Utility functions for finding peaks in signals."""

Expand Down
2 changes: 2 additions & 0 deletions scipy/signal/_spectral.pyx
@@ -1,3 +1,5 @@
# cython: language_level=3

# Author: Pim Schellart
# 2010 - 2011

Expand Down
2 changes: 2 additions & 0 deletions scipy/signal/_upfirdn_apply.pyx
@@ -1,3 +1,5 @@
# cython: language_level=3

# -*- coding: utf-8 -*-

# Code adapted from "upfirdn" python library with permission:
Expand Down
2 changes: 2 additions & 0 deletions scipy/sparse/_csparsetools.pyx.in
@@ -1,3 +1,5 @@
# cython: language_level=3

# -*- cython -*-
#
# Tempita-templated Cython file
Expand Down
2 changes: 2 additions & 0 deletions scipy/sparse/csgraph/_min_spanning_tree.pyx
@@ -1,3 +1,5 @@
# cython: language_level=3

# Author: Jake Vanderplas -- <vanderplas@astro.washington.edu>
# License: BSD, (C) 2011

Expand Down
2 changes: 2 additions & 0 deletions scipy/sparse/csgraph/_reordering.pyx
@@ -1,3 +1,5 @@
# cython: language_level=3

# Author: Paul Nation -- <nonhermitian@gmail.com>
# Original Source: QuTiP: Quantum Toolbox in Python (qutip.org)
# License: New BSD, (C) 2014
Expand Down
2 changes: 2 additions & 0 deletions scipy/sparse/csgraph/_shortest_path.pyx
@@ -1,3 +1,5 @@
# cython: language_level=3

"""
Routines for performing shortest-path graph searches
Expand Down
2 changes: 2 additions & 0 deletions scipy/sparse/csgraph/_tools.pyx
@@ -1,3 +1,5 @@
# cython: language_level=3

"""
Tools and utilities for working with compressed sparse graphs
"""
Expand Down
2 changes: 2 additions & 0 deletions scipy/sparse/csgraph/_traversal.pyx
@@ -1,3 +1,5 @@
# cython: language_level=3

"""
Routines for traversing graphs in compressed sparse format
"""
Expand Down
2 changes: 2 additions & 0 deletions scipy/spatial/_hausdorff.pyx
@@ -1,3 +1,5 @@
# cython: language_level=3

"""
Directed Hausdorff Code
Expand Down
2 changes: 2 additions & 0 deletions scipy/spatial/_voronoi.pyx
@@ -1,3 +1,5 @@
# cython: language_level=3

"""
Spherical Voronoi Cython Code
Expand Down
2 changes: 2 additions & 0 deletions scipy/spatial/ckdtree.pyx
@@ -1,3 +1,5 @@
# cython: language_level=3

# Copyright Anne M. Archibald 2008
# Additional contributions by Patrick Varilly and Sturla Molden 2012
# Revision by Sturla Molden 2015
Expand Down
3 changes: 3 additions & 0 deletions scipy/spatial/qhull.pxd
@@ -1,4 +1,7 @@
# -*-cython-*-

# cython: language_level=3

"""
Qhull shared definitions, for use by other Cython modules
Expand Down
2 changes: 2 additions & 0 deletions scipy/spatial/qhull.pyx
@@ -1,3 +1,5 @@
# cython: language_level=3

"""
Wrappers for Qhull triangulation, plus some additional N-D geometry utilities
Expand Down
2 changes: 2 additions & 0 deletions scipy/special/_comb.pyx
@@ -1,3 +1,5 @@
# cython: language_level=3

from __future__ import absolute_import

cdef extern from "limits.h":
Expand Down
4 changes: 3 additions & 1 deletion scipy/special/_ellip_harm.pxd
@@ -1,3 +1,5 @@
# cython: language_level=3

# Copyright (c) 2012, Jaydeep P. Bardhan
# Copyright (c) 2012, Matthew G. Knepley
# Copyright (c) 2014, Janani Padmanabhan
Expand Down Expand Up @@ -63,7 +65,7 @@ cdef inline double* lame_coefficients(double h2, double k2, int n, int p,

cdef double s2, alpha, beta, gamma, lamba_romain, pp, psi, t1, tol, vl, vu
cdef int r, tp, j, size, i, info, lwork, liwork, c, iu
cdef char t
cdef Py_UNICODE t

r = n/2
alpha = h2
Expand Down
2 changes: 2 additions & 0 deletions scipy/special/_ellip_harm_2.pxd
@@ -1,3 +1,5 @@
# cython: language_level=3

cdef double _F_integrand(double t, void *data) nogil
cdef double _F_integrand1(double t, void *data) nogil
cdef double _F_integrand2(double t, void *data) nogil
Expand Down
2 changes: 2 additions & 0 deletions scipy/special/_ellip_harm_2.pyx
@@ -1,3 +1,5 @@
# cython: language_level=3

from __future__ import absolute_import

import ctypes
Expand Down
9 changes: 9 additions & 0 deletions scipy/special/_generate_pyx.py
Expand Up @@ -77,6 +77,9 @@
UFUNCS_EXTRA_CODE_COMMON = """\
# This file is automatically generated by _generate_pyx.py.
# Do not edit manually!
# cython: language_level=3
from __future__ import absolute_import
include "_ufuncs_extra_code_common.pxi"
Expand All @@ -94,11 +97,15 @@
"""

CYTHON_SPECIAL_PXD = """\
# cython: language_level=3
#
# This file is automatically generated by _generate_pyx.py.
# Do not edit manually!
"""

CYTHON_SPECIAL_PYX = """\
# cython: language_level=3
#
# This file is automatically generated by _generate_pyx.py.
# Do not edit manually!
\"\"\"
Expand Down Expand Up @@ -1180,6 +1187,8 @@ def generate_ufuncs(fn_prefix, cxx_fn_prefix, ufuncs):
# for _ufuncs_cxx*
cxx_defs = []
cxx_pxd_defs = [
"# cython: language_level=3",
"",
"from . cimport sf_error",
"cdef void _set_action(sf_error.sf_error_t, sf_error.sf_action_t) nogil"
]
Expand Down
2 changes: 2 additions & 0 deletions scipy/special/_test_round.pyx
@@ -1,3 +1,5 @@
# cython: language_level=3

from __future__ import absolute_import

import numpy as np
Expand Down
2 changes: 2 additions & 0 deletions scipy/stats/_stats.pyx
@@ -1,3 +1,5 @@
# cython: language_level=3

from __future__ import absolute_import

from cpython cimport bool
Expand Down

0 comments on commit a70886d

Please sign in to comment.