Skip to content

Commit 301d59c

Browse files
committed
Docs: Inconsistencies & typos
1 parent 5b9c207 commit 301d59c

File tree

17 files changed

+105
-104
lines changed

17 files changed

+105
-104
lines changed

CONTRIBUTING.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 100
4949
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 100
5050
```
5151

52-
To compile with the default Apple Clang on MacOS, use:
52+
To compile with the default Apple Clang on macOS, use:
5353

5454
```sh
5555
brew install openblas
@@ -63,8 +63,8 @@ cmake -D CMAKE_BUILD_TYPE=Release \
6363
cmake --build build_release --config Release
6464
```
6565

66-
On MacOS it's recommended to use Homebrew and install Clang, as opposed to "Apple Clang".
67-
Replacing the default compiler across the entire system is not recommended on MacOS, as it may break the system, but you can pass it as an environment variable:
66+
On macOS it's recommended to use Homebrew and install Clang, as opposed to "Apple Clang".
67+
Replacing the default compiler across the entire system is not recommended on macOS, as it may break the system, but you can pass it as an environment variable:
6868

6969
```sh
7070
brew install llvm openblas
@@ -124,7 +124,7 @@ Here, `-s` will output the logs.
124124
The `-x` will stop on the first failure.
125125
The `-Wd` will silence overflows and runtime warnings.
126126

127-
When building on MacOS, same as with C/C++, use non-Apple Clang version:
127+
When building on macOS, same as with C/C++, use non-Apple Clang version:
128128

