Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.milvus.common.utils;

import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ShortBuffer;
Expand Down Expand Up @@ -161,7 +162,7 @@ public static ByteBuffer f32VectorToBf16Buffer(List<Float> vector) {
* @return List of Float a float32 vector
*/
public static List<Float> fp16BufferToVector(ByteBuffer buf) {
buf.rewind(); // reset the read position
((Buffer) buf).rewind(); // reset the read position
List<Float> vector = new ArrayList<>();
ShortBuffer sbuf = buf.asShortBuffer();
for (int i = 0; i < sbuf.limit(); i++) {
Expand Down Expand Up @@ -198,7 +199,7 @@ public static ByteBuffer f32VectorToFp16Buffer(List<Float> vector) {
* @return List of Float the vector is converted to float32 values
*/
public static List<Float> bf16BufferToVector(ByteBuffer buf) {
buf.rewind(); // reset the read position
((Buffer) buf).rewind(); // reset the read position
List<Float> vector = new ArrayList<>();
ShortBuffer sbuf = buf.asShortBuffer();
for (int i = 0; i < sbuf.limit(); i++) {
Expand Down Expand Up @@ -234,7 +235,7 @@ public static ByteBuffer f16VectorToBuffer(List<Short> vector) {
* @return List of Short the vector is converted to a list of Short, each Short value is a float16 value
*/
public static List<Short> bufferToF16Vector(ByteBuffer buf) {
buf.rewind(); // reset the read position
((Buffer) buf).rewind(); // reset the read position
List<Short> vector = new ArrayList<>();
ShortBuffer sbuf = buf.asShortBuffer();
for (int i = 0; i < sbuf.limit(); i++) {
Expand Down
5 changes: 3 additions & 2 deletions sdk-core/src/main/java/io/milvus/param/ParamUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;

import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.*;
Expand Down Expand Up @@ -1329,11 +1330,11 @@ public static SortedMap<Long, Float> decodeSparseFloatVector(ByteBuffer buf) {
pBuf.put(aa[k]); // fill the first 4 bytes with the unit bytes
}
pBuf.putInt(0); // fill the last 4 bytes to zero
pBuf.rewind(); // reset position to head
((Buffer) pBuf).rewind(); // reset position to head
long k = pBuf.getLong(); // this is the long value converted from the uint

// here we get the float value as normal
buf.position(offset + 4); // position offsets 4 bytes since they were converted to long
((Buffer) buf).position(offset + 4); // position offsets 4 bytes since they were converted to long
float v = buf.getFloat(); // this is the float value
sparse.put(k, v);
}
Expand Down
Loading