Spaces:
Running
Running
File size: 3,408 Bytes
b110593 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
// _ _
// __ _____ __ ___ ___ __ _| |_ ___
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
// \ V V / __/ (_| |\ V /| | (_| | || __/
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
//
// Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
//
// CONTACT: [email protected]
//
package vectorizer
import (
"reflect"
"testing"
)
func TestCombineVectors(t *testing.T) {
type args struct {
vectors [][]float32
}
tests := []struct {
name string
args args
want []float32
}{
{
"Combine simple vectors",
args{
vectors: [][]float32{
{1, 2, 3},
{2, 3, 4},
},
},
[]float32{1.5, 2.5, 3.5},
},
{
"Combine empty vectors",
args{
vectors: [][]float32{},
},
[]float32{},
},
{
"Combine more complex vectors",
args{
vectors: [][]float32{
{-0.214571, -0.605529, -0.335769, -0.185277, -0.212256, 0.478032, -0.536662, 0.298211},
{-0.14713769, -0.06872862, 0.09911085, -0.06342313, 0.10092197, -0.06624051, -0.06812558, 0.07360107},
{-0.18123996, -0.2089612, 0.03738429, -0.26224917, 0.18499854, -0.2620146, -0.12802331, -0.07601682},
{-0.06659584, -0.17120242, 0.07603133, -0.07171547, 0.12537181, -0.19367254, -0.18376349, -0.05517439},
},
},
[]float32{-0.15238613, -0.2636053, -0.030810636, -0.1456662, 0.049759082, -0.010973915, -0.2291436, 0.060155217},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := CombineVectors(tt.args.vectors); !reflect.DeepEqual(got, tt.want) {
t.Errorf("CombineVectors() = %v, want %v", got, tt.want)
}
})
}
}
func TestCombineVectorsWithWeights(t *testing.T) {
type args struct {
vectors [][]float32
weights []float32
}
tests := []struct {
name string
args args
want []float32
}{
{
"Combine simple vectors with 0 weights",
args{
vectors: [][]float32{
{1, 2, 3},
{2, 3, 4},
},
weights: []float32{0, 0, 0},
},
[]float32{0, 0, 0},
},
{
"Combine simple vectors with 1 weights",
args{
vectors: [][]float32{
{1, 2, 3},
{2, 3, 4},
},
weights: []float32{1, 1, 1},
},
[]float32{1.5, 2.5, 3.5},
},
{
"Combine empty vectors",
args{
vectors: [][]float32{},
weights: []float32{},
},
[]float32{},
},
{
"Combine simple vectors without weights",
args{
vectors: [][]float32{
{1, 2, 3},
{2, 3, 4},
},
weights: nil,
},
[]float32{1.5, 2.5, 3.5},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := CombineVectorsWithWeights(tt.args.vectors, tt.args.weights); !reflect.DeepEqual(got, tt.want) {
t.Errorf("CombineVectors() = %v, want %v", got, tt.want)
}
})
}
}
func BenchmarkCombine(b *testing.B) {
for i := 0; i < b.N; i++ {
CombineVectors([][]float32{
{-0.214571, -0.605529, -0.335769, -0.185277, -0.212256, 0.478032, -0.536662, 0.298211},
{-0.14713769, -0.06872862, 0.09911085, -0.06342313, 0.10092197, -0.06624051, -0.06812558, 0.07360107},
{-0.18123996, -0.2089612, 0.03738429, -0.26224917, 0.18499854, -0.2620146, -0.12802331, -0.07601682},
{-0.06659584, -0.17120242, 0.07603133, -0.07171547, 0.12537181, -0.19367254, -0.18376349, -0.05517439},
})
}
}
|