-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add cocycles feature #23
Open
MonkeyBreaker
wants to merge
21
commits into
giotto-ai:main
Choose a base branch
from
MonkeyBreaker:add_cocycles
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
3fdb7ce
Add support to compute and retrieve cocycles
ed4f3d6
Update Python interface to support cocycles
457ae1f
Update gph/python/ripser_interface.py
a69e532
[PY] Rename do_cocycles into return_cocycles
c62a1f4
[PY] Add documentation to the cocycles output
e98c0db
[PY] Add test for cocycles when persistance pair
60626d7
[PY] Update cocycle to return a numpy array
e969b56
Update on @ulupo feedback
b260833
[TEST] Add explicit xfail for cocycle test
c2ad0d5
[CPP] Fix no cocycles output
a72e2a7
[CPP] Split cocycles for finite and essential
dcd8f94
[CPP] Refactor comput_cocycles to return the computed value
3132077
[CPP] Change cocycle type from int to index_t
24be18d
[CPP] use variable when getting pivot index
38e9246
[CPP] Fix bad rebase
MonkeyBreaker 31015b0
[PY] Fix bad rebase
MonkeyBreaker 2ab0b4b
[TEST] Remove warnings
MonkeyBreaker 80a4244
Update gph/python/ripser_interface.py
ulupo 73e57ba
Update gph/python/ripser_interface.py
ulupo 58a2591
Update gph/python/ripser_interface.py
ulupo 9094b07
[CPP] Fix invalid cocycle type
MonkeyBreaker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,15 +39,13 @@ to_numpy_barcodes(std::vector<barcodes_t> barcodes) | |
} | ||
|
||
#if defined USE_COEFFICIENTS | ||
PYBIND11_MODULE(gph_ripser_coeff, m) | ||
{ | ||
PYBIND11_MODULE(gph_ripser_coeff, m) { | ||
#else | ||
PYBIND11_MODULE(gph_ripser, m) | ||
{ | ||
PYBIND11_MODULE(gph_ripser, m) { | ||
#endif | ||
|
||
using namespace pybind11::literals; | ||
m.doc() = "Ripser python interface"; | ||
using namespace pybind11::literals; | ||
m.doc() = "Ripser python interface"; | ||
|
||
py::class_<flagPersGen>(m, "flagPersGen", py::module_local()) | ||
.def_readwrite("finite_0", &flagPersGen::finite_0) | ||
|
@@ -63,14 +61,15 @@ PYBIND11_MODULE(gph_ripser, m) | |
[&](ripserResults& res) { | ||
return to_numpy_barcodes(res.births_and_deaths_by_dim); | ||
}) | ||
.def_readwrite("cocycles_by_dim", &ripserResults::cocycles_by_dim) | ||
.def_readwrite("flag_persistence_generators_by_dim", | ||
&ripserResults::flag_persistence_generators); | ||
|
||
m.def( | ||
"rips_dm", | ||
[](py::array_t<value_t>& D, py::array_t<value_t>& diag, int modulus, | ||
int dim_max, float threshold, int num_threads, | ||
bool return_generators) { | ||
bool return_generators, const bool do_cocycles) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation: 3 spaces? |
||
// Setup distance matrix and figure out threshold | ||
auto D_ = static_cast<value_t*>(D.request().ptr); | ||
std::vector<value_t> distances(D_, D_ + D.size()); | ||
|
@@ -84,36 +83,38 @@ PYBIND11_MODULE(gph_ripser, m) | |
|
||
ripserResults res; | ||
ripser<compressed_lower_distance_matrix> r( | ||
std::move(dist), dim_max, threshold, modulus, num_threads, | ||
return_generators); | ||
std::move(dist), dim_max, threshold, modulus, | ||
num_threads, return_generators, do_cocycles); | ||
r.compute_barcodes(); | ||
r.copy_results(res); | ||
return res; | ||
}, | ||
"D"_a, "diag"_a, "modulus"_a, "dim_max"_a, "threshold"_a, | ||
"num_threads"_a, "return_generators"_a, "ripser distance matrix"); | ||
"D"_a, "N"_a, "modulus"_a, "dim_max"_a, "threshold"_a, "num_threads"_a, | ||
"return_generators"_a, "do_cocycles"_a, "ripser distance matrix"); | ||
|
||
m.def( | ||
"rips_dm_sparse", | ||
[](py::array_t<index_t>& I, py::array_t<index_t>& J, | ||
py::array_t<value_t>& V, int NEdges, int N, int modulus, int dim_max, | ||
float threshold, int num_threads, bool return_generators) { | ||
float threshold, int num_threads, bool return_generators, | ||
const bool do_cocycles) { | ||
auto I_ = static_cast<index_t*>(I.request().ptr); | ||
auto J_ = static_cast<index_t*>(J.request().ptr); | ||
auto V_ = static_cast<value_t*>(V.request().ptr); | ||
|
||
// Setup distance matrix and figure out threshold | ||
ripser<sparse_distance_matrix> r( | ||
sparse_distance_matrix(I_, J_, V_, NEdges, N, threshold), | ||
dim_max, threshold, modulus, num_threads, return_generators); | ||
dim_max, threshold, modulus, num_threads, | ||
return_generators, do_cocycles); | ||
r.compute_barcodes(); | ||
|
||
ripserResults res; | ||
r.copy_results(res); | ||
return res; | ||
}, | ||
"I"_a, "J"_a, "V"_a, "NEdges"_a, "N"_a, "modulus"_a, "dim_max"_a, | ||
"threshold"_a, "num_threads"_a, "return_generators"_a, | ||
"threshold"_a, "num_threads"_a, "return_generators"_a, "do_cocycles"_a, | ||
"ripser sparse distance matrix"); | ||
|
||
m.def("get_max_coefficient_field_supported", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this indentation intentionally 2 spaces instead of 4?