编写C++;简化C+的包装器+;使用复杂的层次结构初始化,以便Cython可以调用它 我试图为C++计算拓扑库GUDHI()设计一个Cython包装器。GUDHI类将其他类作为其参数,这些类将其他子类传递给它们的方法。直接推到Cython就有点乱了。我在下面有一个代码示例
我向Cython谷歌集团发布了一个问题,有人建议我用C++编写一个简化的包装器来隐藏Cython的这种复杂性。评论内容如下 <> P>一种选择,如果事情变得复杂,就是在C++中编写简化的包装器并调用这些包装器。(在Cython支持任何C++之前,这是必须的,如果使用了深奥的C++特性,即使它只是简单的声明一对类型的DEBDES,它仍然是有用的。在下面的代码中,它定义(和未定义和重新定义(!))宏,以应付否则非常冗长的代码,这可能是您的最佳选择。)您还可以执行强制转换[1](动态或其他)以在Cython不知道相关的类型之间进行转换 下面是一个代码示例,让您了解所涉及的层次结构编写C++;简化C+的包装器+;使用复杂的层次结构初始化,以便Cython可以调用它 我试图为C++计算拓扑库GUDHI()设计一个Cython包装器。GUDHI类将其他类作为其参数,这些类将其他子类传递给它们的方法。直接推到Cython就有点乱了。我在下面有一个代码示例,c++,python-3.x,wrapper,cython,C++,Python 3.x,Wrapper,Cython,我向Cython谷歌集团发布了一个问题,有人建议我用C++编写一个简化的包装器来隐藏Cython的这种复杂性。评论内容如下 P>一种选择,如果事情变得复杂,就是在C++中编写简化的包装器并调用这些包装器。(在Cython支持任何C++之前,这是必须的,如果使用了深奥的C++特性,即使它只是简单的声明一对类型的DEBDES,它仍然是有用的。在下面的代码中,它定义(和未定义和重新定义(!))宏,以应付否则非常冗长的代码,这可能是您的最佳选择。)您还可以执行强制转换[1](动态或其他)以在Cytho
typedef CGAL::Epick_d< CGAL::Dimension_tag<2> > Kernel;
--- needs to be passed into
Gudhi::alpha_complex::Alpha_complex<Kernel> alpha_complex_from_points(points, alpha_square_max_value);
Epick_d.h
--- Epick_d.h depends upon these libraries
#include <CGAL/NewKernel_d/Cartesian_base.h>
#include <CGAL/NewKernel_d/Cartesian_static_filters.h>
#include <CGAL/NewKernel_d/Cartesian_filter_K.h>
#include <CGAL/NewKernel_d/Wrapper/Cartesian_wrap.h>
#include <CGAL/NewKernel_d/Kernel_d_interface.h>
#include <CGAL/internal/Exact_type_selector.h>
#include <CGAL/Interval_nt.h>
--- Sample source code for Epick_d.h
namespace CGAL {
#define CGAL_BASE \
Cartesian_filter_K< Cartesian_base_d<double, Dim>, \
Cartesian_base_d<Interval_nt_advanced, Dim>, \
Cartesian_base_d<internal::Exact_field_selector<double>::Type, Dim> \
>
template<class Dim>
struct Epick_d_help1
: CGAL_BASE
{
CGAL_CONSTEXPR Epick_d_help1(){}
CGAL_CONSTEXPR Epick_d_help1(int d):CGAL_BASE(d){}
};
#undef CGAL_BASE
#define CGAL_BASE \
Cartesian_static_filters<Dim,Epick_d_help1<Dim>,Epick_d_help2<Dim> >
template<class Dim>
struct Epick_d_help2
: CGAL_BASE
{
CGAL_CONSTEXPR Epick_d_help2(){}
CGAL_CONSTEXPR Epick_d_help2(int d):CGAL_BASE(d){}
};
#undef CGAL_BASE
#define CGAL_BASE \
Kernel_d_interface< \
Cartesian_wrap< \
Epick_d_help2<Dim>, \
Epick_d<Dim> > >
template<class Dim>
struct Epick_d
: CGAL_BASE
{
CGAL_CONSTEXPR Epick_d(){}
CGAL_CONSTEXPR Epick_d(int d):CGAL_BASE(d){}
};
#undef CGAL_BASE
}
#endif
然后,我是否能够在不必传递所有类层次结构的情况下用cython包装这个类,因为我只传递一个指向函数的数组指针?这就是上次所做的。 包装类Alpha_complex_接口(不再模板化)包装Alpha_complex>以在每个维度中工作。 然后,类Alpha_complex_接口被循环化(参见Alpha_complex.pyx) 然后通过std::vector>&交换点。 如果您对我的操作方式有任何疑问,或者您需要其他接口,请不要犹豫
Class(*array)
constructor(*array)
loop:
take values from *array and create CGAL::Point_d
push new CGAL::Point_d to std::vector<CGAL::Point_d>
include all of the hierarchical class operations here.
method_1(std::vector)
include all of the hierarchical operations here, but
return the result as a simple array or struct.