Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmake/MultipersCodegen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ set(MULTIPERS_CORE_GENERATED_FILES
"${MULTIPERS_GENERATED_ROOT}/tools/core/filtrations_instantiations.inc"
"${MULTIPERS_GENERATED_ROOT}/tools/core/simplextree_instantiations.inc"
"${MULTIPERS_GENERATED_ROOT}/tools/core/simplextree_conversion_instantiations.inc"
"${MULTIPERS_GENERATED_ROOT}/tools/core/slicer_instantiations.inc"
"${MULTIPERS_GENERATED_ROOT}/tools/core/slicer_conversion_instantiations.inc"
"${MULTIPERS_GENERATED_ROOT}/tools/core/slicer_instantiations1.inc"
"${MULTIPERS_GENERATED_ROOT}/tools/core/slicer_instantiations2.inc"
"${MULTIPERS_GENERATED_ROOT}/tools/core/slicer_instantiations3.inc"
"${MULTIPERS_GENERATED_ROOT}/multipers/_slicer_nanobind_registry.inc"
"${MULTIPERS_GENERATED_ROOT}/multipers/_mma_nanobind_registry.inc"
"${MULTIPERS_GENERATED_ROOT}/multipers/gudhi/filtrations_extern_templates.h"
"${MULTIPERS_GENERATED_ROOT}/multipers/gudhi/simplextree_multi_extern_templates.h"
"${MULTIPERS_GENERATED_ROOT}/multipers/gudhi/simplextree_conversion_extern_templates.h"
"${MULTIPERS_GENERATED_ROOT}/multipers/gudhi/slicer_extern_templates.h"
"${MULTIPERS_GENERATED_ROOT}/multipers/gudhi/slicer_conversion_extern_templates.h"
)

set(MULTIPERS_CODEGEN_DRIVER "${CMAKE_SOURCE_DIR}/tools/tempita_grid_gen.py")
Expand Down
26 changes: 19 additions & 7 deletions cmake/MultipersCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ function(multipers_add_core_object_library target_name source_file)
target_link_libraries(
${target_name}
PRIVATE
multipers::project_options
multipers::project_warnings
multipers::gudhi
multipers::phat
multipers::project_options
multipers::project_warnings
)
multipers_apply_common_build_flags(${target_name})
endfunction()
Expand All @@ -34,8 +34,18 @@ multipers_add_core_object_library(
multipers_core_filtrations_obj
)
multipers_add_core_object_library(
multipers_core_slicer_obj
"${CMAKE_SOURCE_DIR}/tools/core/slicer_core.cc"
multipers_core_slicer_obj1
"${CMAKE_SOURCE_DIR}/tools/core/slicer_core1.cc"
multipers_core_filtrations_obj
)
multipers_add_core_object_library(
multipers_core_slicer_obj2
"${CMAKE_SOURCE_DIR}/tools/core/slicer_core2.cc"
multipers_core_filtrations_obj
)
multipers_add_core_object_library(
multipers_core_slicer_obj3
"${CMAKE_SOURCE_DIR}/tools/core/slicer_core3.cc"
multipers_core_filtrations_obj
)
multipers_add_core_object_library(
Expand Down Expand Up @@ -65,7 +75,7 @@ if(MULTIPERS_BUILD_GRAPH_MPH0_BENCHMARK)
)
target_link_libraries(
multipers_benchmark_graph_mph0
PRIVATE multipers::project_options multipers::project_warnings multipers::gudhi
PRIVATE multipers::gudhi multipers::project_options multipers::project_warnings
)
multipers_apply_common_build_flags(multipers_benchmark_graph_mph0)
endif()
Expand All @@ -76,17 +86,19 @@ add_library(
$<TARGET_OBJECTS:multipers_core_backend_log_policy_obj>
$<TARGET_OBJECTS:multipers_core_filtrations_obj>
$<TARGET_OBJECTS:multipers_core_simplextree_obj>
$<TARGET_OBJECTS:multipers_core_slicer_obj>
$<TARGET_OBJECTS:multipers_core_slicer_obj1>
$<TARGET_OBJECTS:multipers_core_slicer_obj2>
$<TARGET_OBJECTS:multipers_core_slicer_obj3>
$<TARGET_OBJECTS:multipers_core_hera_obj>
$<TARGET_OBJECTS:multipers_core_graph_mph0_obj>
)
add_dependencies(multipers_core_shared multipers_codegen)
target_link_libraries(
multipers_core_shared
PRIVATE
multipers::project_options
multipers::gudhi
multipers::phat
multipers::project_options
multipers::backend_hera
multipers::tbb
multipers::openmp
Expand Down
6 changes: 3 additions & 3 deletions cmake/MultipersExtensions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ add_dependencies(
target_link_libraries(
multipers_nanobind_runtime_obj
PRIVATE
multipers::gudhi
multipers::phat
multipers::project_options
multipers::project_warnings
multipers::python
multipers::gudhi
multipers::phat
multipers::backend_mpfree
multipers::backend_muphasa
multipers::backend_function_delaunay
Expand Down Expand Up @@ -71,10 +71,10 @@ function(multipers_add_extension)
target_link_libraries(
${_target_name}
PRIVATE
multipers::gudhi
multipers::project_options
multipers::project_warnings
multipers::python
multipers::gudhi
)
if(NOT ARG_PHAT_MODE OR NOT ARG_PHAT_MODE STREQUAL "NONE")
target_link_libraries(${_target_name} PRIVATE multipers::phat)
Expand Down
56 changes: 20 additions & 36 deletions docs/notebooks/ops/AIDA.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions multipers/_2pac_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ nb::object minimal_presentation_for_target(nb::object target,
backend_name,
[&] {
return multipers::twopac_minpres_contiguous_interface(
input_wrapper.truc,
input_wrapper.get_slicer(),
degree,
full_resolution,
use_chunk,
Expand All @@ -57,7 +57,7 @@ nb::object minimal_presentation_for_target(nb::object target,
},
[&] {
return multipers::twopac_minpres_with_generators_contiguous_interface(
input_wrapper.truc,
input_wrapper.get_slicer(),
degree,
full_resolution,
use_chunk,
Expand Down
31 changes: 13 additions & 18 deletions multipers/_aida_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
#include <nanobind/stl/vector.h>

#include <algorithm>
#include <cstdint>
#include <stdexcept>
#include <utility>
#include <vector>

#include "ext_interface/aida_interface.hpp"
#include "interface_helper_structs.h"

#if !MULTIPERS_DISABLE_AIDA_INTERFACE
#include "ext_interface/nanobind_registry_runtime.hpp"
Expand All @@ -28,15 +28,15 @@ inline nb::object ensure_supported_target(nb::object slicer) {
}

inline nb::object to_colexical_target(const nb::object& target) {
return nb::cast(multipers::nanobind_helpers::colexical_slicer_copy(nb::cast<const CanonicalWrapper&>(target)));
return nb::cast<const CanonicalWrapper&>(target).build_colexical_permuted_slicer(false);
}

multipers::nanobind_helpers::BifiltrationMinpresDegreeBlock build_input_from_slicer(const CanonicalWrapper& wrapper) {
const int degree = multipers::nanobind_helpers::slicer_minpres_degree(wrapper);
const int degree = wrapper.get_min_pres_degree();
if (degree < 0) {
throw std::runtime_error("AIDA takes a minimal presentation as an input.");
}
if (wrapper.truc.get_number_of_parameters() != 2) {
if (wrapper.get_number_of_parameters() != 2) {
throw std::runtime_error("AIDA is only compatible with 2-parameter minimal presentations.");
}
return multipers::nanobind_helpers::extract_bifiltration_minpres_degree_block(wrapper, degree);
Expand Down Expand Up @@ -64,19 +64,14 @@ nb::object summand_to_slicer(nb::object target,

nb::object compact_grid = nb::none();
if (is_squeezed) {
std::vector<std::vector<int64_t>> used_coordinates(2);
used_coordinates[0].reserve(filtration_values.size());
used_coordinates[1].reserve(filtration_values.size());
for (const auto& degree : filtration_values) {
used_coordinates[0].push_back(multipers::nanobind_helpers::squeezed_raw_index_from_value(degree.first, 0));
used_coordinates[1].push_back(multipers::nanobind_helpers::squeezed_raw_index_from_value(degree.second, 1));
}
auto compacted =
multipers::nanobind_helpers::compact_squeezed_filtration_grid(filtration_grid, std::move(used_coordinates));
compact_grid = compacted.filtration_grid;
auto usedCoordinates =
Gudhi::multi_persistence::detail::Compacted_squeezed_filtration_grid::collect_used_squeezed_coordinates(
filtration_values);
Gudhi::multi_persistence::detail::Compacted_squeezed_filtration_grid compact(filtration_grid, usedCoordinates);
compact_grid = compact.filtrationGrid;
for (auto& degree : filtration_values) {
degree.first = multipers::nanobind_helpers::remap_squeezed_coordinate(degree.first, 0, compacted.remap);
degree.second = multipers::nanobind_helpers::remap_squeezed_coordinate(degree.second, 1, compacted.remap);
degree.first = compact.remap_squeezed_coordinate(degree.first, 0);
degree.second = compact.remap_squeezed_coordinate(degree.second, 1);
}
}

Expand All @@ -85,9 +80,9 @@ nb::object summand_to_slicer(nb::object target,
nb::object out =
multipers::nanobind_helpers::build_canonical_contiguous_f64_slicer_object_from_complex(target, complex);
auto& out_wrapper = nb::cast<CanonicalWrapper&>(out);
multipers::nanobind_helpers::mark_slicer_minpres(out_wrapper, degree);
out_wrapper.set_min_pres_degree(degree);
if (is_squeezed) {
out_wrapper.filtration_grid = compact_grid;
out_wrapper.set_filtration_grid(compact_grid);
}
return out;
}
Expand Down
19 changes: 9 additions & 10 deletions multipers/_end_curves_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ inline index_curves birth_curve_indices(const CanonicalWrapper& wrapper,
if (inf_indices.size() != 2) {
throw std::invalid_argument("birth_curves expects two infinity sentinel indices.");
}
const int degree = multipers::nanobind_helpers::slicer_minpres_degree(wrapper);
const int degree = wrapper.get_min_pres_degree();
if (degree < 0) {
throw std::runtime_error("birth_curves expects a minimal presentation.");
}
if (wrapper.truc.get_number_of_parameters() != 2) {
if (wrapper.get_number_of_parameters() != 2) {
throw std::runtime_error("birth_curves is only compatible with 2-parameter minimal presentations.");
}

Expand Down Expand Up @@ -276,16 +276,16 @@ inline index_curves death_curve_indices(const CanonicalWrapper& wrapper,
if (inf_indices.size() != 2) {
throw std::invalid_argument("death_curves expects two infinity sentinel indices.");
}
auto complex = multipers::persistence_algebra_death_curve_contiguous_interface(wrapper.truc, degree);
auto complex = multipers::persistence_algebra_death_curve_contiguous_interface(wrapper.get_slicer(), degree);
CanonicalWrapper death_wrapper;
multipers::build_slicer_from_complex(death_wrapper.truc, complex);
multipers::nanobind_helpers::mark_slicer_minpres(death_wrapper, degree);
death_wrapper.filtration_grid = wrapper.filtration_grid;
multipers::build_slicer_from_complex(death_wrapper.get_slicer(), complex);
death_wrapper.set_min_pres_degree(degree);
death_wrapper.set_filtration_grid(wrapper.get_filtration_grid());
if (aida_sort) {
death_wrapper = multipers::nanobind_helpers::colexical_slicer_copy(death_wrapper);
death_wrapper.sort_slicer_co_lexically();
}

const auto& dimensions = death_wrapper.truc.get_dimensions();
const auto& dimensions = death_wrapper.get_slicer().get_dimensions();
if (std::find(dimensions.begin(), dimensions.end(), degree) == dimensions.end()) {
return {};
}
Expand Down Expand Up @@ -358,8 +358,7 @@ NB_MODULE(_end_curves_interface, m) {
#else
nb::object target = multipers::nanobind_helpers::ensure_canonical_contiguous_f64_slicer_object(slicer);
if (aida_sort) {
target = nb::cast(multipers::nanobind_helpers::colexical_slicer_copy(
nb::cast<const mpendcurves::CanonicalWrapper&>(target)));
nb::cast<mpendcurves::CanonicalWrapper&>(target).sort_slicer_co_lexically();
}
return mpendcurves::birth_curve_indices(nb::cast<const mpendcurves::CanonicalWrapper&>(target),
inf_indices,
Expand Down
4 changes: 2 additions & 2 deletions multipers/_graphcode_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ using CanonicalWrapper = multipers::nanobind_helpers::canonical_contiguous_f64_s
inline multipers::graphcode_interface_input input_from_slicer(nb::object slicer) {
nb::object target = multipers::nanobind_helpers::ensure_canonical_contiguous_f64_slicer_object(slicer);
const auto& wrapper = nb::cast<const CanonicalWrapper&>(target);
const int degree = multipers::nanobind_helpers::slicer_minpres_degree(wrapper);
const int degree = wrapper.get_min_pres_degree();
if (degree < 0) {
throw std::runtime_error("graphcode expects a minimal-presentation slicer.");
}
if (wrapper.truc.get_number_of_parameters() != 2) {
if (wrapper.get_slicer().get_number_of_parameters() != 2) {
throw std::runtime_error("graphcode expects a 2-parameter minimal-presentation slicer.");
}

Expand Down
18 changes: 9 additions & 9 deletions multipers/_hera_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,12 @@ template <bool IsKcritical, typename Func>
decltype(auto) with_native_f64_slicer(const nb::handle& input, Func&& func) {
using NativeSlicer = native_f64_slicer_t<IsKcritical>;
return multipers::nanobind_helpers::visit_const_slicer_wrapper(
input, [&]<typename Desc>(const typename Desc::wrapper& wrapper) -> decltype(auto) {
input, [&]<typename Desc>(const typename Desc::interface& wrapper) -> decltype(auto) {
// Monte Carlo fast path always runs on non-vine float64 matrix slicers.
if constexpr (std::is_same_v<typename Desc::concrete, NativeSlicer>) {
return std::forward<Func>(func)(wrapper.truc);
return std::forward<Func>(func)(wrapper.get_slicer());
} else {
NativeSlicer copy(wrapper.truc);
NativeSlicer copy(wrapper.get_slicer());
return std::forward<Func>(func)(copy);
}
});
Expand All @@ -198,16 +198,16 @@ multipers::hera_module_presentation_input<int> module_input_from_slicer(nb::obje
throw std::runtime_error("Input has to be a slicer.");
}
return multipers::nanobind_helpers::visit_const_slicer_wrapper(
slicer, [&]<typename Desc>(const typename Desc::wrapper& wrapper) {
if (wrapper.truc.get_number_of_parameters() != 2) {
slicer, [&]<typename Desc>(const typename Desc::interface& wrapper) {
if (wrapper.get_slicer().get_number_of_parameters() != 2) {
throw std::runtime_error("Matching distance only supports 2-parameter slicers.");
}
if constexpr (Desc::is_kcritical) {
throw std::runtime_error("Matching distance expects 1-critical minimal-presentation slicers.");
}

auto block = multipers::nanobind_helpers::extract_bifiltration_minpres_degree_block(
wrapper, multipers::nanobind_helpers::slicer_minpres_degree(wrapper));
wrapper, wrapper.get_min_pres_degree());

multipers::hera_module_presentation_input<int> out;
out.generator_grades = std::move(block.row_grades);
Expand All @@ -225,11 +225,11 @@ multipers::hera_module_presentation_input<int> module_input_from_slicer(nb::obje

inline monte_carlo_slicer_metadata metadata_from_slicer(nb::handle input) {
return multipers::nanobind_helpers::visit_const_slicer_wrapper(
input, [&]<typename Desc>(const typename Desc::wrapper& wrapper) {
input, [&]<typename Desc>(const typename Desc::interface& wrapper) {
monte_carlo_slicer_metadata out;
out.is_kcritical = Desc::is_kcritical;
out.is_squeezed = multipers::nanobind_helpers::has_nonempty_filtration_grid(wrapper.filtration_grid);
out.num_parameters = static_cast<std::size_t>(wrapper.truc.get_number_of_parameters());
out.is_squeezed = multipers::nanobind_helpers::has_nonempty_filtration_grid(wrapper.get_filtration_grid());
out.num_parameters = static_cast<std::size_t>(wrapper.get_number_of_parameters());
return out;
});
}
Expand Down
6 changes: 3 additions & 3 deletions multipers/_mma_nanobind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ void bind_float_module_methods(Class& cls) {
"directions"_a = nb::none(),
"degree"_a = -1,
"keep_inf"_a = true)
// .def("evaluate_in_grid", nb::overload_cast<const std::vector<std::vector<T>>&>(&Module::evaluate_in_grid))
.def("evaluate_in_grid", nb::overload_cast<const std::vector<NDArray1>&>(&Module::evaluate_in_grid))
.def("evaluate_in_grid", nb::overload_cast<NDArray2>(&Module::evaluate_in_grid))
.def("evaluate_in_grid", nb::overload_cast<const std::vector<NDArray1>&>(&Module::evaluate_in_grid))
// .def("evaluate_in_grid", nb::overload_cast<const std::vector<std::vector<T>>&>(&Module::evaluate_in_grid))
.def("_compute_landscapes_box",
&Module::template compute_landscapes_from_box<std::int32_t>,
"degree"_a,
Expand Down Expand Up @@ -150,8 +150,8 @@ void bind_float_module_methods(Class& cls) {
"p"_a,
"normalize"_a = false,
"n_jobs"_a = 0)
// .def("distance_to", &Module::compute_distance_to_iterable, "pts"_a, "signed"_a = false, "n_jobs"_a = 0)
.def("distance_to", &Module::compute_distance_to_tensor, "pts"_a, "signed"_a = false, "n_jobs"_a = 0)
// .def("distance_to", &Module::compute_distance_to_iterable, "pts"_a, "signed"_a = false, "n_jobs"_a = 0)
.def("get_interleavings", &Module::compute_interleavings)
.def("get_interleavings", &Module::compute_interleavings_from_box);
}
Expand Down
4 changes: 2 additions & 2 deletions multipers/_mpfree_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ nb::object minimal_presentation_for_target(nb::object target,
"mpfree",
[&] {
return multipers::mpfree_minpres_contiguous_interface(
input_wrapper.truc, degree, full_resolution, use_chunk, use_clearing, verbose);
input_wrapper.get_slicer(), degree, full_resolution, use_chunk, use_clearing, verbose);
},
[&] {
return multipers::mpfree_minpres_with_generators_contiguous_interface(
input_wrapper.truc, degree, full_resolution, use_chunk, use_clearing, verbose);
input_wrapper.get_slicer(), degree, full_resolution, use_chunk, use_clearing, verbose);
});
}

Expand Down
10 changes: 5 additions & 5 deletions multipers/_multi_critical_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,9 @@ nb::object output_to_slicer(int target_template_id,
auto complex = multipers::build_contiguous_f64_slicer_from_output(output.filtration_values, output.boundaries, dims);
nb::object canonical_out = nb::borrow<nb::object>(nb::type<CanonicalWrapper>())();
auto& canonical_wrapper = nb::cast<CanonicalWrapper&>(canonical_out);
multipers::build_slicer_from_complex(canonical_wrapper.truc, complex);
multipers::build_slicer_from_complex(canonical_wrapper.get_slicer(), complex);
if (mark_minpres) {
multipers::nanobind_helpers::mark_slicer_minpres(canonical_wrapper, degree);
canonical_wrapper.set_min_pres_degree(degree);
}
return multipers::nanobind_helpers::astype_slicer_to_template_id(canonical_out, target_template_id);
}
Expand Down Expand Up @@ -449,7 +449,7 @@ NB_MODULE(_multi_critical_interface, m) {
{
nb::gil_scoped_release release;
auto input =
multipers::multi_critical_detail::multi_critical_input_from_kcontiguous_slicer(input_wrapper.truc);
multipers::multi_critical_detail::multi_critical_input_from_kcontiguous_slicer(input_wrapper.get_slicer());
out = multipers::multi_critical_resolution_interface<int>(input, use_logpath, true, verbose);
}
return mpmc::output_to_slicer(target_template_id, out, false, -1);
Expand All @@ -459,7 +459,7 @@ NB_MODULE(_multi_critical_interface, m) {
{
nb::gil_scoped_release release;
auto input =
multipers::multi_critical_detail::multi_critical_input_from_kcontiguous_slicer(input_wrapper.truc);
multipers::multi_critical_detail::multi_critical_input_from_kcontiguous_slicer(input_wrapper.get_slicer());
outs = multipers::multi_critical_minpres_all_interface<int>(input, use_logpath, true, verbose, swedish);
}
return nb::object(mpmc::tuple_from_size(outs.size(), [&](size_t i) -> nb::object {
Expand All @@ -471,7 +471,7 @@ NB_MODULE(_multi_critical_interface, m) {
{
nb::gil_scoped_release release;
auto input =
multipers::multi_critical_detail::multi_critical_input_from_kcontiguous_slicer(input_wrapper.truc);
multipers::multi_critical_detail::multi_critical_input_from_kcontiguous_slicer(input_wrapper.get_slicer());
out =
multipers::multi_critical_minpres_interface<int>(input, degree + 1, use_logpath, true, verbose, swedish);
}
Expand Down
Loading
Loading