| 413 | } |
| 414 | |
| 415 | void NGT::Index::insertFromRefinementObjectFile() { |
| 416 | NGT::Property prop; |
| 417 | getProperty(prop); |
| 418 | float maxMag = prop.maxMagnitude; |
| 419 | if (prop.maxMagnitude <= 0.0) { |
| 420 | std::stringstream msg; |
| 421 | msg << "Max magnitude is not set yet. " << maxMag; |
| 422 | NGTThrowException(msg); |
| 423 | } |
| 424 | auto &ros = getRefinementObjectSpace(); |
| 425 | auto &rrepo = ros.getRepository(); |
| 426 | auto &repo = getObjectSpace().getRepository(); |
| 427 | size_t dim = getDimension(); |
| 428 | auto dataSize = rrepo.size(); |
| 429 | std::vector<float> addedElement(dataSize); |
| 430 | |
| 431 | for (size_t idx = 1; idx < rrepo.size(); idx++) { |
| 432 | if (rrepo[idx] == 0) continue; |
| 433 | if (repo.size() > idx && repo[idx] != 0) continue; |
| 434 | std::vector<float> object; |
| 435 | ros.getObject(idx, object); |
| 436 | if (object.size() != dim) { |
| 437 | if (object.size() == dim + 1) { |
| 438 | object.resize(dim); |
| 439 | } else { |
| 440 | std::stringstream msg; |
| 441 | msg << "Fatal inner error! iInvalid dimension. " << dim << ":" << object.size(); |
| 442 | ; |
| 443 | NGTThrowException(msg); |
| 444 | } |
| 445 | } |
| 446 | if (prop.distanceType == NGT::ObjectSpace::DistanceType::DistanceTypeInnerProduct) { |
| 447 | double mag = 0.0; |
| 448 | for (auto &v : object) { |
| 449 | mag += v * v; |
| 450 | } |
| 451 | if (mag > maxMag) { |
| 452 | maxMag = mag; |
| 453 | } |
| 454 | object.emplace_back(sqrt(maxMag - mag)); |
| 455 | } |
| 456 | try { |
| 457 | insert(idx, object); |
| 458 | } catch (NGT::Exception &err) { |
| 459 | std::stringstream msg; |
| 460 | msg << "Cannot insert. " << idx << " " << err.what(); |
| 461 | NGTThrowException(msg); |
| 462 | } |
| 463 | if (idx + 1 > getObjectRepositorySize()) { |
| 464 | std::stringstream msg; |
| 465 | msg << "The object repository and refinement repository are inconsistent. " << idx + 1 << ":" |
| 466 | << getObjectRepositorySize(); |
| 467 | NGTThrowException(msg); |
| 468 | } |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | void NGT::Index::appendFromTextObjectFile(const std::string &indexPath, const std::string &data, |
nothing calls this directly
no test coverage detected