Skip to content

Commit 9f585bc

Browse files
authored
Merge branch 'main' into patch-1
2 parents 94b3728 + 7c36141 commit 9f585bc

39 files changed

Lines changed: 257 additions & 305 deletions

.github/workflows/build.yml

Lines changed: 23 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -16,70 +16,27 @@ jobs:
1616
lint:
1717
runs-on: ubuntu-latest
1818
steps:
19-
- uses: actions/checkout@v3
20-
21-
- name: Set up Python
22-
uses: actions/setup-python@v4
19+
- uses: actions/checkout@v6
20+
- uses: actions/setup-python@v6
2321
with:
24-
python-version: 3.9
25-
26-
- name: Install dependencies
27-
run: |
28-
python -m pip install --upgrade pip
29-
pip install -r requirements-dev.txt
30-
- name: Lint with flake8
31-
run: |
32-
# stop the build if there are Python syntax errors or undefined names
33-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
34-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
35-
flake8 . --count --exit-zero --max-complexity=11 --max-line-length=127 --statistics
36-
flake8 --filename='*.pyx,*.px*' --ignore E901,E225,E226,E227,E402,E999
37-
- name: Lint with black
38-
run: |
39-
black --check .
40-
- name: Lint with clang-format
41-
run: |
42-
sudo apt install clang-format
43-
find implicit | grep -E '\.(cu|cuh|h|cpp)$' | xargs clang-format --dry-run --Werror
44-
if: runner.os == 'Linux'
45-
- name: Lint with isort
46-
run: |
47-
isort -c .
48-
- name: Lint with codespell
49-
run: |
50-
codespell
51-
- name: Lint with pylint
52-
run: |
53-
pylint implicit tests benchmarks examples
22+
python-version: 3.12
23+
- uses: pre-commit/action@v3.0.1
5424

5525
build-wheels:
5626
needs: [lint]
5727
runs-on: ${{ matrix.os }}
5828
strategy:
5929
matrix:
60-
os: [macos-latest, ubuntu-latest, windows-latest]
61-
python-version: [36, 37, 38, 39, 310, 311, 312]
62-
cibw-arch: [auto, aarch64]
63-
exclude:
64-
- os: macos-latest
65-
cibw-arch: aarch64
66-
- os: windows-latest
67-
cibw-arch: aarch64
30+
os: [macos-latest, ubuntu-latest, windows-latest, ubuntu-24.04-arm]
31+
python-version: [39, 310, 311, 312, 313, 314]
6832

6933
steps:
70-
- uses: actions/checkout@v3
71-
72-
- name: Set up QEMU
73-
if: runner.os == 'Linux'
74-
uses: docker/setup-qemu-action@v3
75-
with:
76-
platforms: all
34+
- uses: actions/checkout@v6
7735

7836
- name: Build wheels
79-
uses: pypa/cibuildwheel@v2.16.2
8037
env:
8138
CIBW_BUILD: cp${{matrix.python-version}}-*
82-
CIBW_ARCHS_LINUX: ${{ matrix.cibw-arch }}
39+
uses: pypa/cibuildwheel@v3.4.1
8340

8441
- name: Build sdist
8542
run: |
@@ -93,42 +50,39 @@ jobs:
9350
if: runner.os == 'Linux'
9451

