Skip to content
Snippets Groups Projects
Commit 84e038e3 authored by Mingchung Xia's avatar Mingchung Xia
Browse files

Added nifty & linux fallback revamp

parent 9d02e0e0
No related branches found
No related tags found
1 merge request!13HNSW Implementation with Testcases
Pipeline #114970 failed
......@@ -27,6 +27,15 @@
"version" : "2.2.0"
}
},
{
"identity" : "nifty",
"kind" : "remoteSourceControl",
"location" : "https://github.com/mingchungx/nifty.git",
"state" : {
"branch" : "master",
"revision" : "ac093ab6a67e4c6c5cfccbe67c65dac06111cf6a"
}
},
{
"identity" : "similarity-topology",
"kind" : "remoteSourceControl",
......
......@@ -22,6 +22,7 @@ let package = Package(
.package(url: "https://github.com/L1MeN9Yu/Elva", .upToNextMajor(from: "2.1.3")),
.package(url: "https://github.com/JadenGeller/similarity-topology", .exact("0.1.14")),
.package(url: "https://github.com/Jounce/Surge.git", .upToNextMajor(from: "2.0.0")),
.package(url: "https://github.com/mingchungx/nifty.git", .branch("master"))
],
targets: [
.target(
......@@ -31,6 +32,7 @@ let package = Package(
.product(name: "HNSWEphemeral", package: "similarity-topology"),
.product(name: "HNSWDurable", package: "similarity-topology", condition: .when(platforms: [.macOS])),
.product(name: "HNSWSample", package: "similarity-topology", condition: .when(platforms: [.macOS])),
.product(name: "Nifty", package: "nifty"),
.product(name: "ZSTD", package: "Elva"),
.byName(name: "Surge", condition: .when(platforms: [.macOS])),
],
......
......@@ -38,16 +38,19 @@ public struct CartesianDistanceMetric<Vector: Collection & Codable>: SimilarityM
}
#else
// TODO: Import using Nifty (currently unable to fetch package dependency)
// import Nifty
import Nifty
/// This implementation may be less efficient on Linux
public struct CartesianDistanceMetric<Vector: Collection & Codable>: SimilarityMetric where Vector.Element: BinaryFloatingPoint {
public func similarity(between someItem: Vector, _ otherItem: Vector) -> Vector.Element {
return someItem.enumerated().reduce(0) { result, item in
let diff = item.element - otherItem[item.offset]
return result + diff * diff
var sum: Vector.Element = 0
for (a, b) in zip(someItem, otherItem) {
let difference = a - b
sum += difference * difference
}
return sum
}
}
......
......@@ -53,8 +53,7 @@ public struct CosineSimilarityMetric<Vector: Collection & Codable>: SimilarityMe
}
#else
// TODO: Import using Nifty (currently unable to fetch package dependency)
// import Nifty
import Nifty
/// This implementation may be less efficient on Linux
public struct CosineSimilarityMetric<Vector: Collection & Codable>: SimilarityMetric where Vector.Element: BinaryFloatingPoint {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment