ComputeDistanceByThreshold

API definition

APP_ERROR ComputeDistanceByThreshold(const std::vector<uint32_t> &queryIdxArr, uint32_t codeStartIdx, uint32_t codeNum, float threshold, bool aboveFilter, std::vector<std::vector<float>> &resDistArr, std::vector<std::vector<uint32_t>> &resIdxArr);

Function

Queries the distance between a specified number of feature vectors and designated vectors in the database, filters out calculated distances based on the threshold, and returns the distances and labels that meet the conditions.

Input

const std::vector<uint32_t> &queryIdxArr: ID of the query vector in the database.

uint32_t codeStartIdx: ID of the starting position where distance is to be calculated.

uint32_t codeNum: number of base vectors whose distances are to be calculated.

float threshold: threshold used for filtering. Distances smaller than the threshold are filtered out.

bool aboveFilter: reserved.

Output

std::vector<std::vector<float>> &resDistArr: returned two-dimensional array, indicating the distance between each query vector and the base vector that meets the threshold condition.

std::vector<std::vector<uint32_t>> &resIdxArr: returned two-dimensional array, indicating the label between each query vector and the base vector that meets the threshold condition.

Return value

APP_ERROR: return status. For details, see Return Code Reference.

Restrictions

  • The length of queryIdxArr must be the same as that of resDistArr and resIdxArr, that is, queryIdxArr.size() == resDistArr.size().
  • The value of queryIdxArr.size() must be greater than 0 and less than or equal to that of ntotal.
  • The value of codeNum must be greater than 0 and less than or equal to that of ntotal.
  • The sum of codeStartIdx and codeNum cannot be greater than ntotal.
  • The value of codeStartIdx must be greater than or equal to 0 and less than or equal to that of ntotal.