usearch 2.8.7 → 2.8.8
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/CITATION.cff +1 -1
- package/CMakeLists.txt +3 -3
- package/CONTRIBUTING.md +3 -3
- package/Cargo.toml +1 -1
- package/Dockerfile +16 -0
- package/README.md +41 -38
- package/VERSION +1 -0
- package/binding.gyp +57 -8
- package/conanfile.py +1 -1
- package/include/usearch/index.hpp +1 -1
- package/include/usearch/index_plugins.hpp +27 -23
- package/package.json +1 -2
- package/setup.py +76 -15
- package/wasmer.toml +1 -1
- package/. npmignore +0 -14
- package/.gitignore +0 -95
- package/.vscode/launch.json +0 -181
- package/.vscode/settings.json +0 -180
- package/.vscode/tasks.json +0 -71
- package/Package.swift +0 -41
- package/csharp/.editorconfig +0 -361
- package/csharp/Cloud.Unum.USearch.sln +0 -34
- package/csharp/DEV_SETUP.md +0 -51
- package/csharp/Directory.Build.props +0 -29
- package/csharp/README.md +0 -74
- package/csharp/build_and_test.cmd +0 -31
- package/csharp/build_and_test.sh +0 -30
- package/csharp/nuget/nuget-package.props +0 -33
- package/csharp/pack.sh +0 -56
- package/csharp/src/Cloud.Unum.USearch.Tests/Cloud.Unum.USearch.Tests.csproj +0 -39
- package/csharp/src/Cloud.Unum.USearch.Tests/USearchIndexTests.cs +0 -1013
- package/csharp/src/Cloud.Unum.USearch.Tests/Usings.cs +0 -1
- package/docs/_static/custom.css +0 -26
- package/docs/_static/custom.js +0 -7
- package/docs/benchmarks.md +0 -245
- package/docs/benchmarks.rst +0 -5
- package/docs/c/index.rst +0 -11
- package/docs/c/reference.rst +0 -7
- package/docs/conf.dox +0 -2668
- package/docs/conf.py +0 -53
- package/docs/contributing.rst +0 -5
- package/docs/cpp/index.rst +0 -11
- package/docs/cpp/reference.rst +0 -17
- package/docs/csharp/index.rst +0 -6
- package/docs/format.md +0 -86
- package/docs/format.rst +0 -5
- package/docs/golang/index.rst +0 -6
- package/docs/index.rst +0 -33
- package/docs/java/index.rst +0 -11
- package/docs/java/reference.rst +0 -7
- package/docs/javascript/index.rst +0 -11
- package/docs/javascript/reference.rst +0 -12
- package/docs/python/index.rst +0 -11
- package/docs/python/reference.rst +0 -42
- package/docs/rust/index.rst +0 -6
- package/docs/swift/index.rst +0 -6
- package/docs/wolfram/index.rst +0 -6
- package/golang/README.md +0 -95
- package/golang/go.mod +0 -3
- package/golang/lib.go +0 -379
- package/golang/lib_test.go +0 -108
- package/java/README.md +0 -22
- package/java/cloud/unum/usearch/Index.java +0 -337
- package/java/cloud/unum/usearch/cloud_unum_usearch_Index.cpp +0 -197
- package/java/cloud/unum/usearch/cloud_unum_usearch_Index.h +0 -125
- package/java/test/IndexTest.java +0 -30
- package/objc/USearchObjective.mm +0 -299
- package/objc/include/USearchObjective.h +0 -154
- package/python/README.md +0 -292
- package/python/lib.cpp +0 -1216
- package/python/scripts/bench.ipynb +0 -193
- package/python/scripts/bench.py +0 -137
- package/python/scripts/bench_exact.py +0 -44
- package/python/scripts/cluster.ipynb +0 -160
- package/python/scripts/index_faiss.py +0 -100
- package/python/scripts/join.py +0 -155
- package/python/scripts/test_index.py +0 -247
- package/python/scripts/test_jit.py +0 -231
- package/python/scripts/test_sparse.py +0 -32
- package/python/scripts/test_tooling.py +0 -133
- package/python/usearch/__init__.py +0 -0
- package/python/usearch/client.py +0 -124
- package/python/usearch/eval.py +0 -470
- package/python/usearch/index.py +0 -1401
- package/python/usearch/io.py +0 -113
- package/python/usearch/numba.py +0 -121
- package/python/usearch/server.py +0 -137
- package/rust/README.md +0 -66
- package/rust/lib.cpp +0 -136
- package/rust/lib.hpp +0 -69
- package/rust/lib.rs +0 -610
- package/swift/Index+Sugar.swift +0 -153
- package/swift/README.md +0 -48
- package/swift/Test.swift +0 -37
- package/swift/USearch.swift +0 -8
- package/wasm/CMakeLists.txt +0 -7
- package/wasm/README.md +0 -13
- package/wasm/lib.cpp +0 -5
- package/wolfram/CMakeLists.txt +0 -18
- package/wolfram/README.md +0 -13
- package/wolfram/lib.cpp +0 -160
- package/wolfram/test.wls +0 -27
package/swift/Index+Sugar.swift
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Index+Sugar.swift
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// Created by Ash Vardanian on 5/11/23.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
@available(iOS 13, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
|
|
9
|
-
extension USearchIndex {
|
|
10
|
-
public typealias Key = USearchKey
|
|
11
|
-
public typealias Metric = USearchMetric
|
|
12
|
-
public typealias Scalar = USearchScalar
|
|
13
|
-
|
|
14
|
-
/// Adds a labeled vector to the index.
|
|
15
|
-
/// - Parameter key: Unique identifer for that object.
|
|
16
|
-
/// - Parameter vector: Single-precision vector.
|
|
17
|
-
/// - Throws: If runs out of memory.
|
|
18
|
-
public func add(key: USearchKey, vector: ArraySlice<Float32>) {
|
|
19
|
-
vector.withContiguousStorageIfAvailable {
|
|
20
|
-
addSingle(key: key, vector: $0.baseAddress!)
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/// Adds a labeled vector to the index.
|
|
25
|
-
/// - Parameter key: Unique identifer for that object.
|
|
26
|
-
/// - Parameter vector: Single-precision vector.
|
|
27
|
-
/// - Throws: If runs out of memory.
|
|
28
|
-
public func add(key: USearchKey, vector: Array<Float32>) {
|
|
29
|
-
add(key: key, vector: vector[...])
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/// Approximate nearest neighbors search.
|
|
33
|
-
/// - Parameter vector: Single-precision query vector.
|
|
34
|
-
/// - Parameter count: Upper limit on the number of matches to retrieve.
|
|
35
|
-
/// - Returns: Labels and distances to closest approximate matches in decreasing similarity order.
|
|
36
|
-
/// - Throws: If runs out of memory.
|
|
37
|
-
public func search(vector: ArraySlice<Float32>, count: Int) -> ([Key], [Float]) {
|
|
38
|
-
var matches: [Key] = Array(repeating: 0, count: count)
|
|
39
|
-
var distances: [Float] = Array(repeating: 0, count: count)
|
|
40
|
-
let results = vector.withContiguousStorageIfAvailable {
|
|
41
|
-
searchSingle(vector: $0.baseAddress!, count: CUnsignedInt(count), keys: &matches, distances: &distances)
|
|
42
|
-
}
|
|
43
|
-
matches.removeLast(count - Int(results!))
|
|
44
|
-
distances.removeLast(count - Int(results!))
|
|
45
|
-
return (matches, distances)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/// Approximate nearest neighbors search.
|
|
49
|
-
/// - Parameter vector: Single-precision query vector.
|
|
50
|
-
/// - Parameter count: Upper limit on the number of matches to retrieve.
|
|
51
|
-
/// - Returns: Labels and distances to closest approximate matches in decreasing similarity order.
|
|
52
|
-
/// - Throws: If runs out of memory.
|
|
53
|
-
public func search(vector: Array<Float32>, count: Int) -> ([Key], [Float]) {
|
|
54
|
-
return search(vector: vector[...], count: count)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/// Adds a labeled vector to the index.
|
|
58
|
-
/// - Parameter key: Unique identifer for that object.
|
|
59
|
-
/// - Parameter vector: Double-precision vector.
|
|
60
|
-
/// - Throws: If runs out of memory.
|
|
61
|
-
public func add(key: Key, vector: ArraySlice<Float64>) {
|
|
62
|
-
vector.withContiguousStorageIfAvailable {
|
|
63
|
-
addDouble(key: key, vector: $0.baseAddress!)
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/// Adds a labeled vector to the index.
|
|
68
|
-
/// - Parameter key: Unique identifer for that object.
|
|
69
|
-
/// - Parameter vector: Double-precision vector.
|
|
70
|
-
/// - Throws: If runs out of memory.
|
|
71
|
-
public func add(key: Key, vector: Array<Float64>) {
|
|
72
|
-
add(key: key, vector: vector[...])
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/// Approximate nearest neighbors search.
|
|
76
|
-
/// - Parameter vector: Double-precision query vector.
|
|
77
|
-
/// - Parameter count: Upper limit on the number of matches to retrieve.
|
|
78
|
-
/// - Returns: Labels and distances to closest approximate matches in decreasing similarity order.
|
|
79
|
-
/// - Throws: If runs out of memory.
|
|
80
|
-
public func search(vector: ArraySlice<Float64>, count: Int) -> ([Key], [Float]) {
|
|
81
|
-
var matches: [Key] = Array(repeating: 0, count: count)
|
|
82
|
-
var distances: [Float] = Array(repeating: 0, count: count)
|
|
83
|
-
let results = vector.withContiguousStorageIfAvailable {
|
|
84
|
-
searchDouble(vector: $0.baseAddress!, count: CUnsignedInt(count), keys: &matches, distances: &distances)
|
|
85
|
-
}
|
|
86
|
-
matches.removeLast(count - Int(results!))
|
|
87
|
-
distances.removeLast(count - Int(results!))
|
|
88
|
-
return (matches, distances)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/// Approximate nearest neighbors search.
|
|
92
|
-
/// - Parameter vector: Double-precision query vector.
|
|
93
|
-
/// - Parameter count: Upper limit on the number of matches to retrieve.
|
|
94
|
-
/// - Returns: Labels and distances to closest approximate matches in decreasing similarity order.
|
|
95
|
-
/// - Throws: If runs out of memory.
|
|
96
|
-
public func search(vector: Array<Float64>, count: Int) -> ([Key], [Float]) {
|
|
97
|
-
search(vector: vector[...], count: count)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
#if arch(arm64)
|
|
101
|
-
|
|
102
|
-
/// Adds a labeled vector to the index.
|
|
103
|
-
/// - Parameter key: Unique identifer for that object.
|
|
104
|
-
/// - Parameter vector: Half-precision vector.
|
|
105
|
-
/// - Throws: If runs out of memory.
|
|
106
|
-
@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
|
|
107
|
-
public func add(key: Key, vector: ArraySlice<Float16>) {
|
|
108
|
-
vector.withContiguousStorageIfAvailable { buffer in
|
|
109
|
-
addHalf(key: key, vector: buffer.baseAddress!)
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/// Adds a labeled vector to the index.
|
|
114
|
-
/// - Parameter key: Unique identifer for that object.
|
|
115
|
-
/// - Parameter vector: Half-precision vector.
|
|
116
|
-
/// - Throws: If runs out of memory.
|
|
117
|
-
@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
|
|
118
|
-
public func add(key: Key, vector: Array<Float16>) {
|
|
119
|
-
add(key: key, vector: vector[...])
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/// Approximate nearest neighbors search.
|
|
123
|
-
/// - Parameter vector: Half-precision query vector.
|
|
124
|
-
/// - Parameter count: Upper limit on the number of matches to retrieve.
|
|
125
|
-
/// - Returns: Labels and distances to closest approximate matches in decreasing similarity order.
|
|
126
|
-
/// - Throws: If runs out of memory.
|
|
127
|
-
@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
|
|
128
|
-
public func search(vector: ArraySlice<Float16>, count: Int) -> ([Key], [Float]) {
|
|
129
|
-
var matches: [Key] = Array(repeating: 0, count: count)
|
|
130
|
-
var distances: [Float] = Array(repeating: 0, count: count)
|
|
131
|
-
let results = vector.withContiguousStorageIfAvailable {
|
|
132
|
-
searchHalf(vector: $0.baseAddress!, count: CUnsignedInt(count), keys: &matches, distances: &distances)
|
|
133
|
-
}
|
|
134
|
-
matches.removeLast(count - Int(results!))
|
|
135
|
-
distances.removeLast(count - Int(results!))
|
|
136
|
-
return (matches, distances)
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/// Approximate nearest neighbors search.
|
|
140
|
-
/// - Parameter vector: Half-precision query vector.
|
|
141
|
-
/// - Parameter count: Upper limit on the number of matches to retrieve.
|
|
142
|
-
/// - Returns: Labels and distances to closest approximate matches in decreasing similarity order.
|
|
143
|
-
/// - Throws: If runs out of memory.
|
|
144
|
-
@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
|
|
145
|
-
public func search(vector: Array<Float16>, count: Int) -> ([Key], [Float]) {
|
|
146
|
-
search(vector: vector[...], count: count)
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
#endif
|
|
150
|
-
|
|
151
|
-
/// Number of vectors in the index.
|
|
152
|
-
public var count: Int { return Int(length) }
|
|
153
|
-
}
|
package/swift/README.md
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
# USearch for Swift
|
|
2
|
-
|
|
3
|
-
## Installation
|
|
4
|
-
|
|
5
|
-
```txt
|
|
6
|
-
https://github.com/unum-cloud/usearch
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
## Quickstart
|
|
10
|
-
|
|
11
|
-
```swift
|
|
12
|
-
let index = USearchIndex.make(metric: .Cos, dimensions: 3, connectivity: 8)
|
|
13
|
-
let vectorA: [Float32] = [0.3, 0.5, 1.2] // `Float32` and `Float64` are always supported
|
|
14
|
-
let vectorB: [Float32] = [0.4, 0.2, 1.2] // `Float16` supports on the OS & hardware version
|
|
15
|
-
index.add(key: 42, vector: vectorA) // Pass full arrays or slices
|
|
16
|
-
index.add(key: 43, vector: vectorB)
|
|
17
|
-
|
|
18
|
-
let results = index.search(vector: vectorA, count: 10)
|
|
19
|
-
assert(results.0[0] == 42)
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
If using in a SwiftUI application, make sure to annulate the void responses:
|
|
23
|
-
|
|
24
|
-
```swift
|
|
25
|
-
import SwiftUI
|
|
26
|
-
import USearch
|
|
27
|
-
|
|
28
|
-
@main
|
|
29
|
-
struct USearchMobileApp: App {
|
|
30
|
-
var body: some Scene {
|
|
31
|
-
WindowGroup {
|
|
32
|
-
let index = USearchIndex.make(metric: .IP, dimensions: 2, connectivity: 16, quantization: .F32)
|
|
33
|
-
let _ = index.reserve(10)
|
|
34
|
-
let coordiantes: Array<Float32> = [40.177200, 44.503490]
|
|
35
|
-
let _ = index.add(key: 10, vector: coordiantes)
|
|
36
|
-
VStack {
|
|
37
|
-
Text("USearch index contains \(index.length) vectors")
|
|
38
|
-
Spacer()
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
You can find a working example of using USearch with SwiftUI maps at [ashvardanian/SwiftVectorSearch](https://github.com/ashvardanian/SwiftVectorSearch).
|
|
47
|
-
|
|
48
|
-
[](https://github.com/ashvardanian/SwiftVectorSearch)
|
package/swift/Test.swift
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// File.swift
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// Created by Ash Vardanian on 5/11/23.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
import Foundation
|
|
9
|
-
import USearch
|
|
10
|
-
import XCTest
|
|
11
|
-
|
|
12
|
-
@available(iOS 13, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
|
|
13
|
-
class Test: XCTestCase {
|
|
14
|
-
func testUnit() throws {
|
|
15
|
-
let index = USearchIndex.make(metric: USearchMetric.l2sq, dimensions: 4, connectivity: 8, quantization: USearchScalar.F32)
|
|
16
|
-
let vectorA: [Float32] = [0.3, 0.5, 1.2, 1.4]
|
|
17
|
-
let vectorB: [Float32] = [0.4, 0.2, 1.2, 1.1]
|
|
18
|
-
index.reserve(2)
|
|
19
|
-
|
|
20
|
-
// Adding a slice
|
|
21
|
-
index.add(key: 42, vector: vectorA[...])
|
|
22
|
-
|
|
23
|
-
// Adding a vector
|
|
24
|
-
index.add(key: 43, vector: vectorB)
|
|
25
|
-
|
|
26
|
-
let results = index.search(vector: vectorA, count: 10)
|
|
27
|
-
assert(results.0[0] == 42)
|
|
28
|
-
|
|
29
|
-
assert(index.contains(key: 42))
|
|
30
|
-
assert(index.count(key: 42) == 1)
|
|
31
|
-
assert(index.count(key: 49) == 0)
|
|
32
|
-
index.rename(from: 42, to: 49)
|
|
33
|
-
assert(index.count(key: 49) == 1)
|
|
34
|
-
index.remove(key: 49)
|
|
35
|
-
assert(index.count(key: 49) == 0)
|
|
36
|
-
}
|
|
37
|
-
}
|
package/swift/USearch.swift
DELETED
package/wasm/CMakeLists.txt
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
include(emscripten)
|
|
2
|
-
|
|
3
|
-
# Setting the compiler globally is never a good idea! set(CMAKE_C_COMPILER emcc) set(CMAKE_CXX_COMPILER em++)
|
|
4
|
-
|
|
5
|
-
add_executable(usearch_wasm lib.cpp)
|
|
6
|
-
setup_target(usearch_wasm)
|
|
7
|
-
set_target_properties(usearch_wasm PROPERTIES CXX_STANDARD 11)
|
package/wasm/README.md
DELETED
package/wasm/lib.cpp
DELETED
package/wolfram/CMakeLists.txt
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
if(NOT WOLFRAM_PATH)
|
|
3
|
-
set(WOLFRAM_PATH "/usr/local/Wolfram/Mathematica")
|
|
4
|
-
endif()
|
|
5
|
-
|
|
6
|
-
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${WOLFRAM_PATH}/SystemFiles/Links/WSTP/DeveloperKit/Linux-x86-64/CompilerAdditions/")
|
|
7
|
-
include(WSTP)
|
|
8
|
-
include_directories("${WOLFRAM_PATH}/SystemFiles/IncludeFiles/C/")
|
|
9
|
-
link_directories("${WOLFRAM_PATH}/SystemFiles/Libraries/Linux-x86-64/")
|
|
10
|
-
|
|
11
|
-
add_library(usearchWFM SHARED lib.cpp)
|
|
12
|
-
|
|
13
|
-
# Link against the Wolfram LibraryLink library
|
|
14
|
-
target_link_libraries(usearchWFM WSTP::STATIC_LIBRARY)
|
|
15
|
-
|
|
16
|
-
# Set the output name of the library to be compatible with Wolfram Language
|
|
17
|
-
set_target_properties(usearchWFM PROPERTIES PREFIX "" OUTPUT_NAME "usearchWFM")
|
|
18
|
-
set_target_properties(usearchWFM PROPERTIES CXX_STANDARD 11)
|
package/wolfram/README.md
DELETED
package/wolfram/lib.cpp
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
#include "WolframLibrary.h"
|
|
2
|
-
#include <usearch/index_dense.hpp>
|
|
3
|
-
|
|
4
|
-
using namespace unum::usearch;
|
|
5
|
-
|
|
6
|
-
using distance_t = distance_punned_t;
|
|
7
|
-
using index_t = index_dense_t;
|
|
8
|
-
using vector_view_t = span_gt<float>;
|
|
9
|
-
|
|
10
|
-
using add_result_t = typename index_t::add_result_t;
|
|
11
|
-
using search_result_t = typename index_t::search_result_t;
|
|
12
|
-
using vector_key_t = typename index_t::vector_key_t;
|
|
13
|
-
|
|
14
|
-
EXTERN_C DLLEXPORT int WolframLibrary_initialize(WolframLibraryData libData) { return LIBRARY_NO_ERROR; }
|
|
15
|
-
EXTERN_C DLLEXPORT void WolframLibrary_uninitialize(WolframLibraryData libData) { return; }
|
|
16
|
-
|
|
17
|
-
EXTERN_C DLLEXPORT int IndexCreate(WolframLibraryData libData, mint Argc, MArgument* Args, MArgument Res) {
|
|
18
|
-
index_config_t config;
|
|
19
|
-
char* quantization_cstr = nullptr;
|
|
20
|
-
char* metric_cstr = nullptr;
|
|
21
|
-
try {
|
|
22
|
-
quantization_cstr = MArgument_getUTF8String(Args[1]);
|
|
23
|
-
metric_cstr = MArgument_getUTF8String(Args[0]);
|
|
24
|
-
std::size_t dimensions = static_cast<std::size_t>(MArgument_getInteger(Args[2]));
|
|
25
|
-
std::size_t capacity = static_cast<std::size_t>(MArgument_getInteger(Args[3]));
|
|
26
|
-
config.connectivity = static_cast<std::size_t>(MArgument_getInteger(Args[4]));
|
|
27
|
-
config.expansion_add = static_cast<std::size_t>(MArgument_getInteger(Args[5]));
|
|
28
|
-
config.expansion_search = static_cast<std::size_t>(MArgument_getInteger(Args[6]));
|
|
29
|
-
|
|
30
|
-
scalar_kind_t quantization = scalar_kind_from_name(quantization_cstr, std::strlen(quantization_cstr));
|
|
31
|
-
metric_kind_t metric_kind = metric_from_name(metric_cstr, std::strlen(metric_cstr));
|
|
32
|
-
index_t index = make_punned<index_t>(metric_kind, dimensions, quantization, config);
|
|
33
|
-
index.reserve(capacity);
|
|
34
|
-
|
|
35
|
-
index_t* result_ptr = new index_t(std::move(index));
|
|
36
|
-
MArgument_setInteger(Res, (long)result_ptr);
|
|
37
|
-
|
|
38
|
-
} catch (...) {
|
|
39
|
-
return LIBRARY_FUNCTION_ERROR;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
libData->UTF8String_disown(quantization_cstr);
|
|
43
|
-
libData->UTF8String_disown(metric_cstr);
|
|
44
|
-
return LIBRARY_NO_ERROR;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
EXTERN_C DLLEXPORT int IndexSave(WolframLibraryData libData, mint Argc, MArgument* Args, MArgument Res) {
|
|
48
|
-
char* path_cstr = nullptr;
|
|
49
|
-
index_t* c_ptr = (index_t*)MArgument_getUTF8String(Args[0]);
|
|
50
|
-
try {
|
|
51
|
-
path_cstr = MArgument_getUTF8String(Args[1]);
|
|
52
|
-
c_ptr->save(path_cstr);
|
|
53
|
-
} catch (...) {
|
|
54
|
-
return LIBRARY_FUNCTION_ERROR;
|
|
55
|
-
}
|
|
56
|
-
libData->UTF8String_disown(path_cstr);
|
|
57
|
-
return LIBRARY_NO_ERROR;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
EXTERN_C DLLEXPORT int IndexLoad(WolframLibraryData libData, mint Argc, MArgument* Args, MArgument Res) {
|
|
61
|
-
char* path_cstr = nullptr;
|
|
62
|
-
index_t* c_ptr = (index_t*)MArgument_getUTF8String(Args[0]);
|
|
63
|
-
try {
|
|
64
|
-
path_cstr = MArgument_getUTF8String(Args[1]);
|
|
65
|
-
c_ptr->load(path_cstr);
|
|
66
|
-
} catch (...) {
|
|
67
|
-
return LIBRARY_FUNCTION_ERROR;
|
|
68
|
-
}
|
|
69
|
-
libData->UTF8String_disown(path_cstr);
|
|
70
|
-
return LIBRARY_NO_ERROR;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
EXTERN_C DLLEXPORT int IndexView(WolframLibraryData libData, mint Argc, MArgument* Args, MArgument Res) {
|
|
74
|
-
char* path_cstr = nullptr;
|
|
75
|
-
index_t* c_ptr = (index_t*)MArgument_getUTF8String(Args[0]);
|
|
76
|
-
try {
|
|
77
|
-
path_cstr = MArgument_getUTF8String(Args[1]);
|
|
78
|
-
c_ptr->view(path_cstr);
|
|
79
|
-
} catch (...) {
|
|
80
|
-
return LIBRARY_FUNCTION_ERROR;
|
|
81
|
-
}
|
|
82
|
-
libData->UTF8String_disown(path_cstr);
|
|
83
|
-
return LIBRARY_NO_ERROR;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
EXTERN_C DLLEXPORT int IndexDestroy(WolframLibraryData libData, mint Argc, MArgument* Args, MArgument Res) {
|
|
87
|
-
delete (index_t*)MArgument_getUTF8String(Args[0]);
|
|
88
|
-
return LIBRARY_NO_ERROR;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
EXTERN_C DLLEXPORT int IndexSize(WolframLibraryData libData, mint Argc, MArgument* Args, MArgument Res) {
|
|
92
|
-
std::size_t res = ((index_t*)MArgument_getUTF8String(Args[0]))->size();
|
|
93
|
-
MArgument_setInteger(Res, res);
|
|
94
|
-
return LIBRARY_NO_ERROR;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
EXTERN_C DLLEXPORT int IndexConnectivity(WolframLibraryData libData, mint Argc, MArgument* Args, MArgument Res) {
|
|
98
|
-
std::size_t res = ((index_t*)MArgument_getUTF8String(Args[0]))->connectivity();
|
|
99
|
-
MArgument_setInteger(Res, res);
|
|
100
|
-
return LIBRARY_NO_ERROR;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
EXTERN_C DLLEXPORT int IndexDimensions(WolframLibraryData libData, mint Argc, MArgument* Args, MArgument Res) {
|
|
104
|
-
std::size_t res = ((index_t*)MArgument_getUTF8String(Args[0]))->dimensions();
|
|
105
|
-
MArgument_setInteger(Res, res);
|
|
106
|
-
return LIBRARY_NO_ERROR;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
EXTERN_C DLLEXPORT int IndexCapacity(WolframLibraryData libData, mint Argc, MArgument* Args, MArgument Res) {
|
|
110
|
-
std::size_t res = ((index_t*)MArgument_getUTF8String(Args[0]))->capacity();
|
|
111
|
-
MArgument_setInteger(Res, res);
|
|
112
|
-
return LIBRARY_NO_ERROR;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
EXTERN_C DLLEXPORT int IndexAdd(WolframLibraryData libData, mint Argc, MArgument* Args, MArgument Res) {
|
|
116
|
-
char* path_cstr = nullptr;
|
|
117
|
-
index_t* c_ptr = (index_t*)MArgument_getUTF8String(Args[0]);
|
|
118
|
-
float* vector_data = nullptr;
|
|
119
|
-
try {
|
|
120
|
-
int key = MArgument_getInteger(Args[1]);
|
|
121
|
-
MTensor tens = MArgument_getMTensor(Args[2]);
|
|
122
|
-
std::size_t len = libData->MTensor_getFlattenedLength(tens);
|
|
123
|
-
vector_data = (float*)libData->MTensor_getRealData(tens);
|
|
124
|
-
vector_view_t vector_span = vector_view_t{vector_data, len};
|
|
125
|
-
c_ptr->add(key, vector_span);
|
|
126
|
-
} catch (...) {
|
|
127
|
-
return LIBRARY_FUNCTION_ERROR;
|
|
128
|
-
}
|
|
129
|
-
return LIBRARY_NO_ERROR;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
EXTERN_C DLLEXPORT int IndexSearch(WolframLibraryData libData, mint Argc, MArgument* Args, MArgument Res) {
|
|
133
|
-
index_t* c_ptr = (index_t*)MArgument_getUTF8String(Args[0]);
|
|
134
|
-
MTensor matches;
|
|
135
|
-
mint dims[] = {1};
|
|
136
|
-
int wanted = MArgument_getInteger(Args[2]);
|
|
137
|
-
float* vector_data = nullptr;
|
|
138
|
-
int* matches_data = nullptr;
|
|
139
|
-
std::size_t found = 0;
|
|
140
|
-
|
|
141
|
-
try {
|
|
142
|
-
libData->MTensor_new(MType_Integer, 1, dims, &matches);
|
|
143
|
-
|
|
144
|
-
MTensor tens = MArgument_getMTensor(Args[1]);
|
|
145
|
-
std::size_t len = libData->MTensor_getFlattenedLength(tens);
|
|
146
|
-
vector_data = (float*)libData->MTensor_getRealData(tens);
|
|
147
|
-
vector_view_t vector_span = vector_view_t{vector_data, len};
|
|
148
|
-
|
|
149
|
-
matches_data = (int*)std::malloc(sizeof(int) * wanted);
|
|
150
|
-
found = c_ptr->search(vector_span, static_cast<std::size_t>(wanted), matches_data, nullptr);
|
|
151
|
-
for (mint i = 0; i < found; i++)
|
|
152
|
-
libData->MTensor_setInteger(matches, &i, matches_data[i]);
|
|
153
|
-
|
|
154
|
-
MArgument_setMTensor(Res, matches);
|
|
155
|
-
} catch (...) {
|
|
156
|
-
return LIBRARY_FUNCTION_ERROR;
|
|
157
|
-
}
|
|
158
|
-
std::free(matches_data);
|
|
159
|
-
return LIBRARY_NO_ERROR;
|
|
160
|
-
}
|
package/wolfram/test.wls
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env wolframscript
|
|
2
|
-
|
|
3
|
-
IndexCreate = LibraryFunctionLoad["wolfram/usearchWFM.so", "IndexCreate", {"UTF8String", "UTF8String", Integer, Integer, Integer, Integer, Integer}, Integer]
|
|
4
|
-
IndexSave = LibraryFunctionLoad["wolfram/usearchWFM.so", "IndexSave", {Integer, "UTF8String"}, "Void"]
|
|
5
|
-
IndexLoad = LibraryFunctionLoad["wolfram/usearchWFM.so", "IndexLoad", {Integer, "UTF8String"}, "Void"]
|
|
6
|
-
IndexView = LibraryFunctionLoad["wolfram/usearchWFM.so", "IndexView", {Integer, "UTF8String"}, "Void"]
|
|
7
|
-
IndexDestroy = LibraryFunctionLoad["wolfram/usearchWFM.so", "IndexDestroy", {Integer}, "Void"]
|
|
8
|
-
IndexSize = LibraryFunctionLoad["wolfram/usearchWFM.so", "IndexSize", {Integer}, Integer]
|
|
9
|
-
IndexConnectivity = LibraryFunctionLoad["wolfram/usearchWFM.so", "IndexConnectivity", {Integer}, Integer]
|
|
10
|
-
IndexDimensions = LibraryFunctionLoad["wolfram/usearchWFM.so", "IndexDimensions", {Integer}, Integer]
|
|
11
|
-
IndexCapacity = LibraryFunctionLoad["wolfram/usearchWFM.so", "IndexCapacity", {Integer}, Integer]
|
|
12
|
-
IndexAdd = LibraryFunctionLoad["wolfram/usearchWFM.so", "IndexAdd", {Integer, Integer, {Real, 1}}, "Void"]
|
|
13
|
-
IndexSearch = LibraryFunctionLoad["wolfram/usearchWFM.so", "IndexSearch", {Integer, {Real, 1}, Integer}, {Integer, 1}]
|
|
14
|
-
Print["Functions Loaded"]
|
|
15
|
-
|
|
16
|
-
$index = IndexCreate["cos", "f16", 10, 10, 10, 10, 10]
|
|
17
|
-
Print["New Index Address: ", $index]
|
|
18
|
-
Print["Index Size: ", IndexSize[$index]]
|
|
19
|
-
Print["Index Capacity: ", IndexCapacity[$index]]
|
|
20
|
-
Print["Index Connectivity: ", IndexConnectivity[$index]]
|
|
21
|
-
$arr = {1.0, 2.0, 3.0, 4.0, 5.0};
|
|
22
|
-
IndexAdd[$index, 42, $arr]
|
|
23
|
-
Print["Added Array: ", $arr]
|
|
24
|
-
$res = IndexSearch[$index, $arr, 42]
|
|
25
|
-
Print["Searched: ", $res]
|
|
26
|
-
IndexDestroy[$index]
|
|
27
|
-
Print["Index Destroyed"]
|