summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorROUVREAU Vincent <vincent.rouvreau@inria.fr>2021-07-01 17:30:38 +0200
committerROUVREAU Vincent <vincent.rouvreau@inria.fr>2021-07-01 17:30:38 +0200
commitf70e6f26f329428184fc5cf935ad4dfc20648bfb (patch)
tree8dff005f5ddbbf5e4efe774cee2234883ac96684
parent67366f6ad3770da26f101dc5f6d2e600219e2ace (diff)
Revert AlphaComplex3D. To be done with periodic
-rw-r--r--src/Alpha_complex/example/Alpha_complex_3d_from_points.cpp29
-rw-r--r--src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp29
-rw-r--r--src/Alpha_complex/include/gudhi/Alpha_complex_3d.h19
-rw-r--r--src/Alpha_complex/test/Alpha_complex_3d_unit_test.cpp30
-rw-r--r--src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp2
-rw-r--r--src/python/CMakeLists.txt2
-rw-r--r--src/python/doc/alpha_complex_ref.rst6
-rw-r--r--src/python/doc/alpha_complex_user.rst14
-rw-r--r--src/python/gudhi/alpha_complex_3d.pyx135
-rw-r--r--src/python/include/Alpha_complex_factory.h35
-rwxr-xr-xsrc/python/test/test_alpha_complex_3d.py159
11 files changed, 42 insertions, 418 deletions
diff --git a/src/Alpha_complex/example/Alpha_complex_3d_from_points.cpp b/src/Alpha_complex/example/Alpha_complex_3d_from_points.cpp
index dd3c0225..a2c85138 100644
--- a/src/Alpha_complex/example/Alpha_complex_3d_from_points.cpp
+++ b/src/Alpha_complex/example/Alpha_complex_3d_from_points.cpp
@@ -34,22 +34,23 @@ int main(int argc, char **argv) {
Alpha_complex_3d alpha_complex_from_points(points);
Gudhi::Simplex_tree<> simplex;
- alpha_complex_from_points.create_complex(simplex);
- // ----------------------------------------------------------------------------
- // Display information about the alpha complex
- // ----------------------------------------------------------------------------
- std::clog << "Alpha complex is of dimension " << simplex.dimension() << " - " << simplex.num_simplices()
- << " simplices - " << simplex.num_vertices() << " vertices." << std::endl;
+ if (alpha_complex_from_points.create_complex(simplex)) {
+ // ----------------------------------------------------------------------------
+ // Display information about the alpha complex
+ // ----------------------------------------------------------------------------
+ std::clog << "Alpha complex is of dimension " << simplex.dimension() << " - " << simplex.num_simplices()
+ << " simplices - " << simplex.num_vertices() << " vertices." << std::endl;
- std::clog << "Iterator on alpha complex simplices in the filtration order, with [filtration value]:" << std::endl;
- for (auto f_simplex : simplex.filtration_simplex_range()) {
- std::clog << " ( ";
- for (auto vertex : simplex.simplex_vertex_range(f_simplex)) {
- std::clog << vertex << " ";
+ std::clog << "Iterator on alpha complex simplices in the filtration order, with [filtration value]:" << std::endl;
+ for (auto f_simplex : simplex.filtration_simplex_range()) {
+ std::clog << " ( ";
+ for (auto vertex : simplex.simplex_vertex_range(f_simplex)) {
+ std::clog << vertex << " ";
+ }
+ std::clog << ") -> "
+ << "[" << simplex.filtration(f_simplex) << "] ";
+ std::clog << std::endl;
}
- std::clog << ") -> "
- << "[" << simplex.filtration(f_simplex) << "] ";
- std::clog << std::endl;
}
return 0;
}
diff --git a/src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp b/src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp
index 507d6413..ee12d418 100644
--- a/src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp
+++ b/src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp
@@ -30,22 +30,23 @@ int main(int argc, char **argv) {
Weighted_alpha_complex_3d alpha_complex_from_points(weighted_points);
Gudhi::Simplex_tree<> simplex;
- alpha_complex_from_points.create_complex(simplex);
- // ----------------------------------------------------------------------------
- // Display information about the alpha complex
- // ----------------------------------------------------------------------------
- std::clog << "Weighted alpha complex is of dimension " << simplex.dimension() << " - " << simplex.num_simplices()
- << " simplices - " << simplex.num_vertices() << " vertices." << std::endl;
+ if (alpha_complex_from_points.create_complex(simplex)) {
+ // ----------------------------------------------------------------------------
+ // Display information about the alpha complex
+ // ----------------------------------------------------------------------------
+ std::clog << "Weighted alpha complex is of dimension " << simplex.dimension() << " - " << simplex.num_simplices()
+ << " simplices - " << simplex.num_vertices() << " vertices." << std::endl;
- std::clog << "Iterator on weighted alpha complex simplices in the filtration order, with [filtration value]:" << std::endl;
- for (auto f_simplex : simplex.filtration_simplex_range()) {
- std::clog << " ( ";
- for (auto vertex : simplex.simplex_vertex_range(f_simplex)) {
- std::clog << vertex << " ";
+ std::clog << "Iterator on weighted alpha complex simplices in the filtration order, with [filtration value]:" << std::endl;
+ for (auto f_simplex : simplex.filtration_simplex_range()) {
+ std::clog << " ( ";
+ for (auto vertex : simplex.simplex_vertex_range(f_simplex)) {
+ std::clog << vertex << " ";
+ }
+ std::clog << ") -> "
+ << "[" << simplex.filtration(f_simplex) << "] ";
+ std::clog << std::endl;
}
- std::clog << ") -> "
- << "[" << simplex.filtration(f_simplex) << "] ";
- std::clog << std::endl;
}
return 0;
}
diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h b/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h
index 73f9dd41..4e5fc933 100644
--- a/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h
+++ b/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h
@@ -48,7 +48,6 @@
#include <memory> // for std::unique_ptr
#include <type_traits> // for std::conditional and std::enable_if
#include <limits> // for numeric_limits<>
-#include <exception> // for domain_error and invalid_argument
// Make compilation fail - required for external projects - https://github.com/GUDHI/gudhi-devel/issues/10
#if CGAL_VERSION_NR < 1041101000
@@ -429,18 +428,19 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Bare_
* @param[in] max_alpha_square maximum for alpha square value. Default value is +\f$\infty\f$, and there is very
* little point using anything else since it does not save time.
*
- * @exception invalid_argument In debug mode, if `complex` given as argument is not empty.
- * @exception domain_error If `points` given in the constructor are on a 2d plane.
+ * @return true if creation succeeds, false otherwise.
*
* @pre The simplicial complex must be empty (no vertices).
*
*/
template <typename SimplicialComplexForAlpha3d,
typename Filtration_value = typename SimplicialComplexForAlpha3d::Filtration_value>
- void create_complex(SimplicialComplexForAlpha3d& complex,
+ bool create_complex(SimplicialComplexForAlpha3d& complex,
Filtration_value max_alpha_square = std::numeric_limits<Filtration_value>::infinity()) {
- GUDHI_CHECK(complex.num_vertices() == 0,
- std::invalid_argument("Alpha_complex_3d create_complex - The complex given as argument is not empty"));
+ if (complex.num_vertices() > 0) {
+ std::cerr << "Alpha_complex_3d create_complex - complex is not empty\n";
+ return false; // ----- >>
+ }
using Complex_vertex_handle = typename SimplicialComplexForAlpha3d::Vertex_handle;
using Simplex_tree_vector_vertex = std::vector<Complex_vertex_handle>;
@@ -461,8 +461,10 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Bare_
#ifdef DEBUG_TRACES
std::clog << "filtration_with_alpha_values returns : " << objects.size() << " objects" << std::endl;
#endif // DEBUG_TRACES
- if (objects.size() == 0)
- throw std::domain_error("Alpha_complex_3d create_complex - no triangulation as points are on a 2d plane");
+ if (objects.size() == 0) {
+ std::cerr << "Alpha_complex_3d create_complex - no triangulation as points are on a 2d plane\n";
+ return false; // ----- >>
+ }
using Alpha_value_iterator = typename std::vector<FT>::const_iterator;
Alpha_value_iterator alpha_value_iterator = alpha_values.begin();
@@ -557,6 +559,7 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Bare_
// Remove all simplices that have a filtration value greater than max_alpha_square
complex.prune_above_filtration(max_alpha_square);
// --------------------------------------------------------------------------------------------
+ return true;
}
/** \brief get_point returns the point corresponding to the vertex given as parameter.
diff --git a/src/Alpha_complex/test/Alpha_complex_3d_unit_test.cpp b/src/Alpha_complex/test/Alpha_complex_3d_unit_test.cpp
index 94021954..a4ecb6ad 100644
--- a/src/Alpha_complex/test/Alpha_complex_3d_unit_test.cpp
+++ b/src/Alpha_complex/test/Alpha_complex_3d_unit_test.cpp
@@ -11,7 +11,6 @@
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE "alpha_complex_3d"
#include <boost/test/unit_test.hpp>
-#include <boost/mpl/list.hpp>
#include <cmath> // float comparison
#include <limits>
@@ -37,7 +36,6 @@ using Safe_alpha_complex_3d =
using Exact_alpha_complex_3d =
Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::EXACT, false, false>;
-
template <typename Point>
std::vector<Point> get_points() {
std::vector<Point> points;
@@ -199,31 +197,3 @@ BOOST_AUTO_TEST_CASE(Alpha_complex_3d_from_points) {
++safe_sh;
}
}
-
-typedef boost::mpl::list<Fast_alpha_complex_3d, Safe_alpha_complex_3d, Exact_alpha_complex_3d> list_of_alpha_variants;
-
-BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_3d_exceptions_points_on_plane, Alpha, list_of_alpha_variants) {
- std::vector<typename Alpha::Bare_point_3> points_on_plane;
- points_on_plane.emplace_back(1.0, 1.0 , 0.0);
- points_on_plane.emplace_back(7.0, 0.0 , 0.0);
- points_on_plane.emplace_back(4.0, 6.0 , 0.0);
- points_on_plane.emplace_back(9.0, 6.0 , 0.0);
- points_on_plane.emplace_back(0.0, 14.0, 0.0);
- points_on_plane.emplace_back(2.0, 19.0, 0.0);
- points_on_plane.emplace_back(9.0, 17.0, 0.0);
-
- Alpha alpha_complex(points_on_plane);
- Gudhi::Simplex_tree<> stree;
-
- BOOST_CHECK_THROW(alpha_complex.create_complex(stree), std::domain_error);
-}
-
-BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_3d_exceptions_non_empty_simplex_tree, Alpha, list_of_alpha_variants) {
- Alpha alpha_complex(get_points<typename Alpha::Bare_point_3>());
- Gudhi::Simplex_tree<> stree;
- stree.insert_simplex_and_subfaces({2,1,0}, 3.0);
-
-#ifdef GUDHI_DEBUG
- BOOST_CHECK_THROW(alpha_complex.create_complex(stree), std::invalid_argument);
-#endif // GUDHI_DEBUG
-} \ No newline at end of file
diff --git a/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp b/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp
index 4e1a38df..875704ee 100644
--- a/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp
+++ b/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp
@@ -83,7 +83,7 @@ BOOST_AUTO_TEST_CASE(Weighted_alpha_complex_3d_comparison) {
// Weighted alpha complex for 3D version
Exact_weighted_alpha_complex_3d alpha_complex_3D_from_weighted_points(w_points_3);
Gudhi::Simplex_tree<> w_simplex_3;
- alpha_complex_3D_from_weighted_points.create_complex(w_simplex_3);
+ BOOST_CHECK(alpha_complex_3D_from_weighted_points.create_complex(w_simplex_3));
std::clog << "Iterator on weighted alpha complex 3D simplices in the filtration order, with [filtration value]:"
<< std::endl;
diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt
index 669239b8..bfa78131 100644
--- a/src/python/CMakeLists.txt
+++ b/src/python/CMakeLists.txt
@@ -62,7 +62,6 @@ if(PYTHONINTERP_FOUND)
set(GUDHI_PYTHON_MODULES "${GUDHI_PYTHON_MODULES}'subsampling', ")
set(GUDHI_PYTHON_MODULES "${GUDHI_PYTHON_MODULES}'tangential_complex', ")
set(GUDHI_PYTHON_MODULES "${GUDHI_PYTHON_MODULES}'alpha_complex', ")
- set(GUDHI_PYTHON_MODULES "${GUDHI_PYTHON_MODULES}'alpha_complex_3d', ")
set(GUDHI_PYTHON_MODULES "${GUDHI_PYTHON_MODULES}'euclidean_witness_complex', ")
set(GUDHI_PYTHON_MODULES "${GUDHI_PYTHON_MODULES}'euclidean_strong_witness_complex', ")
# Modules that should not be auto-imported in __init__.py
@@ -158,7 +157,6 @@ if(PYTHONINTERP_FOUND)
set(GUDHI_CYTHON_MODULES "${GUDHI_CYTHON_MODULES}'nerve_gic', ")
endif ()
if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0)
- set(GUDHI_CYTHON_MODULES "${GUDHI_CYTHON_MODULES}'alpha_complex_3d', ")
set(GUDHI_CYTHON_MODULES "${GUDHI_CYTHON_MODULES}'subsampling', ")
set(GUDHI_CYTHON_MODULES "${GUDHI_CYTHON_MODULES}'tangential_complex', ")
set(GUDHI_CYTHON_MODULES "${GUDHI_CYTHON_MODULES}'euclidean_witness_complex', ")
diff --git a/src/python/doc/alpha_complex_ref.rst b/src/python/doc/alpha_complex_ref.rst
index 49321368..eaa72551 100644
--- a/src/python/doc/alpha_complex_ref.rst
+++ b/src/python/doc/alpha_complex_ref.rst
@@ -11,9 +11,3 @@ Alpha complex reference manual
:undoc-members:
.. automethod:: gudhi.AlphaComplex.__init__
-
-.. autoclass:: gudhi.AlphaComplex3D
- :members:
- :undoc-members:
-
- .. automethod:: gudhi.AlphaComplex3D.__init__
diff --git a/src/python/doc/alpha_complex_user.rst b/src/python/doc/alpha_complex_user.rst
index d7b09246..db0ccdc9 100644
--- a/src/python/doc/alpha_complex_user.rst
+++ b/src/python/doc/alpha_complex_user.rst
@@ -254,17 +254,3 @@ Then, it computes the persistence diagram and displays it:
dgm = stree.persistence()
gd.plot_persistence_diagram(dgm, legend = True)
plt.show()
-
-3d specific version
-^^^^^^^^^^^^^^^^^^^
-
-:Requires: `Eigen <installation.html#eigen>`_ :math:`\geq` 3.1.0 and `CGAL <installation.html#cgal>`_ :math:`\geq` 4.11.0.
-
-A specific module for Alpha complex is available in 3d (cf. :class:`~gudhi.AlphaComplex3D`) and
-allows to construct standard and weighted versions of alpha complexes.
-
-Remark
-""""""
-
-* Contrary to the dD version, with the 3d version, the vertices in the output simplex tree are not guaranteed to match
- the order of the input points. One can use :func:`~gudhi.AlphaComplex3D.get_point` to get the initial point back.
diff --git a/src/python/gudhi/alpha_complex_3d.pyx b/src/python/gudhi/alpha_complex_3d.pyx
deleted file mode 100644
index 578011a7..00000000
--- a/src/python/gudhi/alpha_complex_3d.pyx
+++ /dev/null
@@ -1,135 +0,0 @@
-# This file is part of the Gudhi Library - https://gudhi.inria.fr/ -
-# which is released under MIT.
-# See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full
-# license details.
-# Author(s): Vincent Rouvreau
-#
-# Copyright (C) 2021 Inria
-#
-# Modification(s):
-# - YYYY/MM Author: Description of the modification
-
-from __future__ import print_function
-from cython cimport numeric
-from libcpp.vector cimport vector
-from libcpp.utility cimport pair
-from libcpp.string cimport string
-from libcpp cimport bool
-from libc.stdint cimport intptr_t
-import errno
-import os
-import warnings
-
-from gudhi.simplex_tree cimport *
-from gudhi.simplex_tree import SimplexTree
-from gudhi import read_points_from_off_file
-
-__author__ = "Vincent Rouvreau"
-__copyright__ = "Copyright (C) 2021 Inria"
-__license__ = "GPL v3"
-
-cdef extern from "Alpha_complex_interface_3d.h" namespace "Gudhi":
- cdef cppclass Alpha_complex_interface_3d "Gudhi::alpha_complex::Alpha_complex_interface_3d":
- Alpha_complex_interface_3d(vector[vector[double]] points, vector[double] weights, bool fast_version, bool exact_version) nogil except +
- vector[double] get_point(int vertex) nogil except +
- void create_simplex_tree(Simplex_tree_interface_full_featured* simplex_tree, double max_alpha_square) nogil except +
-
-# AlphaComplex3D python interface
-cdef class AlphaComplex3D:
- """AlphaComplex3D is a simplicial complex constructed from the finite cells of a Delaunay Triangulation.
-
- The filtration value of each simplex is computed as the square of the circumradius of the simplex if the
- circumsphere is empty (the simplex is then said to be Gabriel), and as the minimum of the filtration values of the
- codimension 1 cofaces that make it not Gabriel otherwise.
-
- All simplices that have a filtration value strictly greater than a given alpha squared value are not inserted into
- the complex.
-
- .. note::
-
- When AlphaComplex3D is constructed with an infinite value of alpha, the complex is a Delaunay complex.
-
- .. warning::
-
- Contrary to the dD version, with the 3d version, the vertices in the output simplex tree are not guaranteed to
- match the order of the input points. One can use :func:`~gudhi.AlphaComplex3D.get_point` to get the initial
- point back.
- """
-
- cdef Alpha_complex_interface_3d * this_ptr
-
- # Fake constructor that does nothing but documenting the constructor
- def __init__(self, points=[], weights=[], precision='safe'):
- """AlphaComplex3D constructor.
-
- :param points: A list of points in 3d.
- :type points: Iterable[Iterable[float]]
-
- :param weights: A list of weights. If set, the number of weights must correspond to the number of points.
- :type weights: Iterable[float]
-
- :param precision: Alpha complex precision can be 'fast', 'safe' or 'exact'. Default is 'safe'.
- :type precision: string
-
- :raises ValueError: If the given points are not in 3d.
- :raises ValueError: In case of inconsistency between the number of points and weights.
- """
-
- # The real cython constructor
- def __cinit__(self, points = [], weights=[], precision = 'safe'):
- assert precision in ['fast', 'safe', 'exact'], "Alpha complex precision can only be 'fast', 'safe' or 'exact'"
- cdef bool fast = precision == 'fast'
- cdef bool exact = precision == 'exact'
-
- if len(points) > 0:
- if len(points[0]) != 3:
- raise ValueError("AlphaComplex3D only accepts 3d points as an input")
-
- # weights are set but is inconsistent with the number of points
- if len(weights) != 0 and len(weights) != len(points):
- raise ValueError("Inconsistency between the number of points and weights")
-
- # need to copy the points to use them without the gil
- cdef vector[vector[double]] pts
- cdef vector[double] wgts
- pts = points
- wgts = weights
- with nogil:
- self.this_ptr = new Alpha_complex_interface_3d(pts, wgts, fast, exact)
-
- def __dealloc__(self):
- if self.this_ptr != NULL:
- del self.this_ptr
-
- def __is_defined(self):
- """Returns true if AlphaComplex3D pointer is not NULL.
- """
- return self.this_ptr != NULL
-
- def get_point(self, vertex):
- """This function returns the point corresponding to a given vertex from the :class:`~gudhi.SimplexTree`.
-
- :param vertex: The vertex.
- :type vertex: int
- :rtype: list of float
- :returns: the point.
- """
- return self.this_ptr.get_point(vertex)
-
- def create_simplex_tree(self, max_alpha_square = float('inf')):
- """
- :param max_alpha_square: The maximum alpha square threshold the simplices shall not exceed. Default is set to
- infinity, and there is very little point using anything else since it does not save time.
- :type max_alpha_square: float
- :returns: A simplex tree created from the Delaunay Triangulation.
- :rtype: SimplexTree
-
- :raises ValueError: If the points given at construction time are on a plane.
- """
- stree = SimplexTree()
- cdef double mas = max_alpha_square
- cdef intptr_t stree_int_ptr=stree.thisptr
- with nogil:
- self.this_ptr.create_simplex_tree(<Simplex_tree_interface_full_featured*>stree_int_ptr,
- mas)
- return stree
diff --git a/src/python/include/Alpha_complex_factory.h b/src/python/include/Alpha_complex_factory.h
index fbbf8896..298469fe 100644
--- a/src/python/include/Alpha_complex_factory.h
+++ b/src/python/include/Alpha_complex_factory.h
@@ -147,41 +147,6 @@ class Inexact_alpha_complex_dD final : public Abstract_alpha_complex {
Alpha_complex<Kernel, Weighted> alpha_complex_;
};
-template <complexity Complexity, bool Weighted = false>
-class Alpha_complex_3D final : public Abstract_alpha_complex {
- private:
- using Bare_point = typename Alpha_complex_3d<Complexity, Weighted, false>::Bare_point_3;
- using Point = typename Alpha_complex_3d<Complexity, Weighted, false>::Point_3;
-
- static Bare_point pt_cython_to_cgal_3(std::vector<double> const& vec) {
- return Bare_point(vec[0], vec[1], vec[2]);
- }
-
- public:
- Alpha_complex_3D(const std::vector<std::vector<double>>& points)
- : alpha_complex_(boost::adaptors::transform(points, pt_cython_to_cgal_3)) {
- }
-
- Alpha_complex_3D(const std::vector<std::vector<double>>& points, const std::vector<double>& weights)
- : alpha_complex_(boost::adaptors::transform(points, pt_cython_to_cgal_3), weights) {
- }
-
- virtual std::vector<double> get_point(int vh) override {
- // Can be a Weighted or a Bare point in function of Weighted
- return Point_cgal_to_cython<Point, Weighted>()(alpha_complex_.get_point(vh));
- }
-
- virtual bool create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square,
- bool default_filtration_value) override {
- alpha_complex_.create_complex(*simplex_tree, max_alpha_square);
- return true;
- }
-
- private:
- Alpha_complex_3d<Complexity, Weighted, false> alpha_complex_;
-};
-
-
} // namespace alpha_complex
} // namespace Gudhi
diff --git a/src/python/test/test_alpha_complex_3d.py b/src/python/test/test_alpha_complex_3d.py
deleted file mode 100755
index a5d9373b..00000000
--- a/src/python/test/test_alpha_complex_3d.py
+++ /dev/null
@@ -1,159 +0,0 @@
-""" This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
- See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
- Author(s): Vincent Rouvreau
-
- Copyright (C) 2021 Inria
-
- Modification(s):
- - YYYY/MM Author: Description of the modification
-"""
-
-from gudhi import AlphaComplex3D
-import pytest
-import numpy as np
-
-try:
- # python3
- from itertools import zip_longest
-except ImportError:
- # python2
- from itertools import izip_longest as zip_longest
-
-
-
-def _empty_alpha(precision):
- alpha_complex = AlphaComplex3D(precision = precision)
- assert alpha_complex.__is_defined() == True
-
-def _one_3d_point_alpha(precision):
- alpha_complex = AlphaComplex3D(points=[[0, 0, 0]], precision = precision)
- assert alpha_complex.__is_defined() == True
-
-def test_empty_alpha():
- for precision in ['fast', 'safe', 'exact']:
- _empty_alpha(precision)
- _one_3d_point_alpha(precision)
-
-def _infinite_alpha(precision):
- point_list = [[0, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0], [0, 0, 1], [1, 0, 1], [0, 1, 1], [1, 1, 1]]
- alpha_complex = AlphaComplex3D(points=point_list, precision = precision)
- assert alpha_complex.__is_defined() == True
-
- stree = alpha_complex.create_simplex_tree()
- assert stree.__is_persistence_defined() == False
-
- assert stree.num_simplices() == 51
- assert stree.num_vertices() == len(point_list)
-
- for filtration in stree.get_filtration():
- if len(filtration[0]) == 1:
- assert filtration[1] == 0.
- if len(filtration[0]) == 4:
- assert filtration[1] == 0.75
-
- for idx in range(len(point_list)):
- pt_idx = point_list.index(alpha_complex.get_point(idx))
- assert pt_idx >= 0
- assert pt_idx < len(point_list)
-
- with pytest.raises(IndexError):
- alpha_complex.get_point(len(point_list))
-
-def test_infinite_alpha():
- for precision in ['fast', 'safe', 'exact']:
- _infinite_alpha(precision)
-
-def _filtered_alpha(precision):
- point_list = [[0, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0], [0, 0, 1], [1, 0, 1], [0, 1, 1], [1, 1, 1]]
- filtered_alpha = AlphaComplex3D(points=point_list, precision = precision)
-
- stree = filtered_alpha.create_simplex_tree(max_alpha_square=0.25)
-
- assert stree.num_simplices() == 20
- assert stree.num_vertices() == len(point_list)
-
- for filtration in stree.get_filtration():
- if len(filtration[0]) == 1:
- assert filtration[1] == 0.
- elif len(filtration[0]) == 2:
- assert filtration[1] == 0.25
- else:
- assert False
-
- for idx in range(len(point_list)):
- pt_idx = point_list.index(filtered_alpha.get_point(idx))
- assert pt_idx >= 0
- assert pt_idx < len(point_list)
-
- with pytest.raises(IndexError):
- filtered_alpha.get_point(len(point_list))
-
-def test_filtered_alpha():
- for precision in ['fast', 'safe', 'exact']:
- _filtered_alpha(precision)
-
-def _3d_points_on_a_plane(precision):
- alpha = AlphaComplex3D(points = [[1.0, 1.0 , 0.0],
- [7.0, 0.0 , 0.0],
- [4.0, 6.0 , 0.0],
- [9.0, 6.0 , 0.0],
- [0.0, 14.0, 0.0],
- [2.0, 19.0, 0.0],
- [9.0, 17.0, 0.0]], precision = precision)
-
- with pytest.raises(ValueError):
- stree = alpha.create_simplex_tree()
-
-def test_3d_points_on_a_plane():
- for precision in ['fast', 'safe', 'exact']:
- _3d_points_on_a_plane(precision)
-
-def test_inconsistency_points_and_weights():
- points = [[1.0, 1.0 , 1.0],
- [7.0, 0.0 , 2.0],
- [4.0, 6.0 , 0.0],
- [9.0, 6.0 , 1.0],
- [0.0, 14.0, 2.0],
- [2.0, 19.0, 0.0],
- [9.0, 17.0, 1.0]]
- with pytest.raises(ValueError):
- # 7 points, 8 weights, on purpose
- alpha = AlphaComplex3D(points = points,
- weights = [1., 2., 3., 4., 5., 6., 7., 8.])
-
- with pytest.raises(ValueError):
- # 7 points, 6 weights, on purpose
- alpha = AlphaComplex3D(points = points,
- weights = [1., 2., 3., 4., 5., 6.])
-
-def _weighted_doc_example(precision):
- pts = [[ 1., -1., -1.],
- [-1., 1., -1.],
- [-1., -1., 1.],
- [ 1., 1., 1.],
- [ 2., 2., 2.]]
- wgts = [4., 4., 4., 4., 1.]
- alpha = AlphaComplex3D(points = pts, weights = wgts, precision = precision)
- stree = alpha.create_simplex_tree()
-
- # Needs to retrieve points as points are shuffled
- get_idx = lambda idx: pts.index(alpha.get_point(idx))
- indices = [get_idx(x) for x in range(len(pts))]
-
- assert stree.filtration([indices[x] for x in [0, 1, 2, 3]]) == pytest.approx(-1.)
- assert stree.filtration([indices[x] for x in [0, 1, 3, 4]]) == pytest.approx(95.)
- assert stree.filtration([indices[x] for x in [0, 2, 3, 4]]) == pytest.approx(95.)
- assert stree.filtration([indices[x] for x in [1, 2, 3, 4]]) == pytest.approx(95.)
-
-def test_weighted_doc_example():
- for precision in ['fast', 'safe', 'exact']:
- _weighted_doc_example(precision)
-
-def test_points_not_in_3d():
- with pytest.raises(ValueError):
- alpha = AlphaComplex3D(points = np.random.rand(6,2))
- with pytest.raises(ValueError):
- alpha = AlphaComplex3D(points = np.random.rand(6,4))
-
- alpha = AlphaComplex3D(points = np.random.rand(6,3))
- assert alpha.__is_defined() == True \ No newline at end of file