Skip to content

Commit

Permalink
fix: Make fp16&bf16 column use correct byte length (milvus-io#33684)
Browse files Browse the repository at this point in the history
See also milvus-io/milvus-sdk-go#756 milvus-io#31293

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
  • Loading branch information
congqixia authored and yellow-shine committed Jul 2, 2024
1 parent 127592f commit a03f82a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
10 changes: 5 additions & 5 deletions client/column/columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,12 @@ func FieldDataColumn(fd *schemapb.FieldData, begin, end int) (Column, error) {
data := x.Float16Vector
dim := int(vectors.GetDim())
if end < 0 {
end = len(data) / dim
end = len(data) / dim / 2
}
vector := make([][]byte, 0, end-begin)
for i := begin; i < end; i++ {
v := make([]byte, dim)
copy(v, data[i*dim:(i+1)*dim])
v := make([]byte, dim*2)
copy(v, data[i*dim*2:(i+1)*dim*2])
vector = append(vector, v)
}
return NewColumnFloat16Vector(fd.GetFieldName(), dim, vector), nil
Expand All @@ -300,12 +300,12 @@ func FieldDataColumn(fd *schemapb.FieldData, begin, end int) (Column, error) {
data := x.Bfloat16Vector
dim := int(vectors.GetDim())
if end < 0 {
end = len(data) / dim
end = len(data) / dim / 2
}
vector := make([][]byte, 0, end-begin) // shall not have remanunt
for i := begin; i < end; i++ {
v := make([]byte, dim)
copy(v, data[i*dim:(i+1)*dim])
copy(v, data[i*dim*2:(i+1)*dim*2])
vector = append(vector, v)
}
return NewColumnBFloat16Vector(fd.GetFieldName(), dim, vector), nil
Expand Down
13 changes: 6 additions & 7 deletions client/column/columns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,13 @@ func TestIDColumns(t *testing.T) {
)

t.Run("nil id", func(t *testing.T) {
col, err := IDColumns(intPKCol, nil, 0, -1)
assert.NoError(t, err)
assert.EqualValues(t, 0, col.Len())
col, err = IDColumns(strPKCol, nil, 0, -1)
assert.NoError(t, err)
assert.EqualValues(t, 0, col.Len())
_, err := IDColumns(intPKCol, nil, 0, -1)
assert.Error(t, err)
_, err = IDColumns(strPKCol, nil, 0, -1)
assert.Error(t, err)

idField := &schemapb.IDs{}
col, err = IDColumns(intPKCol, idField, 0, -1)
col, err := IDColumns(intPKCol, idField, 0, -1)
assert.NoError(t, err)
assert.EqualValues(t, 0, col.Len())
col, err = IDColumns(strPKCol, idField, 0, -1)
Expand Down
4 changes: 2 additions & 2 deletions client/column/vector_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a03f82a

Please sign in to comment.