Skip to content

Commit

Permalink
Local Search Improvements (#15)
Browse files Browse the repository at this point in the history
1. Added a working, "quick" local search method which improves reassignment speed.
2. Added multiswap support.
3.  Improve exhaustive searcher using discreture.
  • Loading branch information
dnbaker authored Apr 23, 2020
1 parent 849df8e commit 7bfcd65
Show file tree
Hide file tree
Showing 9 changed files with 260 additions and 147 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@
[submodule "code/fastiota"]
path = fastiota
url = https://github.com/dnbaker/fastiota
[submodule "discreture"]
path = discreture
url = https://github.com/mraggi/discreture/
1 change: 1 addition & 0 deletions discreture
Submodule discreture added at c90e93
2 changes: 1 addition & 1 deletion distmat
Submodule distmat updated 4 files
+3 −3 Makefile
+70 −31 distmat.h
+1,750 −0 mio.hpp
+9 −1 test/span.cpp
30 changes: 30 additions & 0 deletions include/minocore/coreset/coreset.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ static const char *sm2str(SensitivityMethod sm) {
}
return "UNKNOWN";
}
using namespace std::literals;

template<typename IT, typename FT>
struct IndexCoreset {
Expand All @@ -65,6 +66,34 @@ struct IndexCoreset {
size_t size() const {return indices_.size();}
IndexCoreset(IndexCoreset &&o) = default;
IndexCoreset(const IndexCoreset &o) = default;
void write(gzFile fp) const {
uint64_t n = size();
if(gzwrite(fp, &n, sizeof(n)) != sizeof(n)) goto fail;
if(gzwrite(fp, indices_.data(), indices_.size() * sizeof(IT)) != int64_t(indices_.size() * sizeof(IT)))
goto fail;
if(gzwrite(fp, weights_.data(), weights_.size() * sizeof(FT)) != int64_t(weights_.size() * sizeof(FT)))
goto fail;
return;
fail:
throw std::runtime_error("Failed to write in "s + __PRETTY_FUNCTION__);
}
void write(std::FILE *fp) const {
uint64_t n = size();
if(std::fwrite(&n, sizeof(n), 1, fp) != 1) goto fail;
if(std::fwrite(indices_.data(), sizeof(IT), indices_.size(), fp) != int64_t(indices_.size()))
goto fail;
if(std::fwrite(weights_.data(), sizeof(FT), weights_.size(), fp) != int64_t(weights_.size()))
goto fail;
return;
fail:
throw std::runtime_error("Failed to write in "s + __PRETTY_FUNCTION__);
}
void write(std::string path) const {
gzFile fp = gzopen(path.data(), "rb");
if(!fp) throw std::runtime_error("Failed to open file in "s + __PRETTY_FUNCTION__);
write(fp);
gzclose(fp);
}
void compact(bool shrink_to_fit=true) {
// TODO: replace with hash map and compact
std::map<std::pair<IT, FT>, uint32_t> m;
Expand Down Expand Up @@ -205,6 +234,7 @@ struct CoresetSampler {
gzclose(fp);
}
void write(gzFile fp) const {
if(fl_asn_ || fl_bicriteria_points_) throw std::runtime_error("Not implemented: serialization for FL coreset samplers");
uint64_t n = np_;
gzwrite(fp, &n, sizeof(n));
#if VERBOSE_AF
Expand Down
Loading

0 comments on commit 7bfcd65

Please sign in to comment.