Skip to content

Commit

Permalink
Fix redefine build-in symbol lint issue
Browse files Browse the repository at this point in the history
Signed-off-by: Congqi Xia <[email protected]>
  • Loading branch information
congqixia committed Mar 20, 2024
1 parent 0985d33 commit 37ca3e3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
14 changes: 7 additions & 7 deletions entity/columns_sparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,20 @@ func (e sliceSparseEmbedding) Swap(i, j int) {
}

func deserializeSliceSparceEmbedding(bs []byte) (sliceSparseEmbedding, error) {
len := len(bs)
if len%8 != 0 {
length := len(bs)
if length%8 != 0 {
return sliceSparseEmbedding{}, errors.New("not valid sparse embedding bytes")
}

len = len / 8
length = length / 8

result := sliceSparseEmbedding{
positions: make([]uint32, len),
values: make([]float32, len),
len: len,
positions: make([]uint32, length),
values: make([]float32, length),
len: length,
}

for i := 0; i < len; i++ {
for i := 0; i < length; i++ {
result.positions[i] = binary.LittleEndian.Uint32(bs[i*8 : i*8+4])
result.values[i] = math.Float32frombits(binary.LittleEndian.Uint32(bs[i*8+4 : i*8+8]))
}
Expand Down
24 changes: 12 additions & 12 deletions entity/columns_sparse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@ import (
func TestSliceSparseEmbedding(t *testing.T) {
t.Run("normal_case", func(t *testing.T) {

len := 1 + rand.Intn(5)
positions := make([]uint32, len)
values := make([]float32, len)
for i := 0; i < len; i++ {
length := 1 + rand.Intn(5)
positions := make([]uint32, length)
values := make([]float32, length)
for i := 0; i < length; i++ {
positions[i] = uint32(i)
values[i] = rand.Float32()
}
se, err := NewSliceSparseEmbedding(positions, values)
require.NoError(t, err)

assert.EqualValues(t, len, se.Dim())
assert.EqualValues(t, len, se.Len())
assert.EqualValues(t, length, se.Dim())
assert.EqualValues(t, length, se.Len())

bs := se.Serialize()
nv, err := deserializeSliceSparceEmbedding(bs)
require.NoError(t, err)

for i := 0; i < len; i++ {
for i := 0; i < length; i++ {
pos, val, ok := se.Get(i)
require.True(t, ok)
assert.Equal(t, positions[i], pos)
Expand All @@ -54,7 +54,7 @@ func TestSliceSparseEmbedding(t *testing.T) {

_, _, ok := se.Get(-1)
assert.False(t, ok)
_, _, ok = se.Get(len)
_, _, ok = se.Get(length)
assert.False(t, ok)
})

Expand All @@ -71,10 +71,10 @@ func TestColumnSparseEmbedding(t *testing.T) {

v := make([]SparseEmbedding, 0, columnLen)
for i := 0; i < columnLen; i++ {
len := 1 + rand.Intn(5)
positions := make([]uint32, len)
values := make([]float32, len)
for j := 0; j < len; j++ {
length := 1 + rand.Intn(5)
positions := make([]uint32, length)
values := make([]float32, length)
for j := 0; j < length; j++ {
positions[j] = uint32(j)
values[j] = rand.Float32()
}
Expand Down

0 comments on commit 37ca3e3

Please sign in to comment.