Skip to content

Commit

Permalink
v1.7.0 update CAPI, fix some minor bugs of NGT and NGTQ and add a new…
Browse files Browse the repository at this point in the history
… graph construction type.
  • Loading branch information
masajiro committed Mar 28, 2019
1 parent fd2bbb0 commit 03f41fc
Show file tree
Hide file tree
Showing 15 changed files with 391 additions and 196 deletions.
6 changes: 3 additions & 3 deletions README-jp.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Neighborhood Graph and Tree for Indexing High-dimensional Data
ニュース
-------

- Python NGTはPYPIからpipでインストールが可能になりました。 (2019/1/17)
- [NGTQ](bin/ngtq/README-jp.md)(NGT with Quantization) が利用可能になりました。(2018/12/14 : v1.5.0)
- [ONNG](README-jp.md#onng)が利用可能になりました。(2018/08/08 : v1.4.0)
- 2019/01/17 Python NGTはPYPIからpipでインストールが可能になりました。
- 2018/12/14 [NGTQ](bin/ngtq/README-jp.md)(NGT with Quantization) が利用可能になりました。(v1.5.0)
- 2018/08/08 [ONNG](README-jp.md#onng)が利用可能になりました。(v1.4.0)

インストール
-----------
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Neighborhood Graph and Tree for Indexing High-dimensional Data
News
----

- Python NGT can be installed via pip from PyPI (1/17/2019)
- [NGTQ](bin/ngtq/README.md)(NGT with Quantization) is now available (12/14/2018 : v1.5.0)
- [ONNG](README.md#onng) is now available. (08/08/2018 : v1.4.0)
- 01/17/2019 Python NGT can be installed via pip from PyPI
- 12/14/2018 [NGTQ](bin/ngtq/README.md)(NGT with Quantization) is now available (v1.5.0)
- 08/08/2018 [ONNG](README.md#onng) is now available. (v1.4.0)

Installation
------------
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.6.2
1.7.0
45 changes: 5 additions & 40 deletions lib/NGT/Capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ NGTObjectDistances ngt_create_empty_results(NGTError error) {
}
}

bool ngt_search_index(NGTIndex index, double *query, int32_t query_dim, size_t size, float epsilon, NGTObjectDistances results, NGTError error) {
bool ngt_search_index(NGTIndex index, double *query, int32_t query_dim, size_t size, float epsilon, float radius, NGTObjectDistances results, NGTError error) {
if(index == NULL || query == NULL || results == NULL){
std::stringstream ss;
ss << "Capi : " << __FUNCTION__ << "() : parametor error: index = " << index << " query = " << query << " results = " << results;
Expand All @@ -275,7 +275,10 @@ bool ngt_search_index(NGTIndex index, double *query, int32_t query_dim, size_t s

NGT::Index* pindex = static_cast<NGT::Index*>(index);
NGT::Object *ngtquery = NULL;
const float radius = FLT_MAX;

if(radius < 0.0){
radius = FLT_MAX;
}

try{
std::vector<double> vquery(&query[0], &query[query_dim]);
Expand Down Expand Up @@ -304,44 +307,6 @@ bool ngt_search_index(NGTIndex index, double *query, int32_t query_dim, size_t s
return true;
}

bool ngt_search(NGTIndex index, double *query, NGTSearchParameter search_parameter, NGTObjectDistances results, NGTError error) {
if(index == NULL || query == NULL || results == NULL){
std::stringstream ss;
ss << "Capi : " << __FUNCTION__ << "() : parametor error: index = " << index << " query = " << query << " results = " << results;
operate_error_string_(ss, error);
return false;
}

NGT::Index* pindex = static_cast<NGT::Index*>(index);
NGT::Object *ngtquery = NULL;

try{
std::vector<double> vquery(&query[0], &query[search_parameter.query_dim]);
ngtquery = pindex->allocateObject(vquery);
// set search prameters.
NGT::SearchContainer sc(*ngtquery); // search parametera container.

sc.setResults(static_cast<NGT::ObjectDistances*>(results)); // set the result set.
sc.setSize(search_parameter.result_size); // the number of resultant objects.
sc.setRadius(search_parameter.radius); // search radius.
sc.setEpsilon(search_parameter.epsilon); // set exploration coefficient.

pindex->search(sc);

// delete the query object.
pindex->deleteObject(ngtquery);
}catch(std::exception &err) {
std::stringstream ss;
ss << "Capi : " << __FUNCTION__ << "() : Error: " << err.what();
operate_error_string_(ss, error);
if(ngtquery != NULL){
pindex->deleteObject(ngtquery);
}
return false;
}
return true;
}

// * deprecated *
int32_t ngt_get_size(NGTObjectDistances results, NGTError error) {
if(results == NULL){
Expand Down
11 changes: 1 addition & 10 deletions lib/NGT/Capi.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ typedef struct {
float distance;
} NGTObjectDistance;

typedef struct {
int32_t query_dim;
size_t result_size;
float epsilon;
float radius;
} NGTSearchParameter;

NGTIndex ngt_open_index(const char *, NGTError);

NGTIndex ngt_create_graph_and_tree(const char *, NGTProperty, NGTError);
Expand Down Expand Up @@ -83,10 +76,8 @@ bool ngt_set_property_distance_type_cosine(NGTProperty, NGTError);

NGTObjectDistances ngt_create_empty_results(NGTError);

bool ngt_search_index(NGTIndex, double*, int32_t, size_t, float, NGTObjectDistances, NGTError);
bool ngt_search_index(NGTIndex, double*, int32_t, size_t, float, float, NGTObjectDistances, NGTError);

bool ngt_search(NGTIndex, double*, NGTSearchParameter, NGTObjectDistances, NGTError);

int32_t ngt_get_size(NGTObjectDistances, NGTError); // deprecated

uint32_t ngt_get_result_size(NGTObjectDistances, NGTError);
Expand Down
21 changes: 17 additions & 4 deletions lib/NGT/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
NGT::Command::create(Args &args)
{
const string usage = "Usage: ngt create "
"-d dimension [-p #-of-thread] [-i index-type(t|g)] [-g graph-type(a|k|b|o)] "
"-d dimension [-p #-of-thread] [-i index-type(t|g)] [-g graph-type(a|k|b|o|i)] "
"[-t truncation-edge-limit] [-E edge-size] [-S edge-size-for-search] [-L edge-size-limit] "
"[-e epsilon] [-o object-type(f|c)] [-D distance-function(1|2|a|A|h|c|C)] [-n #-of-inserted-objects] "
"[-P path-adjustment-interval] [-B dynamic-edge-size-base] [-A object-alignment(t|f)] "
Expand Down Expand Up @@ -71,6 +71,7 @@
case 'b': property.graphType = NGT::Property::GraphType::GraphTypeBKNNG; break;
case 'd': property.graphType = NGT::Property::GraphType::GraphTypeDNNG; break;
case 'o': property.graphType = NGT::Property::GraphType::GraphTypeONNG; break;
case 'i': property.graphType = NGT::Property::GraphType::GraphTypeIANNG; break;
default:
cerr << "ngt: Error: Invalid graph type. " << graphType << endl;
cerr << usage << endl;
Expand Down Expand Up @@ -284,7 +285,10 @@
}
}
} catch (NGT::Exception &err) {
throw err;
if (searchParameter.outputMode != "ei") {
// not ignore exceptions
throw err;
}
}
totalTime += timer.time;
if (searchParameter.outputMode[0] == 'e') {
Expand Down Expand Up @@ -407,7 +411,7 @@
void
NGT::Command::remove(Args &args)
{
const string usage = "Usage: ngt remove [-d object-ID-type(f|d)] index(input) object-ID(input)";
const string usage = "Usage: ngt remove [-d object-ID-type(f|d)] [-m f] index(input) object-ID(input)";
string database;
try {
database = args.get("#1");
Expand All @@ -424,6 +428,11 @@
return;
}
char dataType = args.getChar("d", 'f');
char mode = args.getChar("m", '-');
bool force = false;
if (mode == 'f') {
force = true;
}
if (debugLevel >= 1) {
cerr << "dataType=" << dataType << endl;
}
Expand Down Expand Up @@ -472,7 +481,7 @@
cerr << "removed ID=" << id << endl;
objects.push_back(id);
}
NGT::Index::remove(database, objects);
NGT::Index::remove(database, objects, force);
} catch (NGT::Exception &err) {
cerr << "ngt: Error " << err.what() << endl;
cerr << usage << endl;
Expand Down Expand Up @@ -806,6 +815,10 @@
size_t smsize = index.getSharedMemorySize(msg);
cerr << "SharedMemorySize=" << smsize << endl;
NGT::GraphIndex::showStatisticsOfGraph(static_cast<NGT::GraphIndex&>(index.getIndex()), mode, edgeSize);
if (mode == 'v') {
vector<uint8_t> status;
index.verify(status);
}
} catch (NGT::Exception &err) {
cerr << "ngt: Error " << err.what() << endl;
cerr << usage << endl;
Expand Down
8 changes: 4 additions & 4 deletions lib/NGT/Graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ NeighborhoodGraph::setupSeeds(NGT::SearchContainer &sc, ObjectDistances &seeds,
ObjectDistance result;
result.id = seeds[i].id;;
if (objectRepository.isEmpty(result.id)) {
cerr << "setupseeds:fatal error " << result.id << endl;
assert(0);
cerr << "setupseeds:warning! unavailable object:" << result.id << "." << endl;
continue;
}
Distance d = comparator(sc.object, *objectRepository.get(result.id));
result.distance = d;
Expand All @@ -169,8 +169,8 @@ NeighborhoodGraph::setupSeeds(NGT::SearchContainer &sc, ObjectDistances &seeds,
ObjectDistance result;
result.id = seeds[i].id;
if (objectRepository.isEmpty(result.id)) {
cerr << "setupseeds:fatal error " << result.id << endl;
assert(0);
cerr << "setupseeds:warning! unavailable object:" << result.id << "." << endl;
continue;
}
result.distance = comparator(sc.object, *objects[result.id]);
tmp.push_back(result);
Expand Down
Loading

0 comments on commit 03f41fc

Please sign in to comment.