Skip to content
Snippets Groups Projects
Commit e41000e6 authored by Brad Nelson's avatar Brad Nelson
Browse files

compile homology algorithm

parent c32130ff
Branches
No related tags found
No related merge requests found
...@@ -15,6 +15,7 @@ setup(name='topologylayer', ...@@ -15,6 +15,7 @@ setup(name='topologylayer',
CppExtension('topologylayer.functional.cohom_cpp', CppExtension('topologylayer.functional.cohom_cpp',
['topologylayer/functional/cohom_cpp/pybind.cpp', ['topologylayer/functional/cohom_cpp/pybind.cpp',
'topologylayer/functional/cohom_cpp/cohom.cpp', 'topologylayer/functional/cohom_cpp/cohom.cpp',
'topologylayer/functional/cohom_cpp/hom.cpp',
'topologylayer/functional/cohom_cpp/complex.cpp', 'topologylayer/functional/cohom_cpp/complex.cpp',
'topologylayer/functional/cohom_cpp/cocycle.cpp'], 'topologylayer/functional/cohom_cpp/cocycle.cpp'],
include_dirs=[include_dir], include_dirs=[include_dir],
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include <map> #include <map>
#include "sparsevec.h" #include "sparsevec.h"
#include "hom.h"
/* /*
Function to build boundary of simplicial complex once sorted order is determined. Function to build boundary of simplicial complex once sorted order is determined.
...@@ -26,7 +28,7 @@ std::vector<SparseF2Vec<int>> sorted_boundary(SimplicialComplex &X) { ...@@ -26,7 +28,7 @@ std::vector<SparseF2Vec<int>> sorted_boundary(SimplicialComplex &X) {
for (size_t j : X.filtration_perm ) { for (size_t j : X.filtration_perm ) {
row_inds.clear(); // clear out column row_inds.clear(); // clear out column
// go through non-zeros in boundary // go through non-zeros in boundary
for (auto i : X.bdr[j].cochain) { for (auto i : X.bdr[j].cochain.nzinds) {
row_inds.push_back(X.inv_filtration_perm[i]); // push location of bounday cell in filtration row_inds.push_back(X.inv_filtration_perm[i]); // push location of bounday cell in filtration
} }
// append sorted row_inds to B // append sorted row_inds to B
...@@ -54,7 +56,7 @@ void homology_reduction_alg(std::vector<SparseF2Vec<int>> &B, std::map<int, int> ...@@ -54,7 +56,7 @@ void homology_reduction_alg(std::vector<SparseF2Vec<int>> &B, std::map<int, int>
// we have completely reduced column // we have completely reduced column
break; break;
} else { } else {
if (pivot_to_col.count(piv)) { if (pivot_to_col.count(piv) > 0) {
// there is a column with that pivot // there is a column with that pivot
B[j].add(B[piv]); B[j].add(B[piv]);
} else { } else {
......
#include <torch/extension.h>
#include <vector>
#include "complex.h"
std::vector<torch::Tensor> persistence_forward_hom(SimplicialComplex &X, int MAXDIM);
#include <torch/extension.h> #include <torch/extension.h>
#include "hom.h"
#include "cohom.h" #include "cohom.h"
#include "complex.h" #include "complex.h"
...@@ -25,4 +26,5 @@ PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { ...@@ -25,4 +26,5 @@ PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
m.def("persistenceForward", &persistence_forward); m.def("persistenceForward", &persistence_forward);
m.def("persistenceBackward", &persistence_backward); m.def("persistenceBackward", &persistence_backward);
m.def("persistenceBackwardFlag", &persistence_backward_flag); m.def("persistenceBackwardFlag", &persistence_backward_flag);
m.def("persistenceForwardHom", &persistence_forward_hom);
} }
...@@ -106,7 +106,7 @@ class SparseF2Vec{ ...@@ -106,7 +106,7 @@ class SparseF2Vec{
// returns last non-zero row in column // returns last non-zero row in column
T pivot() { T pivot() {
return nzinds.back() == 0 ? std::numeric_limits<T>::max() : *(nzinds.back()); return nzinds.size() == 0 ? std::numeric_limits<T>::max() : nzinds.back();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment