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

Numpy 2.0.0 update and removing deprecated scipy modules #3562

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
#
# We use Py3.8 here for historical reasons.
#
python-version: "3.8"
python-version: "3.9"

- name: Update pip
run: python -m pip install -U pip
Expand All @@ -35,7 +35,7 @@ jobs:
sudo apt-get -yq update
sudo apt-get -yq remove texlive-binaries --purge
sudo apt-get -yq --no-install-suggests --no-install-recommends --force-yes install dvipng texlive-latex-base texlive-latex-extra texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended latexmk
sudo apt-get -yq install build-essential python3.8-dev
sudo apt-get -yq install build-essential python3.9-dev
- name: Install gensim and its dependencies
run: pip install -e .[docs]

Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/build-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,17 @@ jobs:
fail-fast: false
matrix:
include:
- {python: '3.8', os: macos-12}
- {python: '3.9', os: macos-12}
- {python: '3.10', os: macos-12}
- {python: '3.11', os: macos-12}
- {python: '3.12', os: macos-12}

- {python: '3.8', os: ubuntu-20.04}
- {python: '3.9', os: ubuntu-20.04}
- {python: '3.10', os: ubuntu-20.04}
- {python: '3.11', os: ubuntu-20.04}
- {python: '3.12', os: ubuntu-20.04}

- {python: '3.8', os: windows-2019}
- {python: '3.9', os: windows-2019}

- {python: '3.10', os: windows-2019}
- {python: '3.11', os: windows-2019}
- {python: '3.12', os: windows-2019}
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
#
# We use Py3.8 here for historical reasons.
#
python-version: "3.8"
python-version: "3.9"

- name: Update pip
run: python -m pip install -U pip
Expand All @@ -43,7 +43,7 @@ jobs:
sudo apt-get -yq update
sudo apt-get -yq remove texlive-binaries --purge
sudo apt-get -yq --no-install-suggests --no-install-recommends --force-yes install dvipng texlive-latex-base texlive-latex-extra texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended latexmk
sudo apt-get -yq install build-essential python3.8-dev
sudo apt-get -yq install build-essential python3.9-dev
- name: Install gensim and its dependencies
run: pip install -e .[docs]

Expand All @@ -63,13 +63,11 @@ jobs:
fail-fast: false
matrix:
include:
- {python: '3.8', os: ubuntu-20.04}
- {python: '3.9', os: ubuntu-20.04}
- {python: '3.10', os: ubuntu-20.04}
- {python: '3.11', os: ubuntu-20.04}
- {python: '3.12', os: ubuntu-20.04}

- {python: '3.8', os: windows-2019}
- {python: '3.9', os: windows-2019}
- {python: '3.10', os: windows-2019}
- {python: '3.11', os: windows-2019}
Expand Down
2 changes: 1 addition & 1 deletion gensim/models/keyedvectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1977,7 +1977,7 @@ def _word2vec_read_text(fin, kv, counts, vocab_size, vector_size, datatype, unic

def _word2vec_line_to_vector(line, datatype, unicode_errors, encoding):
parts = utils.to_unicode(line.rstrip(), encoding=encoding, errors=unicode_errors).split(" ")
word, weights = parts[0], [datatype(x) for x in parts[1:]]
word, weights = parts[0], [datatype(x).item() for x in parts[1:]]
return word, weights


Expand Down
12 changes: 3 additions & 9 deletions gensim/models/lsimodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
import numpy as np
import scipy.linalg
import scipy.sparse
from scipy.sparse import sparsetools

from gensim import interfaces, matutils, utils
from gensim.models import basemodel
Expand Down Expand Up @@ -960,10 +959,8 @@ def stochastic_svd(
m, n = corpus.shape
assert num_terms == m, f"mismatch in number of features: {m} in sparse matrix vs. {num_terms} parameter"
o = random_state.normal(0.0, 1.0, (n, samples)).astype(y.dtype) # draw a random gaussian matrix
sparsetools.csc_matvecs(
m, n, samples, corpus.indptr, corpus.indices,
corpus.data, o.ravel(), y.ravel(),
) # y = corpus * o
y = corpus.dot(o) # y = corpus * o

del o

# unlike np, scipy.sparse `astype()` copies everything, even if there is no change to dtype!
Expand Down Expand Up @@ -994,10 +991,7 @@ def stochastic_svd(
num_docs += n
logger.debug("multiplying chunk * gauss")
o = random_state.normal(0.0, 1.0, (n, samples), ).astype(dtype) # draw a random gaussian matrix
sparsetools.csc_matvecs(
m, n, samples, chunk.indptr, chunk.indices, # y = y + chunk * o
chunk.data, o.ravel(), y.ravel(),
)
y = y + chunk * o
del chunk, o
y = [y]
q, _ = matutils.qr_destroy(y) # orthonormalize the range
Expand Down
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ requires = [
"Cython>=0.29.32,<3.0.0",
# oldest supported Numpy for this platform is 1.17 but the oldest supported by Gensim
# is 1.18.5, remove the line when they increase oldest supported Numpy for this platform
"numpy==1.18.5; python_version=='3.8' and platform_machine not in 'arm64|aarch64'",
"oldest-supported-numpy; python_version>'3.8' or platform_machine in 'arm64|aarch64'",
# 20240604 GM: testing numpy-2.0.0 which requires python >= 3.9 (to 3.12)
"numpy==2.0.0; python_version>='3.9' and platform_machine not in 'arm64|aarch64'",
# "oldest-supported-numpy; python_version>'3.8' or platform_machine in 'arm64|aarch64'",
"scipy",
"setuptools",
"wheel",
]
10 changes: 3 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,7 @@ def run(self):
'pandas',
]

#
# see https://github.com/piskvorky/gensim/pull/3535
#
NUMPY_STR = 'numpy >= 1.18.5, < 2.0'
NUMPY_STR = 'numpy == 2.0.0'

install_requires = [
NUMPY_STR,
Expand All @@ -340,7 +337,7 @@ def run(self):

setup(
name='gensim',
version='4.3.3',
version='4.4.0a0.dev0',
description='Python framework for fast Vector Space Modelling',
long_description=LONG_DESCRIPTION,

Expand Down Expand Up @@ -373,7 +370,6 @@ def run(self):
'Environment :: Console',
'Intended Audience :: Science/Research',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
Expand All @@ -385,7 +381,7 @@ def run(self):
],

test_suite="gensim.test",
python_requires='>=3.8',
python_requires='>=3.9',
install_requires=install_requires,
tests_require=linux_testenv,
extras_require={
Expand Down
Loading