usearch 2.8.3 → 2.8.4
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.
- package/.vscode/settings.json +1 -0
- package/CITATION.cff +1 -1
- package/CONTRIBUTING.md +258 -6
- package/Cargo.toml +1 -1
- package/README.md +57 -53
- package/conanfile.py +1 -1
- package/cpp/README.md +89 -21
- package/csharp/DEV_SETUP.md +1 -1
- package/csharp/nuget/nuget-package.props +1 -1
- package/docs/{compilation.rst → contributing.rst} +2 -2
- package/docs/index.rst +1 -1
- package/include/usearch/index.hpp +1 -1
- package/include/usearch/index_dense.hpp +11 -7
- package/package.json +1 -1
- package/python/README.md +1 -1
- package/simsimd/CMakeLists.txt +1 -1
- package/simsimd/README.md +7 -1
- package/simsimd/include/simsimd/probability.h +24 -24
- package/simsimd/include/simsimd/types.h +8 -0
- package/simsimd/javascript/{test.js → test/simsimd.test.js} +15 -15
- package/simsimd/package.json +4 -8
- package/simsimd/setup.py +3 -0
- package/wasmer.toml +1 -1
- package/docs/compilation.md +0 -215
- package/simsimd/.clang-format +0 -10
- package/simsimd/.github/workflows/prerelease.yml +0 -89
- package/simsimd/.github/workflows/release.yml +0 -141
- package/simsimd/.github/workflows/update_version.sh +0 -5
- package/simsimd/.vscode/launch.json +0 -53
- package/simsimd/.vscode/settings.json +0 -114
- package/simsimd/.vscode/tasks.json +0 -23
- package/simsimd/go.mod +0 -3
- package/simsimd/golang/bench_test.go +0 -40
- package/simsimd/golang/simsimd.go +0 -47
- package/simsimd/golang/unit_test.go +0 -40
- package/simsimd/pyproject.toml +0 -42
- package/simsimd/python/bench.ipynb +0 -187
- package/simsimd/python/bench.py +0 -268
- package/simsimd/python/lib.c +0 -492
- package/simsimd/python/test.py +0 -195
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
name: Pre-Release
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches: ["main-dev"]
|
|
6
|
-
pull_request:
|
|
7
|
-
branches: ["main-dev"]
|
|
8
|
-
|
|
9
|
-
env:
|
|
10
|
-
BUILD_TYPE: Release
|
|
11
|
-
GH_TOKEN: ${{ secrets.SEMANTIC_RELEASE_TOKEN }}
|
|
12
|
-
PYTHONUTF8: 1
|
|
13
|
-
|
|
14
|
-
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
|
|
15
|
-
permissions:
|
|
16
|
-
contents: read
|
|
17
|
-
|
|
18
|
-
jobs:
|
|
19
|
-
test_python:
|
|
20
|
-
name: Test Python ${{ matrix.python-version }} on ${{ matrix.architecture }} ${{ matrix.os }}
|
|
21
|
-
runs-on: ${{ matrix.os }}
|
|
22
|
-
strategy:
|
|
23
|
-
fail-fast: false
|
|
24
|
-
matrix:
|
|
25
|
-
os: [ubuntu-22.04, macOS-11, windows-2022]
|
|
26
|
-
python-version: ["3.12", "3.8"]
|
|
27
|
-
architecture: [x64, arm64]
|
|
28
|
-
|
|
29
|
-
steps:
|
|
30
|
-
- uses: actions/checkout@v3
|
|
31
|
-
- run: git submodule update --init --recursive
|
|
32
|
-
- name: Set up Python ${{ matrix.python-version }}
|
|
33
|
-
uses: actions/setup-python@v4
|
|
34
|
-
with:
|
|
35
|
-
python-version: ${{ matrix.python-version }}
|
|
36
|
-
|
|
37
|
-
- name: Install dependencies
|
|
38
|
-
run: |
|
|
39
|
-
python -m pip install --no-cache-dir --upgrade pip
|
|
40
|
-
pip install --no-cache-dir pytest numpy scipy py-cpuinfo pytest-repeat
|
|
41
|
-
python -c "from cpuinfo import get_cpu_info; print(get_cpu_info())"
|
|
42
|
-
|
|
43
|
-
- name: Build locally on Ubuntu
|
|
44
|
-
run: |
|
|
45
|
-
sudo apt-get update
|
|
46
|
-
sudo apt-get install gcc-12 -y
|
|
47
|
-
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 12
|
|
48
|
-
sudo update-alternatives --config gcc
|
|
49
|
-
gcc --version
|
|
50
|
-
python -m pip install .
|
|
51
|
-
if: ${{ matrix.os == 'ubuntu-22.04' }}
|
|
52
|
-
|
|
53
|
-
- name: Build locally on other OS
|
|
54
|
-
run: python -m pip install .
|
|
55
|
-
if: ${{ matrix.os != 'ubuntu-22.04' }}
|
|
56
|
-
|
|
57
|
-
- name: Test with PyTest
|
|
58
|
-
run: |
|
|
59
|
-
python -c "import simsimd; print(simsimd.get_capabilities())"
|
|
60
|
-
pytest python/test.py -s -x -v
|
|
61
|
-
|
|
62
|
-
test_javascript:
|
|
63
|
-
name: Test JavaScript
|
|
64
|
-
runs-on: ubuntu-22.04
|
|
65
|
-
env:
|
|
66
|
-
CC: gcc-12
|
|
67
|
-
CXX: g++-12
|
|
68
|
-
|
|
69
|
-
steps:
|
|
70
|
-
- uses: actions/checkout@v4
|
|
71
|
-
with:
|
|
72
|
-
ref: "main"
|
|
73
|
-
- run: git submodule update --init --recursive
|
|
74
|
-
|
|
75
|
-
- name: Update compilers
|
|
76
|
-
run: |
|
|
77
|
-
sudo apt update
|
|
78
|
-
sudo apt install -y cmake build-essential libjemalloc-dev libomp-dev gcc-12 g++-12
|
|
79
|
-
|
|
80
|
-
- name: Set up Node.js
|
|
81
|
-
uses: actions/setup-node@v3
|
|
82
|
-
with:
|
|
83
|
-
node-version: 18
|
|
84
|
-
|
|
85
|
-
- name: Build and Test
|
|
86
|
-
run: |
|
|
87
|
-
npm install
|
|
88
|
-
npm ci
|
|
89
|
-
npm test
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
name: Release
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches: ["main"]
|
|
6
|
-
|
|
7
|
-
env:
|
|
8
|
-
BUILD_TYPE: Release
|
|
9
|
-
GH_TOKEN: ${{ secrets.SEMANTIC_RELEASE_TOKEN }}
|
|
10
|
-
PYTHONUTF8: 1
|
|
11
|
-
|
|
12
|
-
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
|
|
13
|
-
permissions:
|
|
14
|
-
contents: write
|
|
15
|
-
pages: write
|
|
16
|
-
id-token: write
|
|
17
|
-
|
|
18
|
-
jobs:
|
|
19
|
-
versioning:
|
|
20
|
-
name: Semantic Release
|
|
21
|
-
runs-on: ubuntu-22.04
|
|
22
|
-
steps:
|
|
23
|
-
- uses: actions/checkout@v3
|
|
24
|
-
with:
|
|
25
|
-
persist-credentials: false
|
|
26
|
-
- uses: actions/setup-node@v3
|
|
27
|
-
- run: npm install --save-dev --prefix ./package-ci @semantic-release/exec @semantic-release/git conventional-changelog-eslint semantic-release && npx --prefix ./package-ci semantic-release
|
|
28
|
-
|
|
29
|
-
rebase:
|
|
30
|
-
name: Rebase Dev. Branch
|
|
31
|
-
needs: versioning
|
|
32
|
-
runs-on: ubuntu-22.04
|
|
33
|
-
steps:
|
|
34
|
-
- name: Checkout the latest code
|
|
35
|
-
uses: actions/checkout@v3
|
|
36
|
-
with:
|
|
37
|
-
fetch-depth: 0
|
|
38
|
-
|
|
39
|
-
- name: Perform rebase
|
|
40
|
-
run: |
|
|
41
|
-
git fetch origin main
|
|
42
|
-
git checkout main-dev
|
|
43
|
-
git rebase origin/main
|
|
44
|
-
|
|
45
|
-
- name: Push changes
|
|
46
|
-
uses: CasperWA/push-protected@v2
|
|
47
|
-
with:
|
|
48
|
-
token: ${{ secrets.SEMANTIC_REBASE_TOKEN }}
|
|
49
|
-
branch: main-dev
|
|
50
|
-
unprotect_reviews: True
|
|
51
|
-
force: True
|
|
52
|
-
|
|
53
|
-
build_wheels:
|
|
54
|
-
name: Build Wheels for ${{ matrix.os }}
|
|
55
|
-
runs-on: ${{ matrix.os }}
|
|
56
|
-
needs: versioning
|
|
57
|
-
strategy:
|
|
58
|
-
fail-fast: false
|
|
59
|
-
matrix:
|
|
60
|
-
os: [ubuntu-22.04, macOS-11, windows-2022]
|
|
61
|
-
steps:
|
|
62
|
-
- uses: actions/checkout@v3
|
|
63
|
-
with:
|
|
64
|
-
ref: "main"
|
|
65
|
-
- uses: actions/setup-python@v3
|
|
66
|
-
|
|
67
|
-
- name: Setup Docker
|
|
68
|
-
if: matrix.os == 'ubuntu-22.04'
|
|
69
|
-
uses: docker-practice/actions-setup-docker@master
|
|
70
|
-
|
|
71
|
-
- name: Setup QEMU
|
|
72
|
-
if: matrix.os == 'ubuntu-22.04'
|
|
73
|
-
uses: docker/setup-qemu-action@v2.1.0
|
|
74
|
-
|
|
75
|
-
- name: Install CIBuildWheel
|
|
76
|
-
run: python -m pip install --no-cache-dir cibuildwheel
|
|
77
|
-
|
|
78
|
-
- name: Build wheels
|
|
79
|
-
run: python -m cibuildwheel
|
|
80
|
-
|
|
81
|
-
- uses: actions/upload-artifact@v3
|
|
82
|
-
with:
|
|
83
|
-
path: ./wheelhouse/*.whl
|
|
84
|
-
|
|
85
|
-
publish_python:
|
|
86
|
-
name: Publish Python
|
|
87
|
-
needs: build_wheels
|
|
88
|
-
runs-on: ubuntu-22.04
|
|
89
|
-
environment:
|
|
90
|
-
name: pypi
|
|
91
|
-
url: https://pypi.org/p/simsimd
|
|
92
|
-
permissions:
|
|
93
|
-
id-token: write
|
|
94
|
-
|
|
95
|
-
steps:
|
|
96
|
-
- name: Download artifacts
|
|
97
|
-
uses: actions/download-artifact@v3.0.2
|
|
98
|
-
with:
|
|
99
|
-
path: ./dist/
|
|
100
|
-
|
|
101
|
-
- name: Publish to PyPi
|
|
102
|
-
uses: pypa/gh-action-pypi-publish@release/v1
|
|
103
|
-
with:
|
|
104
|
-
packages-dir: ./dist/artifact
|
|
105
|
-
verbose: true
|
|
106
|
-
print-hash: true
|
|
107
|
-
|
|
108
|
-
publish_javascript:
|
|
109
|
-
name: Publish JavaScript
|
|
110
|
-
needs: versioning
|
|
111
|
-
runs-on: ubuntu-22.04
|
|
112
|
-
env:
|
|
113
|
-
CC: gcc-12
|
|
114
|
-
CXX: g++-12
|
|
115
|
-
|
|
116
|
-
steps:
|
|
117
|
-
- uses: actions/checkout@v3
|
|
118
|
-
with:
|
|
119
|
-
ref: "main"
|
|
120
|
-
- run: git submodule update --init --recursive
|
|
121
|
-
|
|
122
|
-
- name: Update compilers
|
|
123
|
-
run: |
|
|
124
|
-
sudo apt update
|
|
125
|
-
sudo apt install -y cmake build-essential libjemalloc-dev libomp-dev gcc-12 g++-12
|
|
126
|
-
|
|
127
|
-
- name: Set up Node.js
|
|
128
|
-
uses: actions/setup-node@v3
|
|
129
|
-
with:
|
|
130
|
-
node-version: 18
|
|
131
|
-
|
|
132
|
-
- name: Build and Test
|
|
133
|
-
run: |
|
|
134
|
-
npm install
|
|
135
|
-
npm ci
|
|
136
|
-
npm test
|
|
137
|
-
|
|
138
|
-
- name: Publish
|
|
139
|
-
uses: JS-DevTools/npm-publish@v2
|
|
140
|
-
with:
|
|
141
|
-
token: ${{ secrets.NPM_TOKEN }}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// Use IntelliSense to learn about possible attributes.
|
|
3
|
-
// Hover to view descriptions of existing attributes.
|
|
4
|
-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
-
"version": "0.2.0",
|
|
6
|
-
"configurations": [
|
|
7
|
-
{
|
|
8
|
-
"name": "Debug Benchmark",
|
|
9
|
-
"type": "cppdbg",
|
|
10
|
-
"request": "launch",
|
|
11
|
-
"program": "${workspaceFolder}/build_debug/simsimd_bench",
|
|
12
|
-
"cwd": "${workspaceFolder}",
|
|
13
|
-
"args": [
|
|
14
|
-
"--benchmark_filter=i8_cos"
|
|
15
|
-
],
|
|
16
|
-
"environment": [
|
|
17
|
-
{
|
|
18
|
-
"name": "ASAN_OPTIONS",
|
|
19
|
-
"value": "detect_leaks=0:atexit=1:strict_init_order=1:strict_string_checks=1"
|
|
20
|
-
}
|
|
21
|
-
],
|
|
22
|
-
"stopAtEntry": false,
|
|
23
|
-
"preLaunchTask": "Build Benchmark: Debug",
|
|
24
|
-
"linux": {
|
|
25
|
-
"MIMode": "gdb",
|
|
26
|
-
},
|
|
27
|
-
"osx": {
|
|
28
|
-
"MIMode": "lldb"
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
"name": "Debug Test",
|
|
33
|
-
"type": "cppdbg",
|
|
34
|
-
"request": "launch",
|
|
35
|
-
"program": "${workspaceFolder}/build/test",
|
|
36
|
-
"cwd": "${workspaceFolder}",
|
|
37
|
-
"environment": [
|
|
38
|
-
{
|
|
39
|
-
"name": "ASAN_OPTIONS",
|
|
40
|
-
"value": "detect_leaks=0:atexit=1:strict_init_order=1:strict_string_checks=1"
|
|
41
|
-
}
|
|
42
|
-
],
|
|
43
|
-
"stopAtEntry": false,
|
|
44
|
-
"preLaunchTask": "Build Test: Debug",
|
|
45
|
-
"linux": {
|
|
46
|
-
"MIMode": "gdb"
|
|
47
|
-
},
|
|
48
|
-
"osx": {
|
|
49
|
-
"MIMode": "lldb"
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
]
|
|
53
|
-
}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"files.associations": {
|
|
3
|
-
"array": "cpp",
|
|
4
|
-
"string_view": "cpp",
|
|
5
|
-
"random": "cpp",
|
|
6
|
-
"atomic": "cpp",
|
|
7
|
-
"bit": "cpp",
|
|
8
|
-
"*.tcc": "cpp",
|
|
9
|
-
"bitset": "cpp",
|
|
10
|
-
"cctype": "cpp",
|
|
11
|
-
"chrono": "cpp",
|
|
12
|
-
"cinttypes": "cpp",
|
|
13
|
-
"clocale": "cpp",
|
|
14
|
-
"cmath": "cpp",
|
|
15
|
-
"codecvt": "cpp",
|
|
16
|
-
"compare": "cpp",
|
|
17
|
-
"concepts": "cpp",
|
|
18
|
-
"condition_variable": "cpp",
|
|
19
|
-
"cstdarg": "cpp",
|
|
20
|
-
"cstddef": "cpp",
|
|
21
|
-
"cstdint": "cpp",
|
|
22
|
-
"cstdio": "cpp",
|
|
23
|
-
"cstdlib": "cpp",
|
|
24
|
-
"cstring": "cpp",
|
|
25
|
-
"ctime": "cpp",
|
|
26
|
-
"cwchar": "cpp",
|
|
27
|
-
"cwctype": "cpp",
|
|
28
|
-
"deque": "cpp",
|
|
29
|
-
"list": "cpp",
|
|
30
|
-
"map": "cpp",
|
|
31
|
-
"set": "cpp",
|
|
32
|
-
"string": "cpp",
|
|
33
|
-
"unordered_map": "cpp",
|
|
34
|
-
"vector": "cpp",
|
|
35
|
-
"exception": "cpp",
|
|
36
|
-
"algorithm": "cpp",
|
|
37
|
-
"functional": "cpp",
|
|
38
|
-
"iterator": "cpp",
|
|
39
|
-
"memory": "cpp",
|
|
40
|
-
"memory_resource": "cpp",
|
|
41
|
-
"numeric": "cpp",
|
|
42
|
-
"ratio": "cpp",
|
|
43
|
-
"regex": "cpp",
|
|
44
|
-
"system_error": "cpp",
|
|
45
|
-
"tuple": "cpp",
|
|
46
|
-
"type_traits": "cpp",
|
|
47
|
-
"utility": "cpp",
|
|
48
|
-
"fstream": "cpp",
|
|
49
|
-
"initializer_list": "cpp",
|
|
50
|
-
"iomanip": "cpp",
|
|
51
|
-
"iosfwd": "cpp",
|
|
52
|
-
"iostream": "cpp",
|
|
53
|
-
"istream": "cpp",
|
|
54
|
-
"limits": "cpp",
|
|
55
|
-
"mutex": "cpp",
|
|
56
|
-
"new": "cpp",
|
|
57
|
-
"numbers": "cpp",
|
|
58
|
-
"ostream": "cpp",
|
|
59
|
-
"semaphore": "cpp",
|
|
60
|
-
"sstream": "cpp",
|
|
61
|
-
"stdexcept": "cpp",
|
|
62
|
-
"stop_token": "cpp",
|
|
63
|
-
"streambuf": "cpp",
|
|
64
|
-
"thread": "cpp",
|
|
65
|
-
"typeinfo": "cpp",
|
|
66
|
-
"complex": "cpp",
|
|
67
|
-
"immintrin.h": "c",
|
|
68
|
-
"__bit_reference": "cpp",
|
|
69
|
-
"__bits": "cpp",
|
|
70
|
-
"__config": "cpp",
|
|
71
|
-
"__debug": "cpp",
|
|
72
|
-
"__errc": "cpp",
|
|
73
|
-
"__hash_table": "cpp",
|
|
74
|
-
"__locale": "cpp",
|
|
75
|
-
"__mutex_base": "cpp",
|
|
76
|
-
"__node_handle": "cpp",
|
|
77
|
-
"__split_buffer": "cpp",
|
|
78
|
-
"__threading_support": "cpp",
|
|
79
|
-
"__tuple": "cpp",
|
|
80
|
-
"__verbose_abort": "cpp",
|
|
81
|
-
"charconv": "cpp",
|
|
82
|
-
"ios": "cpp",
|
|
83
|
-
"locale": "cpp",
|
|
84
|
-
"optional": "cpp",
|
|
85
|
-
"variant": "cpp",
|
|
86
|
-
"__nullptr": "cpp",
|
|
87
|
-
"unordered_set": "cpp",
|
|
88
|
-
"span": "cpp",
|
|
89
|
-
"arm_neon.h": "c",
|
|
90
|
-
"__tree": "cpp",
|
|
91
|
-
"filesystem": "cpp"
|
|
92
|
-
},
|
|
93
|
-
"cSpell.words": [
|
|
94
|
-
"castsi",
|
|
95
|
-
"dtype",
|
|
96
|
-
"dtypes",
|
|
97
|
-
"jaccard",
|
|
98
|
-
"kann",
|
|
99
|
-
"Kullback",
|
|
100
|
-
"Leibler",
|
|
101
|
-
"loadu",
|
|
102
|
-
"maccs",
|
|
103
|
-
"maskz",
|
|
104
|
-
"napi",
|
|
105
|
-
"simd",
|
|
106
|
-
"simsimd",
|
|
107
|
-
"sqeuclidean",
|
|
108
|
-
"tanimoto",
|
|
109
|
-
"typedarray",
|
|
110
|
-
"unsw",
|
|
111
|
-
"Vardanian",
|
|
112
|
-
"vpopcntdq"
|
|
113
|
-
]
|
|
114
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": "2.0.0",
|
|
3
|
-
"tasks": [
|
|
4
|
-
{
|
|
5
|
-
"label": "Build Benchmark: Debug",
|
|
6
|
-
"command": "cmake -DCMAKE_BUILD_TYPE=Debug -DSIMSIMD_BUILD_BENCHMARKS=1 -B ./build_debug && make -j 2 -C ./build_debug",
|
|
7
|
-
"args": [],
|
|
8
|
-
"type": "shell"
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
"label": "Build Test: Debug",
|
|
12
|
-
"command": "cmake -DCMAKE_BUILD_TYPE=Debug -B ./build && make test py_simsimd -C ./build",
|
|
13
|
-
"args": [],
|
|
14
|
-
"type": "shell"
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
"label": "Build Benchmark: Release",
|
|
18
|
-
"command": "cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DSIMSIMD_BUILD_BENCHMARKS=1 -B ./build_release && make -j 2 -C ./build_release",
|
|
19
|
-
"args": [],
|
|
20
|
-
"type": "shell"
|
|
21
|
-
}
|
|
22
|
-
]
|
|
23
|
-
}
|
package/simsimd/go.mod
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
package simsimd
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"math"
|
|
5
|
-
"math/rand"
|
|
6
|
-
"testing"
|
|
7
|
-
)
|
|
8
|
-
|
|
9
|
-
func cosineSimilarity(a, b []float32) float32 {
|
|
10
|
-
var dotProduct float32
|
|
11
|
-
var normA, normB float32
|
|
12
|
-
for i := range a {
|
|
13
|
-
dotProduct += a[i] * b[i]
|
|
14
|
-
normA += a[i] * a[i]
|
|
15
|
-
normB += b[i] * b[i]
|
|
16
|
-
}
|
|
17
|
-
return dotProduct / (float32(math.Sqrt(float64(normA))) * float32(math.Sqrt(float64(normB))))
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
func generateRandomVector(dim int) []float32 {
|
|
21
|
-
vec := make([]float32, dim)
|
|
22
|
-
for i := range vec {
|
|
23
|
-
vec[i] = rand.Float32()
|
|
24
|
-
}
|
|
25
|
-
return vec
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
func BenchmarkCosineSimilarityNative(b *testing.B) {
|
|
29
|
-
first, second := generateRandomVector(1536), generateRandomVector(1536)
|
|
30
|
-
for i := 0; i < b.N; i++ {
|
|
31
|
-
cosineSimilarity(first, second)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
func BenchmarkCosineSimilaritySIMD(b *testing.B) {
|
|
36
|
-
first, second := generateRandomVector(1536), generateRandomVector(1536)
|
|
37
|
-
for i := 0; i < b.N; i++ {
|
|
38
|
-
CosineF32(first, second)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
package simsimd
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
#cgo CFLAGS: -O3
|
|
5
|
-
#cgo LDFLAGS: -O3 -L.
|
|
6
|
-
#include "../simsimd/simsimd.h"
|
|
7
|
-
#include <stdlib.h>
|
|
8
|
-
|
|
9
|
-
inline static simsimd_f32_t cosine_i8(simsimd_i8_t const* a, simsimd_i8_t const* b, simsimd_size_t d) { return simsimd_metric_punned(simsimd_metric_cosine_k, simsimd_datatype_i8_k, simsimd_cap_any_k)(a, b, d, d); }
|
|
10
|
-
inline static simsimd_f32_t cosine_f32(simsimd_f32_t const* a, simsimd_f32_t const* b, simsimd_size_t d) { return simsimd_neon_f32_cos(a, b, d); }
|
|
11
|
-
inline static simsimd_f32_t inner_i8(simsimd_i8_t const* a, simsimd_i8_t const* b, simsimd_size_t d) { return simsimd_metric_punned(simsimd_metric_inner_k, simsimd_datatype_i8_k, simsimd_cap_any_k)(a, b, d, d); }
|
|
12
|
-
inline static simsimd_f32_t inner_f32(simsimd_f32_t const* a, simsimd_f32_t const* b, simsimd_size_t d) { return simsimd_metric_punned(simsimd_metric_inner_k, simsimd_datatype_f32_k, simsimd_cap_any_k)(a, b, d, d); }
|
|
13
|
-
inline static simsimd_f32_t sqeuclidean_i8(simsimd_i8_t const* a, simsimd_i8_t const* b, simsimd_size_t d) { return simsimd_metric_punned(simsimd_metric_sqeuclidean_k, simsimd_datatype_i8_k, simsimd_cap_any_k)(a, b, d, d); }
|
|
14
|
-
inline static simsimd_f32_t sqeuclidean_f32(simsimd_f32_t const* a, simsimd_f32_t const* b, simsimd_size_t d) { return simsimd_metric_punned(simsimd_metric_sqeuclidean_k, simsimd_datatype_f32_k, simsimd_cap_any_k)(a, b, d, d); }
|
|
15
|
-
*/
|
|
16
|
-
import "C"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// CosineI8 computes the cosine similarity between two i8 vectors using the most suitable SIMD instruction set available.
|
|
20
|
-
func CosineI8(a, b []int8) float32 {
|
|
21
|
-
return float32(C.cosine_i8((*C.simsimd_i8_t)(&a[0]), (*C.simsimd_i8_t)(&b[0]), C.simsimd_size_t(len(a))))
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// CosineF32 computes the cosine similarity between two i8 vectors using the most suitable SIMD instruction set available.
|
|
25
|
-
func CosineF32(a, b []float32) float32 {
|
|
26
|
-
return float32(C.cosine_f32((*C.simsimd_f32_t)(&a[0]), (*C.simsimd_f32_t)(&b[0]), C.simsimd_size_t(len(a))))
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// InnerI8 computes the inner-product similarity between two i8 vectors using the most suitable SIMD instruction set available.
|
|
30
|
-
func InnerI8(a, b []int8) float32 {
|
|
31
|
-
return float32(C.inner_i8((*C.simsimd_i8_t)(&a[0]), (*C.simsimd_i8_t)(&b[0]), C.simsimd_size_t(len(a))))
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// InnerF32 computes the inner-product similarity between two i8 vectors using the most suitable SIMD instruction set available.
|
|
35
|
-
func InnerF32(a, b []float32) float32 {
|
|
36
|
-
return float32(C.inner_f32((*C.simsimd_f32_t)(&a[0]), (*C.simsimd_f32_t)(&b[0]), C.simsimd_size_t(len(a))))
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// SqEuclideanI8 computes the squared euclidean similarity between two i8 vectors using the most suitable SIMD instruction set available.
|
|
40
|
-
func SqEuclideanI8(a, b []int8) float32 {
|
|
41
|
-
return float32(C.sqeuclidean_i8((*C.simsimd_i8_t)(&a[0]), (*C.simsimd_i8_t)(&b[0]), C.simsimd_size_t(len(a))))
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// SqEuclideanF32 computes the squared euclidean similarity between two i8 vectors using the most suitable SIMD instruction set available.
|
|
45
|
-
func SqEuclideanF32(a, b []float32) float32 {
|
|
46
|
-
return float32(C.sqeuclidean_f32((*C.simsimd_f32_t)(&a[0]), (*C.simsimd_f32_t)(&b[0]), C.simsimd_size_t(len(a))))
|
|
47
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
package simsimd
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"math"
|
|
5
|
-
"testing"
|
|
6
|
-
)
|
|
7
|
-
|
|
8
|
-
func TestCosineI8(t *testing.T) {
|
|
9
|
-
a := []int8{1, 0}
|
|
10
|
-
b := []int8{0, 1}
|
|
11
|
-
|
|
12
|
-
result := CosineI8(a, b)
|
|
13
|
-
expected := float32(1.0) // Cosine similarity of orthogonal vectors is 0
|
|
14
|
-
if math.Abs(float64(result-expected)) > 1e-3 {
|
|
15
|
-
t.Errorf("Expected %v, got %v", expected, result)
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
func TestCosineF32(t *testing.T) {
|
|
20
|
-
a := []float32{1, 0}
|
|
21
|
-
b := []float32{0, 1}
|
|
22
|
-
|
|
23
|
-
result := CosineF32(a, b)
|
|
24
|
-
expected := float32(1.0) // Cosine similarity of orthogonal vectors is 0
|
|
25
|
-
if math.Abs(float64(result-expected)) > 1e-3 {
|
|
26
|
-
t.Errorf("Expected %v, got %v", expected, result)
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
func TestVectorLengthMismatch(t *testing.T) {
|
|
31
|
-
defer func() {
|
|
32
|
-
if r := recover(); r == nil {
|
|
33
|
-
t.Errorf("The code did not panic")
|
|
34
|
-
}
|
|
35
|
-
}()
|
|
36
|
-
|
|
37
|
-
a := []int8{1, 0}
|
|
38
|
-
b := []int8{0}
|
|
39
|
-
_ = CosineI8(a, b) // This should panic
|
|
40
|
-
}
|
package/simsimd/pyproject.toml
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
[build-system]
|
|
2
|
-
requires = ["setuptools>=42", "wheel", "numpy"]
|
|
3
|
-
build-backend = "setuptools.build_meta"
|
|
4
|
-
|
|
5
|
-
[tool.pytest.ini_options]
|
|
6
|
-
minversion = "6.0"
|
|
7
|
-
addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"]
|
|
8
|
-
xfail_strict = true
|
|
9
|
-
filterwarnings = ["error"]
|
|
10
|
-
|
|
11
|
-
[tool.cibuildwheel]
|
|
12
|
-
test-requires = ["pytest", "pytest-repeat", "scipy"]
|
|
13
|
-
test-command = "pytest {project}/python/test.py -s -x"
|
|
14
|
-
build-verbosity = 0
|
|
15
|
-
skip = ["*musllinux*", "*i686*", "pp*", "cp36-*", "cp37-*"]
|
|
16
|
-
|
|
17
|
-
[tool.cibuildwheel.linux]
|
|
18
|
-
before-build = [
|
|
19
|
-
"rm -rf {project}/build",
|
|
20
|
-
]
|
|
21
|
-
manylinux-x86_64-image = "manylinux_2_28"
|
|
22
|
-
manylinux-aarch64-image = "manylinux_2_28"
|
|
23
|
-
|
|
24
|
-
archs = ["x86_64", "aarch64"]
|
|
25
|
-
before-all = [
|
|
26
|
-
"yum install -y glibc-devel wget python3-devel"
|
|
27
|
-
]
|
|
28
|
-
repair-wheel-command = "auditwheel repair --lib-sdir . -w {dest_dir} {wheel}"
|
|
29
|
-
|
|
30
|
-
[tool.cibuildwheel.macos]
|
|
31
|
-
before-build = [
|
|
32
|
-
"rm -rf {project}/build",
|
|
33
|
-
]
|
|
34
|
-
archs = ["x86_64", "arm64"]
|
|
35
|
-
repair-wheel-command = "delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel}"
|
|
36
|
-
|
|
37
|
-
[tool.cibuildwheel.windows]
|
|
38
|
-
before-build = [
|
|
39
|
-
"rd /s /q {project}\\build || echo Done",
|
|
40
|
-
]
|
|
41
|
-
archs = ["x86", "AMD64"]
|
|
42
|
-
skip = ["*win32*", "pp*"]
|