9552
- name: Upload Binaries
96-
uses: actions/upload-artifact@v3
53+
uses: actions/upload-artifact@v7
9754
with:
98-
name: wheels
99-
path: wheelhouse
55+
name: wheels-${{ matrix.os }}-${{ matrix.python-version }}
56+
path: ./wheelhouse/*.whl
10057

10158
test-wheels:
10259
needs: [build-wheels]
10360
runs-on: ${{ matrix.os }}
10461
strategy:
10562
matrix:
106-
python-version: [3.7, 3.8, 3.9, '3.10', '3.11', '3.12']
107-
os: [macos-latest, ubuntu-latest, windows-latest]
63+
python-version: [3.9, '3.10', '3.11', '3.12', '3.13', '3.14']
64+
os: [macos-latest, ubuntu-latest, windows-latest, ubuntu-24.04-arm]
10865

10966
steps:
110-
- uses: actions/checkout@v3
67+
- uses: actions/checkout@v6
11168
with:
11269
path: implicit_source
113-
- uses: actions/download-artifact@v3
70+
- uses: actions/download-artifact@v8
11471
with:
115-
name: wheels
72+
pattern: wheels-${{ matrix.os }}-*
73+
merge-multiple: true
11674
- name: Set up Python ${{ matrix.python-version }}
117-
uses: actions/setup-python@v4
75+
uses: actions/setup-python@v6
11876
with:
11977
python-version: ${{ matrix.python-version }}
12078
- name: Install dependencies
12179
run: |
12280
python -m pip install --upgrade pip
12381
pip install pytest
12482
pip install -r implicit_source/requirements.txt
125-
- name: Install h5py
126-
run: pip install h5py
127-
12883
- name: Install ANN Libraries
12984
run: pip install annoy nmslib
130-
if: ${{ matrix.python-version != '3.12' && matrix.python-version != '3.11' && runner.os == 'Linux' }}
131-
85+
if: ${{ matrix.python-version != '3.14' && runner.os == 'Linux' }}
13286
- name: Install wheel
13387
run: |
13488
pip install --force-reinstall --no-deps --no-index --find-links . implicit
@@ -142,15 +96,16 @@ jobs:
14296
if: "startsWith(github.ref, 'refs/tags/')"
14397
needs: [test-wheels]
14498
steps:
145-
- uses: actions/download-artifact@v3
99+
- uses: actions/download-artifact@v8
146100
with:
147-
name: wheels
101+
pattern: wheels-*
102+
merge-multiple: true
148103
- name: Create GitHub Release
149104
uses: fnkr/github-action-ghr@v1.3
150105
env:
151106
GHR_PATH: .
152107
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
153-
- uses: actions/setup-python@v2
108+
- uses: actions/setup-python@v6
154109
with:
155110
python-version: 3.9
156111
- name: Push to PyPi

.pre-commit-config.yaml

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,18 @@
11
repos:
2-
- repo: https://github.com/timothycrosley/isort
3-
rev: 5.12.0
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.15.12
44
hooks:
5-
- id: isort
6-
additional_dependencies: [toml]
7-
- repo: https://github.com/python/black
8-
rev: 23.3.0
9-
hooks:
10-
- id: black
11-
- repo: https://github.com/pycqa/flake8
12-
rev: 6.0.0
13-
hooks:
14-
- id: flake8
15-
- repo: https://github.com/pycqa/pylint
16-
rev: v2.17.4
17-
hooks:
18-
- id: pylint
5+
- id: ruff-check
6+
types_or: [ python, pyi, jupyter, pyproject ]
7+
args: [ --fix ]
8+
- id: ruff-format
199
- repo: https://github.com/codespell-project/codespell
2010
rev: v2.2.4
2111
hooks:
2212
- id: codespell
23-
- repo: local
13+
- repo: https://github.com/pre-commit/mirrors-clang-format
14+
rev: v22.1.4
2415
hooks:
2516
- id: clang-format
26-
name: clang-format
27-
description: Format files with ClangFormat.
28-
entry: clang-format --dry-run --Werror
29-
language: system
3017
files: \.(cu|cuh|h|cpp)$
3118

.pylintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,6 @@ disable=fixme,
4545
min-similarity-lines=64
4646
ignore-docstrings=yes
4747
ignore-imports=yes
48+
49+
[DESIGN]
50+
max-positional-arguments=12

CMakeLists.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
cmake_minimum_required(VERSION 3.17.0)
1+
cmake_minimum_required(VERSION 3.21...4.0)
22

33
project(implicit)
44

5+
find_package(
6+
Python
7+
COMPONENTS Interpreter Development.Module
8+
REQUIRED)
9+
include(UseCython)
10+
511
enable_testing()
612

7-
find_package(PythonExtensions REQUIRED)
8-
find_package(Cython REQUIRED)
913
find_package(OpenMP)
1014

1115
include_directories(.)
12-
set (CMAKE_CXX_STANDARD 11)
16+
set (CMAKE_CXX_STANDARD 17)
1317
add_subdirectory(implicit)

benchmarks/benchmark_als.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
""" test script to verify the CG method works, and time it versus cholesky """
1+
"""test script to verify the CG method works, and time it versus cholesky"""
2+
23
import argparse
34
import json
45
import logging

ci/install_cuda.sh

Lines changed: 0 additions & 9 deletions
This file was deleted.

ci/install_cuda_13.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
dnf config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel8/x86_64/cuda-rhel8.repo
2+
3+
dnf install -y \
4+
cuda-nvcc-13-0 \
5+
cuda-cudart-devel-13-0 \
6+
libcurand-devel-13-0 \
7+
libcublas-devel-13-0
8+
9+
ln -s cuda-13.0 /usr/local/cuda

examples/lastfm.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
""" An example of using this library to calculate related artists
1+
"""An example of using this library to calculate related artists
22
from the last.fm dataset. More details can be found
33
at http://www.benfrederickson.com/matrix-factorization/
44
55
This code will automatically download a HDF5 version of the dataset from
66
GitHub when it is first run. The original dataset can also be found at
77
http://ocelma.net/MusicRecommendationDataset/lastfm-360K.html
88
"""
9+
910
import argparse
10-
import codecs
1111
import logging
1212
import time
1313

@@ -102,7 +102,7 @@ def calculate_similar_artists(output_filename, model_name="als"):
102102
# write out as a TSV of artistid, otherartistid, score
103103
logging.debug("writing similar items")
104104
with tqdm.tqdm(total=len(to_generate)) as progress:
105-
with codecs.open(output_filename, "w", "utf8") as o:
105+
with open(output_filename, "w", encoding="utf8") as o:
106106
batch_size = 1000
107107
for startidx in range(0, len(to_generate), batch_size):
108108
batch = to_generate[startidx : startidx + batch_size]
@@ -146,7 +146,7 @@ def calculate_recommendations(output_filename, model_name="als"):
146146
# generate recommendations for each user and write out to a file
147147
start = time.time()
148148
with tqdm.tqdm(total=len(users)) as progress:
149-
with codecs.open(output_filename, "w", "utf8") as o:
149+
with open(output_filename, "w", encoding="utf8") as o:
150150
batch_size = 1000
151151
to_generate = np.arange(len(users))
152152
for startidx in range(0, len(to_generate), batch_size):

examples/movielens.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from __future__ import print_function
1414

1515
import argparse
16-
import codecs
1716
import logging
1817
import time
1918

@@ -87,7 +86,7 @@ def calculate_similar_movies(output_filename, model_name="als", min_rating=4.0,
8786

8887
log.debug("calculating similar movies")
8988
with tqdm.tqdm(total=len(to_generate)) as progress:
90-
with codecs.open(output_filename, "w", "utf8") as o:
89+
with open(output_filename, "w", encoding="utf8") as o:
9190
batch_size = 1000
9291
for startidx in range(0, len(to_generate), batch_size):
9392
batch = to_generate[startidx : startidx + batch_size]

examples/tutorial_lastfm.ipynb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,12 @@
8585
"source": [
8686
"from implicit.nearest_neighbours import bm25_weight\n",
8787
"\n",
88-
"# weight the matrix, both to reduce impact of users that have played the same artist thousands of times\n",
89-
"# and to reduce the weight given to popular items\n",
88+
"# weight the matrix, both to reduce impact of users that have played the same artist thousands\n",
89+
"# of times and to reduce the weight given to popular items\n",
9090
"artist_user_plays = bm25_weight(artist_user_plays, K1=100, B=0.8)\n",
9191
"\n",
92-
"# get the transpose since the most of the functions in implicit expect (user, item) sparse matrices instead of (item, user)\n",
92+
"# get the transpose since the most of the functions in implicit expect (user, item) sparse\n",
93+
"# matrices instead of (item, user)\n",
9394
"user_plays = artist_user_plays.T.tocsr()"
9495
]
9596
},
@@ -293,7 +294,14 @@
293294
"# Use pandas to display the output in a table, pandas isn't a dependency of implicit otherwise\n",
294295
"import numpy as np\n",
295296
"import pandas as pd\n",
296-
"pd.DataFrame({\"artist\": artists[ids], \"score\": scores, \"already_liked\": np.in1d(ids, user_plays[userid].indices)})"
297+
"\n",
298+
"pd.DataFrame(\n",
299+
" {\n",
300+
" \"artist\": artists[ids],\n",
301+
" \"score\": scores,\n",
302+
" \"already_liked\": np.isin(ids, user_plays[userid].indices),\n",
303+
" }\n",
304+
")"
297305
]
298306
},
299307
{
@@ -423,7 +431,7 @@
423431
],
424432
"source": [
425433
"# get related items for the beatles (itemid = 25512)\n",
426-
"ids, scores= model.similar_items(252512)\n",
434+
"ids, scores = model.similar_items(252512)\n",
427435
"\n",
428436
"# display the results using pandas for nicer formatting\n",
429437
"pd.DataFrame({\"artist\": artists[ids], \"score\": scores})"

0 commit comments

Comments
 (0)