Skip to content
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

Switch to Cython language level 3 #3344

Merged
merged 2 commits into from
Dec 3, 2022
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
1 change: 1 addition & 0 deletions gensim/_matutils.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env cython
# coding: utf-8
# cython: embedsignature=True
# cython: language_level=3

from __future__ import division
cimport cython
Expand Down
1 change: 1 addition & 0 deletions gensim/corpora/_mmreader.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (C) 2018 Radim Rehurek <[email protected]>
# cython: embedsignature=True
# cython: language_level=3

"""Reader for corpus in the Matrix Market format."""
import logging
Expand Down
1 change: 1 addition & 0 deletions gensim/models/doc2vec_corpusfile.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env cython
# cython: language_level=3
# cython: boundscheck=False
# cython: wraparound=False
# cython: cdivision=True
Expand Down
3 changes: 2 additions & 1 deletion gensim/models/doc2vec_inner.pxd
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env cython
# distutils: language = c++
# cython: language_level=3
# cython: boundscheck=False
# cython: wraparound=False
# cython: cdivision=True
Expand All @@ -15,7 +16,7 @@
import numpy as np
cimport numpy as np

from word2vec_inner cimport REAL_t
from gensim.models.word2vec_inner cimport REAL_t

DEF MAX_DOCUMENT_LEN = 10000

Expand Down
3 changes: 2 additions & 1 deletion gensim/models/doc2vec_inner.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env cython
# cython: language_level=3
# cython: boundscheck=False
# cython: wraparound=False
# cython: cdivision=True
Expand All @@ -24,7 +25,7 @@ except ImportError:
# in scipy > 0.15, fblas function has been removed
import scipy.linalg.blas as fblas

from word2vec_inner cimport bisect_left, random_int32, sscal, REAL_t, EXP_TABLE, our_dot, our_saxpy
from gensim.models.word2vec_inner cimport bisect_left, random_int32, sscal, REAL_t, EXP_TABLE, our_dot, our_saxpy

DEF MAX_DOCUMENT_LEN = 10000

Expand Down
1 change: 1 addition & 0 deletions gensim/models/fasttext_corpusfile.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env cython
# distutils: language = c++
# cython: language_level=3
# cython: boundscheck=False
# cython: wraparound=False
# cython: cdivision=True
Expand Down
3 changes: 2 additions & 1 deletion gensim/models/fasttext_inner.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env cython
# cython: language_level=3
# cython: boundscheck=False
# cython: wraparound=False
# cython: cdivision=True
Expand All @@ -13,7 +14,7 @@
import numpy as np
cimport numpy as np

from word2vec_inner cimport REAL_t
from gensim.models.word2vec_inner cimport REAL_t


DEF MAX_SENTENCE_LEN = 10000
Expand Down
3 changes: 2 additions & 1 deletion gensim/models/fasttext_inner.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env cython
# cython: language_level=3
# cython: boundscheck=False
# cython: wraparound=False
# cython: cdivision=True
Expand Down Expand Up @@ -55,7 +56,7 @@ from libc.string cimport memset
#
# The versions are as chosen in word2vec_inner.pyx, and aliased to `our_` functions

from word2vec_inner cimport bisect_left, random_int32, scopy, sscal, \
from gensim.models.word2vec_inner cimport bisect_left, random_int32, scopy, sscal, \
REAL_t, our_dot, our_saxpy

DEF MAX_SENTENCE_LEN = 10000
Expand Down
1 change: 1 addition & 0 deletions gensim/models/nmf_pgd.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Author: Timofey Yefimov

# cython: language_level=3
# cython: cdivision=True
# cython: boundscheck=False
# cython: wraparound=False
Expand Down
1 change: 1 addition & 0 deletions gensim/models/word2vec_corpusfile.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# distutils: language = c++
# cython: language_level=3
# cython: boundscheck=False
# cython: wraparound=False
# cython: cdivision=True
Expand Down
1 change: 1 addition & 0 deletions gensim/models/word2vec_corpusfile.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env cython
# distutils: language = c++
# cython: language_level=3
# cython: boundscheck=False
# cython: wraparound=False
# cython: cdivision=True
Expand Down
1 change: 1 addition & 0 deletions gensim/models/word2vec_inner.pxd
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# cython: language_level=3
# cython: boundscheck=False
# cython: wraparound=False
# cython: cdivision=True
Expand Down
8 changes: 2 additions & 6 deletions gensim/models/word2vec_inner.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env cython
# cython: language_level=3
# cython: boundscheck=False
# cython: wraparound=False
# cython: cdivision=True
Expand All @@ -19,12 +20,7 @@ from libc.math cimport exp
from libc.math cimport log
from libc.string cimport memset

# scipy <= 0.15
try:
from scipy.linalg.blas import fblas
except ImportError:
# in scipy > 0.15, fblas function has been removed
import scipy.linalg.blas as fblas
import scipy.linalg.blas as fblas

REAL = np.float32

Expand Down
33 changes: 17 additions & 16 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,26 @@
import platform
import shutil
import sys
from collections import OrderedDict

from setuptools import Extension, find_packages, setup, distutils
from setuptools.command.build_ext import build_ext

c_extensions = {
'gensim.models.word2vec_inner': 'gensim/models/word2vec_inner.c',
'gensim.corpora._mmreader': 'gensim/corpora/_mmreader.c',
'gensim.models.fasttext_inner': 'gensim/models/fasttext_inner.c',
'gensim._matutils': 'gensim/_matutils.c',
'gensim.models.nmf_pgd': 'gensim/models/nmf_pgd.c',
'gensim.similarities.fastss': 'gensim/similarities/fastss.c',
}
c_extensions = OrderedDict([
('gensim.models.word2vec_inner', 'gensim/models/word2vec_inner.c'),
('gensim.corpora._mmreader', 'gensim/corpora/_mmreader.c'),
('gensim.models.fasttext_inner', 'gensim/models/fasttext_inner.c'),
('gensim._matutils', 'gensim/_matutils.c'),
('gensim.models.nmf_pgd', 'gensim/models/nmf_pgd.c'),
('gensim.similarities.fastss', 'gensim/similarities/fastss.c'),
])

cpp_extensions = {
'gensim.models.doc2vec_inner': 'gensim/models/doc2vec_inner.cpp',
'gensim.models.word2vec_corpusfile': 'gensim/models/word2vec_corpusfile.cpp',
'gensim.models.fasttext_corpusfile': 'gensim/models/fasttext_corpusfile.cpp',
'gensim.models.doc2vec_corpusfile': 'gensim/models/doc2vec_corpusfile.cpp',
}
cpp_extensions = OrderedDict([
('gensim.models.doc2vec_inner', 'gensim/models/doc2vec_inner.cpp'),
('gensim.models.word2vec_corpusfile', 'gensim/models/word2vec_corpusfile.cpp'),
('gensim.models.fasttext_corpusfile', 'gensim/models/fasttext_corpusfile.cpp'),
('gensim.models.doc2vec_corpusfile', 'gensim/models/doc2vec_corpusfile.cpp'),
])


def need_cython():
Expand Down Expand Up @@ -111,8 +112,8 @@ def finalize_options(self):

if need_cython():
import Cython.Build
Cython.Build.cythonize(list(make_c_ext(use_cython=True)))
Cython.Build.cythonize(list(make_cpp_ext(use_cython=True)))
Cython.Build.cythonize(list(make_c_ext(use_cython=True)), language_level=3)
Cython.Build.cythonize(list(make_cpp_ext(use_cython=True)), language_level=3)


class CleanExt(distutils.cmd.Command):
Expand Down