turboquant-space 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,91 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+ workflow_dispatch:
7
+
8
+ jobs:
9
+ build_wheels:
10
+ name: ${{ matrix.os }} ${{ matrix.arch }}
11
+ runs-on: ${{ matrix.os }}
12
+ strategy:
13
+ fail-fast: false
14
+ matrix:
15
+ include:
16
+ - os: ubuntu-latest
17
+ arch: x86_64
18
+ - os: ubuntu-24.04-arm
19
+ arch: aarch64
20
+ # - os: windows-latest
21
+ # arch: AMD64
22
+ - os: macos-15-intel
23
+ arch: x86_64
24
+ - os: macos-latest
25
+ arch: arm64
26
+
27
+ steps:
28
+ - uses: actions/checkout@v6
29
+
30
+ - name: Build wheels
31
+ uses: pypa/cibuildwheel@v3.4.1
32
+ env:
33
+ CIBW_ARCHS: ${{ matrix.arch }}
34
+ CIBW_BUILD: "cp311-* cp312-* cp313-*"
35
+ CIBW_SKIP: "*-musllinux_* pp*"
36
+ CIBW_BUILD_VERBOSITY: 1
37
+ CIBW_ENVIRONMENT: >-
38
+ CMAKE_ARGS="-DTURBOQUANT_PORTABLE=ON"
39
+ CIBW_BEFORE_BUILD_MACOS: brew install libomp
40
+ CIBW_TEST_REQUIRES: pytest numpy
41
+ CIBW_TEST_COMMAND: pytest {project}/python/tests -v
42
+ # macOS x86_64 runners may lack AVX2; MSVC /arch:AVX2 also requires it,
43
+ # but the portable Linux baseline (x86-64-v3) implies AVX2 as well.
44
+ MACOSX_DEPLOYMENT_TARGET: "15.0"
45
+ CIBW_ENVIRONMENT_WINDOWS: >-
46
+ CMAKE_ARGS="-DTURBOQUANT_PORTABLE=ON -DOpenMP_CXX_FLAGS=/openmp"
47
+ CMAKE_GENERATOR="Ninja"
48
+ CIBW_BEFORE_BUILD_WINDOWS: "pip install ninja"
49
+
50
+ - uses: actions/upload-artifact@v7
51
+ with:
52
+ name: wheels-${{ matrix.os }}-${{ matrix.arch }}
53
+ path: ./wheelhouse/*.whl
54
+
55
+ build_sdist:
56
+ name: Build sdist
57
+ runs-on: ubuntu-latest
58
+ steps:
59
+ - uses: actions/checkout@v6
60
+
61
+ - uses: actions/setup-python@v6.2.0
62
+ with:
63
+ python-version: "3.12"
64
+
65
+ - name: Build sdist
66
+ run: |
67
+ pip install build
68
+ python -m build --sdist
69
+
70
+ - uses: actions/upload-artifact@v7
71
+ with:
72
+ name: sdist
73
+ path: ./dist/*.tar.gz
74
+
75
+ publish:
76
+ name: Publish to PyPI
77
+ needs: [build_wheels, build_sdist]
78
+ runs-on: ubuntu-latest
79
+ if: github.event_name == 'release'
80
+ environment:
81
+ name: pypi
82
+ url: https://pypi.org/p/turboquant-space
83
+ permissions:
84
+ id-token: write
85
+ steps:
86
+ - uses: actions/download-artifact@v7
87
+ with:
88
+ path: dist
89
+ merge-multiple: true
90
+
91
+ - uses: pypa/gh-action-pypi-publish@v1.13.0
@@ -0,0 +1,49 @@
1
+ name: Tests
2
+
3
+ on:
4
+ push:
5
+ branches: [master, main]
6
+ pull_request:
7
+ branches: [master, main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ${{ matrix.os }}
12
+ strategy:
13
+ fail-fast: false
14
+ matrix:
15
+ include:
16
+ - os: ubuntu-latest
17
+ arch: x64
18
+ - os: ubuntu-24.04-arm
19
+ arch: arm64
20
+ - os: windows-latest
21
+ arch: x64
22
+ - os: macos-latest
23
+ arch: arm64
24
+ python-version: ["3.11", "3.12", "3.13"]
25
+
26
+ steps:
27
+ - uses: actions/checkout@v4
28
+
29
+ - name: Install libomp (macOS)
30
+ if: runner.os == 'macOS'
31
+ run: brew install libomp
32
+
33
+ - name: Install uv
34
+ uses: astral-sh/setup-uv@v4
35
+
36
+ - name: Set up Python ${{ matrix.python-version }}
37
+ run: uv python install ${{ matrix.python-version }}
38
+
39
+ - name: Install dependencies
40
+ run: uv sync
41
+
42
+ - name: Report SIMD target
43
+ shell: bash
44
+ run: |
45
+ echo "OS=${{ matrix.os }} ARCH=${{ matrix.arch }} PY=${{ matrix.python-version }}"
46
+ uv run python -c "import platform; print('machine:', platform.machine())"
47
+
48
+ - name: Run tests
49
+ run: uv run pytest python/tests/ -v
@@ -0,0 +1,224 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ # Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ # poetry.lock
109
+ # poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ # pdm.lock
116
+ # pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ # pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # Redis
135
+ *.rdb
136
+ *.aof
137
+ *.pid
138
+
139
+ # RabbitMQ
140
+ mnesia/
141
+ rabbitmq/
142
+ rabbitmq-data/
143
+
144
+ # ActiveMQ
145
+ activemq-data/
146
+
147
+ # SageMath parsed files
148
+ *.sage.py
149
+
150
+ # Environments
151
+ .env
152
+ .envrc
153
+ .venv
154
+ env/
155
+ venv/
156
+ ENV/
157
+ env.bak/
158
+ venv.bak/
159
+
160
+ # Spyder project settings
161
+ .spyderproject
162
+ .spyproject
163
+
164
+ # Rope project settings
165
+ .ropeproject
166
+
167
+ # mkdocs documentation
168
+ /site
169
+
170
+ # mypy
171
+ .mypy_cache/
172
+ .dmypy.json
173
+ dmypy.json
174
+
175
+ # Pyre type checker
176
+ .pyre/
177
+
178
+ # pytype static type analyzer
179
+ .pytype/
180
+
181
+ # Cython debug symbols
182
+ cython_debug/
183
+
184
+ # PyCharm
185
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
186
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
187
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
188
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
189
+ # .idea/
190
+
191
+ # Abstra
192
+ # Abstra is an AI-powered process automation framework.
193
+ # Ignore directories containing user credentials, local state, and settings.
194
+ # Learn more at https://abstra.io/docs
195
+ .abstra/
196
+
197
+ # Visual Studio Code
198
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
199
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
200
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
201
+ # you could uncomment the following to ignore the entire vscode folder
202
+ # .vscode/
203
+
204
+ # Ruff stuff:
205
+ .ruff_cache/
206
+
207
+ # PyPI configuration file
208
+ .pypirc
209
+
210
+ # Marimo
211
+ marimo/_static/
212
+ marimo/_lsp/
213
+ __marimo__/
214
+
215
+ # Streamlit
216
+ .streamlit/secrets.toml
217
+
218
+ */benchmarks/results/
219
+
220
+ *.DS_Store
221
+ *.idea
222
+ *.memsearch
223
+ *.qtcreator
224
+ turboquant-handoff.md
@@ -0,0 +1,96 @@
1
+ cmake_minimum_required(VERSION 3.18...4.31)
2
+
3
+ project(turboquant_space LANGUAGES CXX)
4
+
5
+ set(CMAKE_CXX_STANDARD 17)
6
+ set(CMAKE_CXX_STANDARD_REQUIRED ON)
7
+ set(CMAKE_CXX_EXTENSIONS OFF)
8
+
9
+ find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)
10
+
11
+ execute_process(
12
+ COMMAND "${Python_EXECUTABLE}" -c "import pybind11; print(pybind11.get_cmake_dir())"
13
+ OUTPUT_VARIABLE PYBIND11_DIR
14
+ OUTPUT_STRIP_TRAILING_WHITESPACE
15
+ ERROR_VARIABLE PY_ERROR
16
+ RESULT_VARIABLE PY_RESULT
17
+ )
18
+
19
+ if(NOT PY_RESULT EQUAL 0 OR NOT PYBIND11_DIR)
20
+ message(FATAL_ERROR "pybind11 not found via ${Python_EXECUTABLE}! Error: ${PY_ERROR}")
21
+ endif()
22
+
23
+ find_package(pybind11 REQUIRED PATHS ${PYBIND11_DIR} NO_DEFAULT_PATH)
24
+
25
+ pybind11_add_module(_turboquant python/turboquant/bindings.cpp)
26
+
27
+ target_include_directories(_turboquant PRIVATE
28
+ ${PROJECT_SOURCE_DIR}/include
29
+ )
30
+
31
+ # --- OpenMP (optional) ------------------------------------------------------
32
+ # Apple Clang ships without OpenMP; find_package can't locate Homebrew libomp
33
+ # by itself, so we provide hints when running on macOS.
34
+ if(APPLE)
35
+ execute_process(
36
+ COMMAND brew --prefix libomp
37
+ OUTPUT_VARIABLE LIBOMP_PREFIX
38
+ OUTPUT_STRIP_TRAILING_WHITESPACE
39
+ ERROR_QUIET
40
+ RESULT_VARIABLE LIBOMP_BREW_RC
41
+ )
42
+ if(LIBOMP_BREW_RC EQUAL 0 AND EXISTS "${LIBOMP_PREFIX}")
43
+ set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I${LIBOMP_PREFIX}/include")
44
+ set(OpenMP_CXX_LIB_NAMES "omp")
45
+ set(OpenMP_omp_LIBRARY "${LIBOMP_PREFIX}/lib/libomp.dylib")
46
+ endif()
47
+ endif()
48
+
49
+ find_package(OpenMP)
50
+ if(OpenMP_CXX_FOUND)
51
+ message(STATUS "OpenMP found: parallel batch ops enabled")
52
+ target_link_libraries(_turboquant PRIVATE OpenMP::OpenMP_CXX)
53
+ target_compile_definitions(_turboquant PRIVATE TURBOQUANT_HAVE_OPENMP)
54
+ else()
55
+ message(STATUS "OpenMP not found: batch ops will run single-threaded")
56
+ endif()
57
+
58
+ set_target_properties(_turboquant PROPERTIES
59
+ LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/python/turboquant"
60
+ RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/python/turboquant"
61
+ )
62
+
63
+ # TURBOQUANT_PORTABLE=ON → conservative baseline for prebuilt wheels
64
+ # (x86-64-v3 on x64, armv8-a on arm64, /arch:AVX2 on MSVC).
65
+ # TURBOQUANT_PORTABLE=OFF → -march=native, tuned for the build machine.
66
+ # Default is OFF so local `pip install` / `uv sync` get max performance;
67
+ # cibuildwheel sets it to ON to produce portable wheels.
68
+ option(TURBOQUANT_PORTABLE "Build with a portable CPU baseline instead of -march=native" OFF)
69
+
70
+ if(MSVC)
71
+ target_compile_options(_turboquant PRIVATE /O2 /fp:fast /arch:AVX2)
72
+ else()
73
+ target_compile_options(_turboquant PRIVATE
74
+ -O3
75
+ -ffast-math
76
+ -fno-finite-math-only
77
+ )
78
+ if(TURBOQUANT_PORTABLE)
79
+ if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64|amd64)$")
80
+ target_compile_options(_turboquant PRIVATE -march=x86-64-v3)
81
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64)$")
82
+ target_compile_options(_turboquant PRIVATE -march=armv8-a)
83
+ endif()
84
+ else()
85
+ target_compile_options(_turboquant PRIVATE -march=native)
86
+ endif()
87
+ endif()
88
+
89
+ target_compile_definitions(_turboquant PRIVATE
90
+ $<$<CONFIG:Debug>:DEBUG_MODE>
91
+ $<$<CONFIG:Release>:NDEBUG>
92
+ )
93
+
94
+ # Install the compiled module next to the Python package sources so
95
+ # `from turboquant import _turboquant` resolves inside the installed wheel.
96
+ install(TARGETS _turboquant LIBRARY DESTINATION turboquant)
@@ -0,0 +1,7 @@
1
+ Copyright 2026 Ilya Derendyaev
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.