Skip to content

Commit

Permalink
Further improving integration tests (within #154)
Browse files Browse the repository at this point in the history
  • Loading branch information
searchivairus committed Jan 29, 2018
1 parent b668436 commit 805a53a
Show file tree
Hide file tree
Showing 9 changed files with 330 additions and 252 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Index<dist_t>* CreateBlockMaxInvIndex(bool PrintProgress,
const string& SpaceType,
Space<dist_t>& space,
const ObjectVector& DataObjects) {
return new BlockMaxInvIndex<dist_t>(space, DataObjects);
return new BlockMaxInvIndex<dist_t>(PrintProgress, space, DataObjects);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Index<dist_t>* CreateSimplInvIndex(bool PrintProgress,
const string& SpaceType,
Space<dist_t>& space,
const ObjectVector& DataObjects) {
return new SimplInvIndex<dist_t>(space, DataObjects);
return new SimplInvIndex<dist_t>(PrintProgress, space, DataObjects);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Index<dist_t>* CreateWANDInvIndex(bool PrintProgress,
const string& SpaceType,
Space<dist_t>& space,
const ObjectVector& DataObjects) {
return new WandInvIndex<dist_t>(space, DataObjects);
return new WandInvIndex<dist_t>(PrintProgress, space, DataObjects);
}

/*
Expand Down
4 changes: 2 additions & 2 deletions similarity_search/include/method/blkmax_inverted_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ using std::string;
template <typename dist_t>
class BlockMaxInvIndex : public WandInvIndex<dist_t> {
public:
BlockMaxInvIndex(Space<dist_t>& space,
const ObjectVector& data) : WandInvIndex<dist_t>(space, data) {
BlockMaxInvIndex(bool printProgress, Space<dist_t>& space,
const ObjectVector& data) : WandInvIndex<dist_t>(printProgress, space, data) {
}

void CreateIndex(const AnyParams& IndexParams) override;
Expand Down
7 changes: 5 additions & 2 deletions similarity_search/include/method/simple_inverted_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ class SimplInvIndex : public Index<dist_t> {
* which are guaranteed to be be valid during testing.
* So, we can memorize them safely.
*/
SimplInvIndex(Space<dist_t>& space,
const ObjectVector& data) : Index<dist_t>(data),
SimplInvIndex(bool printProgress,
Space<dist_t>& space,
const ObjectVector& data) : printProgress_(printProgress),
Index<dist_t>(data),
pSpace_(dynamic_cast<SpaceSparseNegativeScalarProductFast*>(&space)) {
if (pSpace_ == nullptr) {
PREPARE_RUNTIME_ERR(err) <<
Expand Down Expand Up @@ -119,6 +121,7 @@ class SimplInvIndex : public Index<dist_t> {
: post_(&pl), post_pos_(0), qval_(qval), qval_x_docval_(qval_x_docval) {}
};

bool printProgress_;
SpaceSparseNegativeScalarProductFast* pSpace_;
std::unordered_map<unsigned, std::unique_ptr<PostList>> index_;
// disable copy and assign
Expand Down
5 changes: 3 additions & 2 deletions similarity_search/include/method/wand_inverted_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ class WandInvIndex : public SimplInvIndex<dist_t> {
* which are guaranteed to be be valid during testing.
* So, we can memorize them safely.
*/
WandInvIndex(Space<dist_t>& space,
const ObjectVector& data) : SimplInvIndex<dist_t>(space, data) {
WandInvIndex(bool printProgress,
Space<dist_t>& space,
const ObjectVector& data) : SimplInvIndex<dist_t>(printProgress, space, data) {
}

void CreateIndex(const AnyParams& IndexParams) override;
Expand Down
13 changes: 9 additions & 4 deletions similarity_search/src/method/simple_inverted_index.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,16 @@ void SimplInvIndex<dist_t>::CreateIndex(AnyParamManager& ParamManager) {
LOG(LIB_INFO) << "Collecting dictionary stat";

{
ProgressDisplay pbar(this->data_.size(), cerr);
unique_ptr<ProgressDisplay> pbar(printProgress_ ?
new ProgressDisplay(this->data_.size(), cerr) : nullptr);

for (const Object* o : this->data_) {
tmp_vect.clear();
UnpackSparseElements(o->data(), o->datalength(), tmp_vect);
for (const auto& e : tmp_vect) dict_qty[e.id_] ++;
++pbar;
if (pbar) ++(*pbar);
}
if (pbar) pbar->finish();
}

LOG(LIB_INFO) << "Actually creating the index";
Expand All @@ -182,7 +184,8 @@ void SimplInvIndex<dist_t>::CreateIndex(AnyParamManager& ParamManager) {
}

{
ProgressDisplay pbar(this->data_.size(), cerr);
unique_ptr<ProgressDisplay> pbar(printProgress_ ?
new ProgressDisplay(this->data_.size(), cerr) : nullptr);

// Fill posting lists
for (size_t did = 0; did < this->data_.size(); ++did) {
Expand All @@ -207,8 +210,10 @@ void SimplInvIndex<dist_t>::CreateIndex(AnyParamManager& ParamManager) {
CHECK(curr_pos < pl.qty_);
pl.entries_[curr_pos] = PostEntry(did, e.val_);
}
++pbar;
if (pbar) ++(*pbar);
}

if (pbar) pbar->finish();
}
#ifdef SANITY_CHECKS
// Sanity check
Expand Down
Loading

0 comments on commit 805a53a

Please sign in to comment.