129129
```sh
130130
brew install llvm
@@ -174,7 +174,7 @@ $ python scripts/bench_vectors.py --help
174174
175175
176176
Before merging your changes you may want to test your changes against the entire matrix of Python versions USearch supports.
177-
For that you need the `cibuildwheel`, which is tricky to use on MacOS and Windows, as it would target just the local environment.
177+
For that you need the `cibuildwheel`, which is tricky to use on macOS and Windows, as it would target just the local environment.
178178
Still, if you have Docker running on any desktop OS, you can use it to build and test the Python bindings for all Python versions for Linux:
179179
180180
```sh
@@ -184,7 +184,7 @@ cibuildwheel --platform linux # works on any OS and builds all
184184
cibuildwheel --platform linux --archs x86_64 # 64-bit x86, the most common on desktop and servers
185185
cibuildwheel --platform linux --archs aarch64 # 64-bit Arm for mobile devices, Apple M-series, and AWS Graviton
186186
cibuildwheel --platform linux --archs i686 # 32-bit Linux
187-
cibuildwheel --platform macos # works only on MacOS
187+
cibuildwheel --platform macos # works only on macOS
188188
cibuildwheel --platform windows # works only on Windows
189189
```
190190
@@ -194,7 +194,7 @@ You may need root privileges for multi-architecture builds:
194194
sudo $(which cibuildwheel) --platform linux
195195
```
196196
197-
On Windows and MacOS, to avoid frequent path resolution issues, you may want to use:
197+
On Windows and macOS, to avoid frequent path resolution issues, you may want to use:
198198
199199
```sh
200200
python -m cibuildwheel --platform windows
@@ -217,7 +217,7 @@ If you don't have the environment configured, here are the [installation options
217217
218218
```sh
219219
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash # Linux
220-
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash # MacOS
220+
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash # macOS
221221
```
222222
223223
Install dependencies:
@@ -242,7 +242,7 @@ If you don't have the environment configured, here are [installation options](ht
242242
243243
```sh
244244
wget -qO- https://deno.land/x/install/install.sh | sh # Linux
245-
curl -fsSL https://deno.land/install.sh | sh # MacOS
245+
curl -fsSL https://deno.land/install.sh | sh # macOS
246246
irm https://deno.land/install.ps1 | iex # Windows
247247
```
248248

README.md

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![SimSIMD banner](https://github.com/ashvardanian/ashvardanian/blob/master/repositories/SimSIMD.jpg?raw=true)
22

3-
Computing dot-products, similarity measures, and distances between low- and high-dimensional vectors is ubiquitous in Machine Learning, Scientific Computing, Geo-Spatial Analysis, and Information Retrieval.
3+
Computing dot-products, similarity measures, and distances between low- and high-dimensional vectors is ubiquitous in Machine Learning, Scientific Computing, Geospatial Analysis, and Information Retrieval.
44
These algorithms generally have linear complexity in time, constant or linear complexity in space, and are data-parallel.
55
In other words, it is easily parallelizable and vectorizable and often available in packages like BLAS (level 1) and LAPACK, as well as higher-level `numpy` and `scipy` Python libraries.
66
Ironically, even with decades of evolution in compilers and numerical computing, [most libraries can be 3-200x slower than hardware potential][benchmarks] even on the most popular hardware, like 64-bit x86 and Arm CPUs.
@@ -32,7 +32,7 @@ SimSIMD provides an alternative.
3232
<img alt="GitHub Actions Windows" src="https://img.shields.io/github/actions/workflow/status/ashvardanian/SimSIMD/release.yml?branch=main&label=Windows&logo=windows&color=blue">
3333
</a>
3434
<a href="https://github.com/ashvardanian/SimSIMD/actions/workflows/release.yml">
35-
<img alt="GitHub Actions MacOS" src="https://img.shields.io/github/actions/workflow/status/ashvardanian/SimSIMD/release.yml?branch=main&label=MacOS&logo=apple&color=blue">
35+
<img alt="GitHub Actions macOS" src="https://img.shields.io/github/actions/workflow/status/ashvardanian/SimSIMD/release.yml?branch=main&label=macOS&logo=apple&color=blue">
3636
</a>
3737
<a href="https://github.com/ashvardanian/SimSIMD/actions/workflows/release.yml">
3838
<img alt="GitHub Actions CentOS Linux" src="https://img.shields.io/github/actions/workflow/status/ashvardanian/SimSIMD/release.yml?branch=main&label=CentOS&logo=centos&color=blue">
@@ -43,7 +43,7 @@ SimSIMD provides an alternative.
4343
## Features
4444

4545
__SimSIMD__ (Arabic: "سيمسيم دي") is a mixed-precision math library of __over 350 SIMD-optimized kernels__ extensively used in AI, Search, and DBMS workloads.
46-
Named after the iconic ["Open Sesame"](https://en.wikipedia.org/wiki/Open_sesame) command that opened doors to treasure in _Ali Baba and the Forty Thieves_, SimSimd can help you 10x the cost-efficiency of your computational pipelines.
46+
Named after the iconic ["Open Sesame"](https://en.wikipedia.org/wiki/Open_sesame) command that opened doors to treasure in _Ali Baba and the Forty Thieves_, SimSIMD can help you 10x the cost-efficiency of your computational pipelines.
4747
Implemented distance functions include:
4848

4949
- Euclidean (L2) and Cosine (Angular) spatial distances for Vector Search. _[docs][docs-spatial]_
@@ -85,7 +85,7 @@ You can learn more about the technical implementation details in the following b
8585

8686
- [Uses Horner's method for polynomial approximations, beating GCC 12 by 119x](https://ashvardanian.com/posts/gcc-12-vs-avx512fp16/).
8787
- [Uses Arm SVE and x86 AVX-512's masked loads to eliminate tail `for`-loops](https://ashvardanian.com/posts/simsimd-faster-scipy/#tails-of-the-past-the-significance-of-masked-loads).
88-
- [Substitutes LibC's `sqrt` with Newton Raphson iterations](https://github.com/ashvardanian/SimSIMD/releases/tag/v5.4.0).
88+
- [Substitutes libc's `sqrt` with Newton Raphson iterations](https://github.com/ashvardanian/SimSIMD/releases/tag/v5.4.0).
8989
- [Uses Galloping and SVE2 histograms to intersect sparse vectors](https://ashvardanian.com/posts/simd-set-intersections-sve2-avx512/).
9090
- For Python: [avoids slow PyBind11, SWIG, & `PyArg_ParseTuple`](https://ashvardanian.com/posts/pybind11-cpython-tutorial/) [using faster calling convention](https://ashvardanian.com/posts/discount-on-keyword-arguments-in-python/).
9191
- For JavaScript: [uses typed arrays and NAPI for zero-copy calls](https://ashvardanian.com/posts/javascript-ai-vector-search/).
@@ -625,13 +625,13 @@ fn main() {
625625
let vector_a: Vec<f32> = vec![1.0, 2.0, 3.0];
626626
let vector_b: Vec<f32> = vec![4.0, 5.0, 6.0];
627627

628-
// Compute the cosine similarity between vector_a and vector_b
629-
let cosine_similarity = f32::cosine(&vector_a, &vector_b)
628+
// Compute the cosine distance between vectors
629+
let cosine_distance = f32::cosine(&vector_a, &vector_b)
630630
.expect("Vectors must be of the same length");
631631

632-
println!("Cosine Similarity: {}", cosine_similarity);
632+
println!("Cosine Distance: {}", cosine_distance);
633633

634-
// Compute the squared Euclidean distance between vector_a and vector_b
634+
// Compute the squared Euclidean distance between vectors
635635
let sq_euclidean_distance = f32::sqeuclidean(&vector_a, &vector_b)
636636
.expect("Vectors must be of the same length");
637637

@@ -648,16 +648,17 @@ use simsimd::SpatialSimilarity;
648648
use simsimd::ComplexProducts;
649649

650650
fn main() {
651+
// Complex vectors have interleaved real & imaginary components
651652
let vector_a: Vec<f32> = vec![1.0, 2.0, 3.0, 4.0];
652653
let vector_b: Vec<f32> = vec![5.0, 6.0, 7.0, 8.0];
653654

654-
// Compute the inner product between vector_a and vector_b
655+
// Compute the inner product between vectors
655656
let inner_product = SpatialSimilarity::dot(&vector_a, &vector_b)
656657
.expect("Vectors must be of the same length");
657658

658659
println!("Inner Product: {}", inner_product);
659660

660-
// Compute the complex inner product between complex_vector_a and complex_vector_b
661+
// Compute the complex inner product between vectors
661662
let complex_inner_product = ComplexProducts::dot(&vector_a, &vector_b)
662663
.expect("Vectors must be of the same length");
663664

@@ -705,13 +706,13 @@ fn main() {
705706
let vector_a = &[0b11110000, 0b00001111, 0b10101010];
706707
let vector_b = &[0b11110000, 0b00001111, 0b01010101];
707708

708-
// Compute the Hamming distance between vector_a and vector_b
709+
// Compute the Hamming distance between vectors
709710
let hamming_distance = u8::hamming(&vector_a, &vector_b)
710711
.expect("Vectors must be of the same length");
711712

712713
println!("Hamming Distance: {}", hamming_distance);
713714

714-
// Compute the Jaccard distance between vector_a and vector_b
715+
// Compute the Jaccard distance between vectors
715716
let jaccard_distance = u8::jaccard(&vector_a, &vector_b)
716717
.expect("Vectors must be of the same length");
717718

@@ -734,11 +735,11 @@ fn main() {
734735
let vector_a: Vec<f16> = vec![1.0, 2.0, 3.0].iter().map(|&x| f16::from_f32(x)).collect();
735736
let vector_b: Vec<f16> = vec![4.0, 5.0, 6.0].iter().map(|&x| f16::from_f32(x)).collect();
736737

737-
// Compute the cosine similarity
738-
let cosine_similarity = f16::cosine(&vector_a, &vector_b)
738+
// Compute the cosine distance
739+
let cosine_distance = f16::cosine(&vector_a, &vector_b)
739740
.expect("Vectors must be of the same length");
740741

741-
println!("Cosine Similarity: {}", cosine_similarity);
742+
println!("Cosine Distance: {}", cosine_distance);
742743

743744
// Direct bit manipulation
744745
let half = f16::from_f32(3.14159);
@@ -764,10 +765,10 @@ fn main() {
764765
let buffer_a: &[SimF16] = unsafe { std::slice::from_raw_parts(vector_a.as_ptr() as *const SimF16, vector_a.len()) };
765766
let buffer_b: &[SimF16] = unsafe { std::slice::from_raw_parts(vector_b.as_ptr() as *const SimF16, vector_b.len()) };
766767

767-
let cosine_similarity = SimF16::cosine(buffer_a, buffer_b)
768+
let cosine_distance = SimF16::cosine(buffer_a, buffer_b)
768769
.expect("Vectors must be of the same length");
769770

770-
println!("Cosine Similarity: {}", cosine_similarity);
771+
println!("Cosine Distance: {}", cosine_distance);
771772
}
772773
```
773774

