forked from opensearch-project/neural-search
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVectorUtil.java
31 lines (27 loc) · 847 Bytes
/
VectorUtil.java
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
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
package org.opensearch.neuralsearch.common;
import java.util.List;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
/**
* Utility class for working with vectors
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class VectorUtil {
/**
* Converts a vector represented as a list to an array
*
* @param vectorAsList {@link List} of {@link Float}'s representing the vector
* @return array of floats produced from input list
*/
public static float[] vectorAsListToArray(List<Number> vectorAsList) {
float[] vector = new float[vectorAsList.size()];
for (int i = 0; i < vectorAsList.size(); i++) {
vector[i] = vectorAsList.get(i).floatValue();
}
return vector;
}
}