mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-25 03:05:52 -05:00
Replace float64 with float32 in vector operations.
This commit is contained in:
@@ -145,7 +145,7 @@ func NewProximityMap(ns tree.NodeStore, node tree.Node, keyDesc val.TupleDesc, v
|
||||
NodeStore: ns,
|
||||
Order: keyDesc,
|
||||
DistanceType: distanceType,
|
||||
Convert: func(ctx context.Context, bytes []byte) []float64 {
|
||||
Convert: func(ctx context.Context, bytes []byte) []float32 {
|
||||
h, _ := keyDesc.GetJSONAddr(0, bytes)
|
||||
doc := tree.NewJSONDoc(h, ns)
|
||||
jsonWrapper, err := doc.ToIndexedJSONDocument(ctx)
|
||||
@@ -509,7 +509,7 @@ func (b *ProximityMapBuilder) getNextPathSegmentCandidates(ctx context.Context,
|
||||
}
|
||||
|
||||
// getClosestVector iterates over a range of candidate vectors to determine which one is the closest to the target.
|
||||
func (b *ProximityMapBuilder) getClosestVector(ctx context.Context, targetVector []float64, nextCandidate func() (candidate hash.Hash, err error, valid bool)) (hash.Hash, error) {
|
||||
func (b *ProximityMapBuilder) getClosestVector(ctx context.Context, targetVector []float32, nextCandidate func() (candidate hash.Hash, err error, valid bool)) (hash.Hash, error) {
|
||||
// First call to nextCandidate is guaranteed to be valid because there's at least one vector in the set.
|
||||
// (non-root nodes inherit the first vector from their parent)
|
||||
candidateVectorHash, err, _ := nextCandidate()
|
||||
@@ -597,7 +597,7 @@ func getJsonValueFromHash(ctx context.Context, ns tree.NodeStore, h hash.Hash) (
|
||||
return tree.NewJSONDoc(h, ns).ToIndexedJSONDocument(ctx)
|
||||
}
|
||||
|
||||
func getVectorFromHash(ctx context.Context, ns tree.NodeStore, h hash.Hash) ([]float64, error) {
|
||||
func getVectorFromHash(ctx context.Context, ns tree.NodeStore, h hash.Hash) ([]float32, error) {
|
||||
otherValue, err := getJsonValueFromHash(ctx, ns, h)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -148,7 +148,7 @@ func validateHistoryIndependence(t *testing.T, ctx context.Context, ns tree.Node
|
||||
require.Equal(t, other.HashOf(), m.HashOf())
|
||||
}
|
||||
|
||||
func vectorFromKey(t *testing.T, ctx context.Context, ns tree.NodeStore, keyDesc val.TupleDesc, key []byte) []float64 {
|
||||
func vectorFromKey(t *testing.T, ctx context.Context, ns tree.NodeStore, keyDesc val.TupleDesc, key []byte) []float32 {
|
||||
vectorHash, _ := keyDesc.GetJSONAddr(0, key)
|
||||
jsonWrapper, err := getJsonValueFromHash(ctx, ns, vectorHash)
|
||||
require.NoError(t, err)
|
||||
@@ -168,7 +168,7 @@ func validateProximityMapNode(t *testing.T, ctx context.Context, ns tree.NodeSto
|
||||
return
|
||||
}
|
||||
// Get the vector in each key
|
||||
vectors := make([][]float64, nd.Count())
|
||||
vectors := make([][]float32, nd.Count())
|
||||
for vectorIdx := 0; vectorIdx < nd.Count(); vectorIdx++ {
|
||||
vectorKey := nd.GetKey(vectorIdx)
|
||||
vectors[vectorIdx] = vectorFromKey(t, ctx, ns, keyDesc, vectorKey)
|
||||
|
||||
@@ -56,7 +56,7 @@ func (f ProximityFlusher) ApplyMutationsWithSerializer(
|
||||
keyDesc := mutableMap.keyDesc
|
||||
valDesc := mutableMap.valDesc
|
||||
ns := mutableMap.NodeStore()
|
||||
convert := func(ctx context.Context, bytes []byte) []float64 {
|
||||
convert := func(ctx context.Context, bytes []byte) []float32 {
|
||||
h, _ := keyDesc.GetJSONAddr(0, bytes)
|
||||
doc := tree.NewJSONDoc(h, ns)
|
||||
jsonWrapper, err := doc.ToIndexedJSONDocument(ctx)
|
||||
@@ -161,7 +161,7 @@ func (f ProximityFlusher) visitNode(
|
||||
ns tree.NodeStore,
|
||||
node tree.Node,
|
||||
edits []VectorIndexKV,
|
||||
convert func(context.Context, []byte) []float64,
|
||||
convert func(context.Context, []byte) []float32,
|
||||
distanceType vector.DistanceType,
|
||||
keyDesc val.TupleDesc,
|
||||
valDesc val.TupleDesc,
|
||||
|
||||
@@ -35,7 +35,7 @@ type ProximityMap[K, V ~[]byte, O Ordering[K]] struct {
|
||||
NodeStore NodeStore
|
||||
DistanceType vector.DistanceType
|
||||
Order O
|
||||
Convert func(context.Context, []byte) []float64
|
||||
Convert func(context.Context, []byte) []float32
|
||||
Root Node
|
||||
}
|
||||
|
||||
@@ -270,7 +270,7 @@ func getJsonValueFromHash(ctx context.Context, ns NodeStore, h hash.Hash) (inter
|
||||
return NewJSONDoc(h, ns).ToIndexedJSONDocument(ctx)
|
||||
}
|
||||
|
||||
func getVectorFromHash(ctx context.Context, ns NodeStore, h hash.Hash) ([]float64, error) {
|
||||
func getVectorFromHash(ctx context.Context, ns NodeStore, h hash.Hash) ([]float32, error) {
|
||||
otherValue, err := getJsonValueFromHash(ctx, ns, h)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user