@@ -787,10 +788,10 @@ fn main() {
787788
let vector_b: Vec<bf16> = vec![4.0, 5.0, 6.0].iter().map(|&x| bf16::from_f32(x)).collect();
788789

789790
// Compute the cosine similarity
790-
let cosine_similarity = bf16::cosine(&vector_a, &vector_b)
791+
let cosine_distance = bf16::cosine(&vector_a, &vector_b)
791792
.expect("Vectors must be of the same length");
792793

793-
println!("Cosine Similarity: {}", cosine_similarity);
794+
println!("Cosine Distance: {}", cosine_distance);
794795

795796
// Direct bit manipulation
796797
let brain_half = bf16::from_f32(3.14159);
@@ -899,8 +900,8 @@ import SimSIMD
899900
let vectorA: [Int8] = [1, 2, 3]
900901
let vectorB: [Int8] = [4, 5, 6]
901902

902-
let cosineSimilarity = vectorA.cosine(vectorB) // Computes the cosine similarity
903903
let dotProduct = vectorA.dot(vectorB) // Computes the dot product
904+
let cosineDistance = vectorA.cosine(vectorB) // Computes the cosine distance
904905
let sqEuclidean = vectorA.sqeuclidean(vectorB) // Computes the squared Euclidean distance
905906
```
906907

c/lib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* - Linux: everything is available in GCC 12+ and Clang 16+.
2020
* - Windows - MSVC: everything except Sapphire Rapids and ARM SVE.
21-
* - MacOS - Apple Clang: only Arm NEON and x86 AVX2 Haswell extensions are available.
21+
* - macOS - Apple Clang: only Arm NEON and x86 AVX2 Haswell extensions are available.
2222
*/
2323
#if !defined(SIMSIMD_TARGET_NEON) && (defined(__APPLE__) || defined(__linux__))
2424
#define SIMSIMD_TARGET_NEON 1

golang/bench_test.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ import (
66
"testing"
77
)
88

9-
func cosineSimilarity(a, b []float32) float32 {
9+
func cosineDistance(a, b []float32) float32 {
1010
var dotProduct float32
1111
var normA, normB float32
1212
for i := range a {
1313
dotProduct += a[i] * b[i]
1414
normA += a[i] * a[i]
1515
normB += b[i] * b[i]
1616
}
17-
return dotProduct / (float32(math.Sqrt(float64(normA))) * float32(math.Sqrt(float64(normB))))
17+
sim := dotProduct / (float32(math.Sqrt(float64(normA))) * float32(math.Sqrt(float64(normB))))
18+
return 1 - sim
1819
}
1920

2021
func generateRandomVector(dim int) []float32 {
@@ -25,16 +26,16 @@ func generateRandomVector(dim int) []float32 {
2526
return vec
2627
}
2728

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-
}
29+
func BenchmarkCosineDistanceNative(b *testing.B) {
30+
first, second := generateRandomVector(1536), generateRandomVector(1536)
31+
for i := 0; i < b.N; i++ {
32+
cosineDistance(first, second)
33+
}
3334
}
3435

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-
}
36+
func BenchmarkCosineDistanceSIMD(b *testing.B) {
37+
first, second := generateRandomVector(1536), generateRandomVector(1536)
38+
for i := 0; i < b.N; i++ {
39+
CosineF32(first, second)
40+
}
41+
}

golang/simsimd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func InnerF32(a, b []float32) float32 {
5353
return float32(C.inner_f32((*C.simsimd_f32_t)(&a[0]), (*C.simsimd_f32_t)(&b[0]), C.simsimd_size_t(len(a))))
5454
}
5555

56-
// SqEuclideanI8 computes the squared euclidean similarity between two i8 vectors using the most suitable SIMD instruction set available.
56+
// SqEuclideanI8 computes the squared Euclidean distance between two i8 vectors using the most suitable SIMD instruction set available.
5757
func SqEuclideanI8(a, b []int8) float32 {
5858
if len(a) != len(b) {
5959
panic("both vectors must have the same length")
@@ -62,7 +62,7 @@ func SqEuclideanI8(a, b []int8) float32 {
6262
return float32(C.sqeuclidean_i8((*C.simsimd_i8_t)(&a[0]), (*C.simsimd_i8_t)(&b[0]), C.simsimd_size_t(len(a))))
6363
}
6464

65-
// SqEuclideanF32 computes the squared euclidean similarity between two f32 vectors using the most suitable SIMD instruction set available.
65+
// SqEuclideanF32 computes the squared Euclidean distance between two f32 vectors using the most suitable SIMD instruction set available.
6666
func SqEuclideanF32(a, b []float32) float32 {
6767
if len(a) != len(b) {
6868
panic("both vectors must have the same length")

golang/unit_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func TestCosineI8(t *testing.T) {
1010
b := []int8{0, 1}
1111

1212
result := CosineI8(a, b)
13-
expected := float32(1.0) // Cosine similarity of orthogonal vectors is 0
13+
expected := float32(1.0) // Cosine distance of orthogonal vectors is 1
1414
if math.Abs(float64(result-expected)) > 1e-3 {
1515
t.Errorf("Expected %v, got %v", expected, result)
1616
}
@@ -21,7 +21,7 @@ func TestCosineF32(t *testing.T) {
2121
b := []float32{0, 1}
2222

2323
result := CosineF32(a, b)
24-
expected := float32(1.0) // Cosine similarity of orthogonal vectors is 0
24+
expected := float32(1.0) // Cosine distance of orthogonal vectors is 1
2525
if math.Abs(float64(result-expected)) > 1e-3 {
2626
t.Errorf("Expected %v, got %v", expected, result)
2727
}

include/simsimd/binary.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Contains:
88
* - Hamming distance
9-
* - Jaccard similarity (Tanimoto coefficient)
9+
* - Jaccard distance (Tanimoto coefficient)
1010
*
1111
* For hardware architectures:
1212
* - Arm: NEON, SVE
@@ -19,7 +19,7 @@
1919
* - Lookup tables, mostly using nibbles (4-bit lookups)
2020
* - Harley-Seal population counts: https://arxiv.org/pdf/1611.07612
2121
*
22-
* On binary vectors, when computing Jaccard similarity we can clearly see how the CPU struggles
22+
* On binary vectors, when computing Jaccard distance we can clearly see how the CPU struggles
2323
* to compute that many population counts. There are several instructions we should keep in mind
2424
* for future optimizations:
2525
*

include/simsimd/geospatial.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @file geospatial.h
3-
* @brief SIMD-accelerated Geo-Spatial distance functions.
3+
* @brief SIMD-accelerated Geospatial distance functions.
44
* @author Ash Vardanian
55
* @date July 1, 2023
66
*

include/simsimd/mesh.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* - 16-bit brain-floating point
1616
*
1717
* For hardware architectures:
18-
* - Arm: Neon
18+
* - Arm: NEON
1919
* - x86: Genoa, Sapphire
2020
*
2121
* x86 intrinsics: https://www.intel.com/content/www/us/en/docs/intrinsics-guide/

include/simsimd/simsimd.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
* Intel Palm Cove was an irrelevant intermediate release extending Skylake with IFMA and VBMI.
2828
* Intel Willow Cove was an irrelevant intermediate release extending Sunny Cove with VP2INTERSECT,
29-
* that aren't supported by any other CPU built to date... and those are only available in Tiger Lake laptops.
29+
* which are not supported by other CPUs to date and are only available in Tiger Lake laptops.
3030
* Intel Cooper Lake was the only intermediary platform, that supported BF16, but not FP16.
3131
* It's mostly used in 4-socket and 8-socket high-memory configurations.
3232
*
@@ -80,7 +80,7 @@
8080
* The N2 core is very similar to V2 and is used by Microsoft @b Cobalt.
8181
* https://developer.arm.com/Processors/Neoverse%20N2
8282
*
83-
* On Consumer side, Apple is the biggest player with mobile @b A chips and desktop @b M chips.
83+
* On the consumer side, Apple is the biggest player with mobile @b A chips and desktop @b M chips.
8484
* The M1 implements Armv8.5-A, both M2 and M3 implement Armv8.6-A, and M4 is expected to have Armv9.1-A.
8585
*/
8686

0 commit comments

Comments
 (0)