Add files
This commit is contained in:
107
python/src/bertini_python.cpp
Normal file
107
python/src/bertini_python.cpp
Normal file
@@ -0,0 +1,107 @@
|
||||
//This file is part of Bertini 2.
|
||||
//
|
||||
//python/bertini_python.cpp is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//python/bertini_python.cpp is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with python/bertini_python.cpp. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright(C) 2016-2018 by Bertini2 Development Team
|
||||
//
|
||||
// See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
// as well as COPYING. Bertini2 is provided with permitted
|
||||
// additional terms in the b2/licenses/ directory.
|
||||
|
||||
// individual authors of this file include:
|
||||
//
|
||||
// James Collins
|
||||
// West Texas A&M University
|
||||
// Spring 2016
|
||||
//
|
||||
// silviana amethyst
|
||||
// UWEC
|
||||
// Spring 2018, Summer 2023
|
||||
//
|
||||
//
|
||||
// python/bertini_python.cpp: the main source file for the python interface for bertini.
|
||||
|
||||
|
||||
#include "bertini_python.hpp"
|
||||
|
||||
|
||||
namespace bertini
|
||||
{
|
||||
namespace python
|
||||
{
|
||||
|
||||
|
||||
|
||||
BOOST_PYTHON_MODULE(_pybertini) // this name must match the name of the generated .so file.
|
||||
{
|
||||
// see https://stackoverflow.com/questions/6114462/how-to-override-the-automatically-created-docstring-data-for-boostpython
|
||||
// docstring_options d(true, true, false); // local_
|
||||
docstring_options docopt;
|
||||
docopt.enable_all();
|
||||
docopt.disable_cpp_signatures();
|
||||
|
||||
object package = scope();
|
||||
package.attr("__path__") = "_pybertini";
|
||||
|
||||
// do this one first, so that the later calls into EigenPy work :)
|
||||
EnableEigenPy();
|
||||
|
||||
|
||||
ExportContainers();
|
||||
|
||||
ExportDetails();
|
||||
|
||||
ExportMpfr();
|
||||
|
||||
ExportRandom();
|
||||
|
||||
SetupFunctionTree();
|
||||
|
||||
{
|
||||
scope current_scope;
|
||||
|
||||
|
||||
std::string new_submodule_name(extract<const char*>(current_scope.attr("__name__")));
|
||||
new_submodule_name.append(".function_tree");
|
||||
object new_submodule(borrowed(PyImport_AddModule(new_submodule_name.c_str())));
|
||||
current_scope.attr("function_tree") = new_submodule;
|
||||
|
||||
|
||||
scope new_submodule_scope = new_submodule;
|
||||
new_submodule_scope.attr("__doc__") = "The symbolics for Bertini2. Operator overloads let you write arithmetic do form your system, after making variables, etc.";
|
||||
ExportNode();
|
||||
ExportSymbols();
|
||||
ExportOperators();
|
||||
ExportRoots();
|
||||
}
|
||||
|
||||
ExportAllSystems();
|
||||
|
||||
ExportParsers();
|
||||
|
||||
ExportTrackers();
|
||||
ExportTrackerObservers();
|
||||
|
||||
ExportEndgames();
|
||||
ExportEndgameObservers();
|
||||
|
||||
ExportLogging();
|
||||
|
||||
ExportZeroDim();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
150
python/src/containers.cpp
Normal file
150
python/src/containers.cpp
Normal file
@@ -0,0 +1,150 @@
|
||||
//This file is part of Bertini 2.
|
||||
//
|
||||
//python/src/containers.cpp is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//python/src/containers.cpp is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with python/src/containers.cpp. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright(C) 2017-2018 by Bertini2 Development Team
|
||||
//
|
||||
// See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
// as well as COPYING. Bertini2 is provided with permitted
|
||||
// additional terms in the b2/licenses/ directory.
|
||||
|
||||
// individual authors of this file include:
|
||||
//
|
||||
// James Collins
|
||||
// West Texas A&M University
|
||||
// Spring 2016
|
||||
//
|
||||
// silviana amethyst
|
||||
// UWEC
|
||||
// Spring 2018
|
||||
//
|
||||
//
|
||||
// python/src/containers.cpp: source file for exposing trackers to python.
|
||||
|
||||
|
||||
#include "containers_export.hpp"
|
||||
|
||||
namespace bertini{
|
||||
namespace python{
|
||||
|
||||
template<typename T>
|
||||
template<typename PyClass>
|
||||
void ListVisitor<T>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
|
||||
.def(vector_indexing_suite< T , true >())
|
||||
// By default indexed elements are returned by proxy. This can be
|
||||
// disabled by supplying *true* in the NoProxy template parameter.
|
||||
|
||||
.def("__str__", &ListVisitor::__str__)
|
||||
.def("__repr__", &ListVisitor::__repr__)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
void ExportContainers()
|
||||
{
|
||||
scope current_scope;
|
||||
std::string new_submodule_name(extract<const char*>(current_scope.attr("__name__")));
|
||||
new_submodule_name.append(".container");
|
||||
object new_submodule(borrowed(PyImport_AddModule(new_submodule_name.c_str())));
|
||||
current_scope.attr("container") = new_submodule;
|
||||
|
||||
scope new_submodule_scope = new_submodule;
|
||||
new_submodule_scope.attr("__doc__") = "Various container types for PyBertini";
|
||||
|
||||
|
||||
boost::python::converter::registry::push_back(&pylist_converter<bertini::VariableGroup>::convertible
|
||||
, &pylist_converter<bertini::VariableGroup>::construct
|
||||
, boost::python::type_id<bertini::VariableGroup>());
|
||||
|
||||
|
||||
|
||||
// std::vector of Rational Node ptrs
|
||||
using T1 = std::vector<std::shared_ptr< bertini::node::Rational > >;
|
||||
class_< T1 >("ListOfRational")
|
||||
.def(ListVisitor<T1>())
|
||||
;
|
||||
|
||||
// The VariableGroup vector container
|
||||
using T2 = bertini::VariableGroup;
|
||||
class_< T2 >("VariableGroup")
|
||||
.def(ListVisitor<T2>())
|
||||
.def("__init__", boost::python::make_constructor(&create_MyClass<T2>))
|
||||
;
|
||||
|
||||
// std::vector of ints
|
||||
using T3 = std::vector<int>;
|
||||
class_< T3 >("ListOfInt")
|
||||
.def(ListVisitor<T3>())
|
||||
;
|
||||
|
||||
|
||||
// std::vector of VariableGroups
|
||||
using T4 = std::vector<bertini::VariableGroup>;
|
||||
class_< T4 >("ListOfVariableGroup")
|
||||
.def(ListVisitor<T4>())
|
||||
;
|
||||
|
||||
|
||||
// std::vector of Function Node ptrs
|
||||
using T5 = std::vector<std::shared_ptr< bertini::node::Function > >;
|
||||
class_< T5 >("ListOfFunction")
|
||||
.def(ListVisitor<T5>())
|
||||
;
|
||||
|
||||
|
||||
// std::vector of Jacobian Node ptrs
|
||||
using T6 = std::vector<std::shared_ptr< bertini::node::Jacobian > >;
|
||||
class_< T6 >("ListOfJacobian")
|
||||
.def(ListVisitor<T6>())
|
||||
;
|
||||
|
||||
|
||||
// std::vector of Eigen::matrix
|
||||
using T7 = std::vector<bertini::Vec<dbl_complex>>;
|
||||
class_< T7 >("ListOfVectorComplexDoublePrecision")
|
||||
.def(ListVisitor<T7>())
|
||||
;
|
||||
|
||||
// std::vector of Eigen::matrix
|
||||
using T8 = std::vector<bertini::Vec<mpfr_complex>>;
|
||||
class_< T8 >("ListOfVectorComplexVariablePrecision")
|
||||
.def(ListVisitor<T8>())
|
||||
;
|
||||
|
||||
using T9 = std::vector<bertini::algorithm::SolutionMetaData<dbl_complex>>;
|
||||
class_< T9 >("ListOfSolutionMetaData_DoublePrec")
|
||||
.def(ListVisitor<T9>())
|
||||
;
|
||||
|
||||
using T10 = std::vector<bertini::algorithm::SolutionMetaData<mpfr_complex>>;
|
||||
class_< T10 >("ListOfSolutionMetaData_MultiPrec")
|
||||
.def(ListVisitor<T10>())
|
||||
;
|
||||
|
||||
using T11 = std::vector<bertini::algorithm::EGBoundaryMetaData<dbl_complex>>;
|
||||
class_< T11 >("ListOfEGBoundaryMetaData_DoublePrec")
|
||||
.def(ListVisitor<T11>())
|
||||
;
|
||||
|
||||
using T12 = std::vector<bertini::algorithm::EGBoundaryMetaData<mpfr_complex>>;
|
||||
class_< T12 >("ListOfEGBoundaryMetaData_MultiPrec")
|
||||
.def(ListVisitor<T12>())
|
||||
;
|
||||
}; // export containers
|
||||
|
||||
}
|
||||
}
|
||||
51
python/src/detail.cpp
Normal file
51
python/src/detail.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
//This file is part of Bertini 2.
|
||||
//
|
||||
//python/generic_observers.cpp is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//python/generic_observers.cpp is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with python/generic_observers.cpp. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright(C) 2017-2018 by Bertini2 Development Team
|
||||
//
|
||||
// See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
// as well as COPYING. Bertini2 is provided with permitted
|
||||
// additional terms in the b2/licenses/ directory.
|
||||
|
||||
// individual authors of this file include:
|
||||
//
|
||||
// silviana amethyst
|
||||
// UWEC
|
||||
// Fall 2017, Spring 2018
|
||||
//
|
||||
//
|
||||
// python/generic_observers.cpp: source file for exposing trackers to python.
|
||||
|
||||
|
||||
#include "detail.hpp"
|
||||
|
||||
namespace bertini{
|
||||
namespace python{
|
||||
|
||||
void ExportDetails()
|
||||
{
|
||||
scope current_scope;
|
||||
std::string new_submodule_name(extract<const char*>(current_scope.attr("__name__")));
|
||||
new_submodule_name.append(".detail");
|
||||
object new_submodule(borrowed(PyImport_AddModule(new_submodule_name.c_str())));
|
||||
current_scope.attr("detail") = new_submodule;
|
||||
|
||||
scope new_submodule_scope = new_submodule;
|
||||
new_submodule_scope.attr("__doc__") = "Hidden things. Keep them secret. Keep them safe...";
|
||||
|
||||
ExportObserver();
|
||||
}
|
||||
}
|
||||
}
|
||||
50
python/src/eigenpy_interaction.cpp
Normal file
50
python/src/eigenpy_interaction.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
//This file is part of Bertini 2.
|
||||
//
|
||||
//python/eigenpy_interaction.cpp is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//python/eigenpy_interaction.cpp is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with python/eigenpy_interaction.cpp. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright(C) 2016-2023 by Bertini2 Development Team
|
||||
//
|
||||
// See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
// as well as COPYING. Bertini2 is provided with permitted
|
||||
// additional terms in the b2/licenses/ directory.
|
||||
|
||||
// individual authors of this file include:
|
||||
//
|
||||
// silviana amethyst
|
||||
// University of Wisconsin Eau Claire
|
||||
// 2023
|
||||
//
|
||||
//
|
||||
// python/eigenpy_interaction.cpp: source file for exposing things to python via EigenPy.
|
||||
|
||||
#include "eigenpy_interaction.hpp"
|
||||
|
||||
|
||||
|
||||
namespace bertini{
|
||||
namespace python{
|
||||
|
||||
|
||||
|
||||
|
||||
void EnableEigenPy(){
|
||||
eigenpy::enableEigenPy();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}} // namespaces
|
||||
252
python/src/endgame_export.cpp
Normal file
252
python/src/endgame_export.cpp
Normal file
@@ -0,0 +1,252 @@
|
||||
//This file is part of Bertini 2.
|
||||
//
|
||||
//python/endgame_export.cpp is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//python/endgame_export.cpp is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with python/endgame_export.cpp. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright(C) 2016-2018 by Bertini2 Development Team
|
||||
//
|
||||
// See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
// as well as COPYING. Bertini2 is provided with permitted
|
||||
// additional terms in the b2/licenses/ directory.
|
||||
|
||||
// individual authors of this file include:
|
||||
//
|
||||
// silviana amethyst
|
||||
// University of Notre Dame, University of Wisconsin Eau Claire
|
||||
// Summer 2016, Fall 2017
|
||||
//
|
||||
//
|
||||
// python/endgame_export.cpp: source file for exposing endgames to python.
|
||||
|
||||
#include "endgame_export.hpp"
|
||||
#include "generic_observable.hpp"
|
||||
|
||||
|
||||
namespace bertini{
|
||||
namespace python{
|
||||
|
||||
|
||||
template<typename EndgameT>
|
||||
template<class PyClass>
|
||||
void EndgameBaseVisitor<EndgameT>::visit(PyClass& cl) const
|
||||
{
|
||||
using TrackerT = typename EndgameT::TrackerType;
|
||||
using BCT = typename TrackerTraits<TrackerT>::BaseComplexType;
|
||||
using BRT = typename TrackerTraits<TrackerT>::BaseRealType;
|
||||
|
||||
cl
|
||||
.def("cycle_number", this->GetCycleNumberFn(),"Get the cycle number as currently computed")
|
||||
|
||||
.def("get_endgame_settings",&EndgameT::EndgameSettings,return_internal_reference<>(),"Get the current non-specific endgame settings")
|
||||
.def("get_security_settings",&EndgameT::SecuritySettings,return_internal_reference<>(),"Get the 'security' settings for the endgame (path truncation near infinity)")
|
||||
|
||||
.def("set_endgame_settings",&EndgameT::template Set<endgame::EndgameConfig>,"Set the values of non-specific endgame settings")
|
||||
.def("set_security_settings",&EndgameT::template Set<endgame::SecurityConfig>,"Set the values of security-level settings")
|
||||
|
||||
.def("get_tracker", &EndgameT::GetTracker, return_internal_reference<>(),"Get the tracker used in this endgame. This is the same tracker as you feed the endgame object when you make it. This is a reference variable")
|
||||
.def("get_system", &EndgameT::GetSystem, return_internal_reference<>(),"Get the tracked system. This is a reference to the internal system.")
|
||||
|
||||
// .def("final_approximation", &EndgameT::template FinalApproximation<BCT>, return_internal_reference<>(),)
|
||||
.def("final_approximation", &return_final_approximation<BCT>,"Get the current approximation of the root, in the ambient numeric type for the tracker being used")
|
||||
|
||||
.def("run", &EndgameBaseVisitor::WrapRunDefaultTime,
|
||||
(boost::python::arg("start_time"), "start_point"),
|
||||
"Run the endgame, from start point and start time, to t=0. Expects complex numeric type matching that of the tracker being used.")
|
||||
.def("run", &EndgameBaseVisitor::WrapRunCustomTime,
|
||||
(boost::python::arg("start_time"), "start_point", "target_time"),
|
||||
"Run the endgame, from start point and start time, to your choice of target time t. Expects complex numeric type matching that of the tracker being used.")
|
||||
|
||||
.def(ObservableVisitor<EndgameT>())
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
template<typename EndgameT>
|
||||
template<class PyClass>
|
||||
void CauchyVisitor<EndgameT>::visit(PyClass& cl) const
|
||||
{
|
||||
using TrackerT = typename EndgameT::TrackerType;
|
||||
|
||||
cl
|
||||
.def(init<TrackerT const&, endgame::CauchyConfig const&>())
|
||||
.def(init<TrackerT const&, endgame::EndgameConfig const&>())
|
||||
.def(init<TrackerT const&, endgame::SecurityConfig const&>());
|
||||
|
||||
}
|
||||
|
||||
|
||||
template<typename EndgameT>
|
||||
template<class PyClass>
|
||||
void PowerSeriesVisitor<EndgameT>::visit(PyClass& cl) const
|
||||
{
|
||||
using TrackerT = typename EndgameT::TrackerType;
|
||||
|
||||
cl
|
||||
.def(init<TrackerT const&, endgame::PowerSeriesConfig const&>())
|
||||
.def(init<TrackerT const&, endgame::EndgameConfig const&>())
|
||||
.def(init<TrackerT const&, endgame::SecurityConfig const&>());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ExportEndgameSettings()
|
||||
{
|
||||
scope current_scope;
|
||||
std::string new_submodule_name(extract<const char*>(current_scope.attr("__name__")));
|
||||
new_submodule_name.append(".config");
|
||||
object new_submodule(borrowed(PyImport_AddModule(new_submodule_name.c_str())));
|
||||
current_scope.attr("config") = new_submodule;
|
||||
|
||||
|
||||
scope new_submodule_scope = new_submodule;
|
||||
new_submodule_scope.attr("__doc__") = "Endgame configuration structs.";
|
||||
|
||||
class_<endgame::EndgameConfig>("Endgame","Generic endgame settings. Number of sample points, etc. Note that some of its configs are rational numbers",init<>())
|
||||
.def_readwrite("sample_point_refinement_factor", &endgame::EndgameConfig::sample_point_refinement_factor, "Extra amount of tolerance for refining before computing the final approximation, during endgame.")
|
||||
.def_readwrite("num_sample_points", &endgame::EndgameConfig::num_sample_points,"The number of points to use for extrapolant calculation. In the Power Series Endgame, the is the number of geometrically spaces points on the path. For Cauchy, this is the number of points on each circle tracked around the target time value.")
|
||||
.def_readwrite("min_track_time", &endgame::EndgameConfig::min_track_time,"The minimum distance from the target time to track to. Decreasing this may help failing runs succeed, or maybe not, because you are, after all, tracking toward a singularity.")
|
||||
.def_readwrite("sample_factor", &endgame::EndgameConfig::sample_factor,"The factor by which to space the geometrically spaced `distance' between sample points, or sample circles for Cauchy.")
|
||||
.def_readwrite("max_num_newton_iterations", &endgame::EndgameConfig::max_num_newton_iterations,"the maximum number of newton iterations to be taken during sample point sharpening. Increasing this can help speed convergence, at the risk of path jumping.")
|
||||
.def_readwrite("final_tolerance", &endgame::EndgameConfig::final_tolerance, "The tolerance to which to track the path, using the endgame. Endgames require two consecutive estimates to be this close to each other under the relative infinity norm. Default value is 1e-11.")
|
||||
;
|
||||
|
||||
|
||||
class_<endgame::SecurityConfig>("Security","Security settings for endgames. Control things like truncation because estimated root is near infinity",init<>())
|
||||
.def_readwrite("level", &endgame::SecurityConfig::level,"Turns on or off truncation of paths going to infinity during the endgame. 0 is off, 1 is on.")
|
||||
.def_readwrite("max_norm", &endgame::SecurityConfig::max_norm,"If on, the norm at which to truncate a path.")
|
||||
;
|
||||
|
||||
class_<endgame::PowerSeriesConfig>("PowerSeriesConfig","Settings specific to the power series endgame for computing singular endpoints",init<>())
|
||||
.def_readwrite("max_cycle_number", &endgame::PowerSeriesConfig::max_cycle_number,"The maximum cycle number to consider, when calculating the cycle number which best fits the path being tracked.")
|
||||
.def_readwrite("cycle_number_amplification", &endgame::PowerSeriesConfig::cycle_number_amplification,"The maximum number allowable iterations during endgames, for points used to approximate the final solution.")
|
||||
;
|
||||
|
||||
|
||||
class_<endgame::CauchyConfig>("CauchyConfig","Settings specific to the Cauchy endgame for computing singular endpoints",init<>())
|
||||
.def_readwrite("cycle_cutoff_time", &endgame::CauchyConfig::cycle_cutoff_time)
|
||||
.def_readwrite("ratio_cutoff_time", &endgame::CauchyConfig::ratio_cutoff_time)
|
||||
.def_readwrite("minimum_for_c_over_k_stabilization", &endgame::CauchyConfig::minimum_for_c_over_k_stabilization)
|
||||
.def_readwrite("maximum_cauchy_ratio", &endgame::CauchyConfig::maximum_cauchy_ratio)
|
||||
.def_readwrite("num_needed_for_stabilization", &endgame::CauchyConfig::num_needed_for_stabilization,"When running stabilization testing for the cycle number when entering the endgame, this is the number of consecutive points for which the test must pass.")
|
||||
.def_readwrite("fail_safe_maximum_cycle_number", &endgame::CauchyConfig::fail_safe_maximum_cycle_number, "max number of loops before giving up." )
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
void ExportEndgames()
|
||||
{
|
||||
scope current_scope;
|
||||
std::string new_submodule_name(extract<const char*>(current_scope.attr("__name__")));
|
||||
new_submodule_name.append(".endgame");
|
||||
object new_submodule(borrowed(PyImport_AddModule(new_submodule_name.c_str())));
|
||||
current_scope.attr("endgame") = new_submodule;
|
||||
|
||||
|
||||
scope new_submodule_scope = new_submodule;
|
||||
new_submodule_scope.attr("__doc__") = "Endgames and associated types and functions. For tracking around singularities.";
|
||||
|
||||
ExportEndgameSettings();
|
||||
|
||||
ExportAMPPSEG();
|
||||
ExportFDPSEG();
|
||||
ExportFMPSEG();
|
||||
|
||||
ExportAMPCauchyEG();
|
||||
ExportFDCauchyEG();
|
||||
ExportFMCauchyEG();
|
||||
}
|
||||
|
||||
void ExportAMPPSEG()
|
||||
{
|
||||
using TrackerT = AMPTracker;
|
||||
using EGT = typename endgame::EndgameSelector<TrackerT>::PSEG;
|
||||
|
||||
class_<EGT>("AMPPSEG",
|
||||
"The adaptive precision implementation of the power series endgame.",
|
||||
init<TrackerT const&>())
|
||||
.def(EndgameBaseVisitor<EGT>())
|
||||
.def(PowerSeriesVisitor<EGT>());
|
||||
}
|
||||
|
||||
|
||||
void ExportFMPSEG()
|
||||
{
|
||||
using TrackerT = MultiplePrecisionTracker;
|
||||
using EGT = typename endgame::EndgameSelector<TrackerT>::PSEG;
|
||||
|
||||
class_<EGT>("FixedMultiplePSEG",
|
||||
"The fixed but arbitrary precision implementation of the power series endgame",
|
||||
init<TrackerT const&>())
|
||||
.def(EndgameBaseVisitor<EGT>())
|
||||
.def(PowerSeriesVisitor<EGT>());
|
||||
}
|
||||
|
||||
|
||||
void ExportFDPSEG()
|
||||
{
|
||||
using TrackerT = DoublePrecisionTracker;
|
||||
using EGT = typename endgame::EndgameSelector<TrackerT>::PSEG;
|
||||
|
||||
class_<EGT>("FixedDoublePSEG",
|
||||
"The double-precision implementation of the power series endgame",
|
||||
init<TrackerT const&>())
|
||||
.def(EndgameBaseVisitor<EGT>())
|
||||
.def(PowerSeriesVisitor<EGT>());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void ExportFDCauchyEG()
|
||||
{
|
||||
using TrackerT = DoublePrecisionTracker;
|
||||
using EGT = typename endgame::EndgameSelector<TrackerT>::Cauchy;
|
||||
|
||||
class_<EGT>("FixedDoubleCauchyEG",
|
||||
"The fixed double precision implementation of the Cauchy endgame",
|
||||
init<TrackerT const&>())
|
||||
.def(EndgameBaseVisitor<EGT>())
|
||||
.def(CauchyVisitor<EGT>())
|
||||
;
|
||||
}
|
||||
|
||||
void ExportFMCauchyEG()
|
||||
{
|
||||
using TrackerT = MultiplePrecisionTracker;
|
||||
using EGT = typename endgame::EndgameSelector<TrackerT>::Cauchy;
|
||||
|
||||
class_<EGT>("FixedMultipleCauchyEG",
|
||||
"The fixed multiple precision implementation of the Cauchy endgame",
|
||||
init<TrackerT const&>())
|
||||
.def(EndgameBaseVisitor<EGT>())
|
||||
.def(CauchyVisitor<EGT>())
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
void ExportAMPCauchyEG()
|
||||
{
|
||||
using TrackerT = AMPTracker;
|
||||
using EGT = typename endgame::EndgameSelector<TrackerT>::Cauchy;
|
||||
|
||||
class_<EGT>("AMPCauchyEG",
|
||||
"The adaptive precision implementation of the Cauchy endgame",
|
||||
init<TrackerT const&>())
|
||||
.def(EndgameBaseVisitor<EGT>())
|
||||
.def(CauchyVisitor<EGT>())
|
||||
;
|
||||
}
|
||||
|
||||
}} // re: namespaces
|
||||
94
python/src/endgame_observers.cpp
Normal file
94
python/src/endgame_observers.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
//This file is part of Bertini 2.
|
||||
//
|
||||
//python/endgame_observers.cpp is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//python/endgame_observers.cpp is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with python/endgame_observers.cpp. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright(C) 2017-2018 by Bertini2 Development Team
|
||||
//
|
||||
// See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
// as well as COPYING. Bertini2 is provided with permitted
|
||||
// additional terms in the b2/licenses/ directory.
|
||||
|
||||
// individual authors of this file include:
|
||||
//
|
||||
// silviana amethyst
|
||||
// UWEC
|
||||
// Spring 2018
|
||||
//
|
||||
//
|
||||
//
|
||||
// python/endgame_observers.cpp: source file for exposing endgames to python.
|
||||
|
||||
|
||||
#include "endgame_observers.hpp"
|
||||
#include "generic_observer.hpp"
|
||||
|
||||
namespace bertini{
|
||||
namespace python{
|
||||
|
||||
|
||||
|
||||
|
||||
template <typename EndgameT>
|
||||
void ExportSpecificObservers(std::string scope_name)
|
||||
{
|
||||
scope scope_C;
|
||||
std::string submodule_name_C(extract<const char*>(scope_C.attr("__name__")));
|
||||
submodule_name_C.append("." + scope_name);
|
||||
object submodule_C(borrowed(PyImport_AddModule(submodule_name_C.c_str())));
|
||||
scope_C.attr(scope_name.c_str()) = submodule_C;
|
||||
scope new_submodule_scope_C = submodule_C;
|
||||
|
||||
class_<ObserverWrapper<Observer<EndgameT>>, bases<AnyObserver>, boost::noncopyable>("Abstract", init< >())
|
||||
;
|
||||
|
||||
class_<GoryDetailLogger<EndgameT>, bases<Observer<EndgameT>> >("GoryDetailLogger", init< >())
|
||||
.def(EndgameObserverVisitor<GoryDetailLogger<EndgameT>>())
|
||||
;
|
||||
}
|
||||
|
||||
void ExportEndgameObservers()
|
||||
{
|
||||
|
||||
scope current_scope;
|
||||
std::string new_submodule_name(extract<const char*>(current_scope.attr("__name__")));
|
||||
new_submodule_name.append(".endgame");
|
||||
object new_submodule(borrowed(PyImport_AddModule(new_submodule_name.c_str())));
|
||||
current_scope.attr("endgame") = new_submodule;
|
||||
|
||||
scope new_submodule_scope = new_submodule;
|
||||
|
||||
|
||||
{
|
||||
scope scope_B;
|
||||
std::string submodule_name_B(extract<const char*>(scope_B.attr("__name__")));
|
||||
submodule_name_B.append(".observers");
|
||||
object submodule_B(borrowed(PyImport_AddModule(submodule_name_B.c_str())));
|
||||
scope_B.attr("observers") = submodule_B;
|
||||
scope new_submodule_scope_B = submodule_B;
|
||||
new_submodule_scope_B.attr("__doc__") = "Endgame observers. Make one, and then attach it to an endgame to observe it. See endgame functions `add_observer` and `remove_observer`";
|
||||
|
||||
ExportSpecificObservers<endgame::EndgameSelector<AMPTracker>::Cauchy>("amp_cauchy");
|
||||
ExportSpecificObservers<endgame::EndgameSelector<AMPTracker>::PSEG>("amp_pseg");
|
||||
|
||||
ExportSpecificObservers<endgame::EndgameSelector<DoublePrecisionTracker>::Cauchy>("double_cauchy");
|
||||
ExportSpecificObservers<endgame::EndgameSelector<DoublePrecisionTracker>::PSEG>("double_pseg");
|
||||
|
||||
ExportSpecificObservers<endgame::EndgameSelector<MultiplePrecisionTracker>::Cauchy>("multiple_cauchy");
|
||||
ExportSpecificObservers<endgame::EndgameSelector<MultiplePrecisionTracker>::PSEG>("multiple_pseg");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}} // namespaces
|
||||
90
python/src/function_tree.cpp
Normal file
90
python/src/function_tree.cpp
Normal file
@@ -0,0 +1,90 @@
|
||||
//This file is part of Bertini 2.
|
||||
//
|
||||
//python/function_tree.cpp is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//python/function_tree.cpp is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with python/function_tree.cpp. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright(C) 2016-2018 by Bertini2 Development Team
|
||||
//
|
||||
// See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
// as well as COPYING. Bertini2 is provided with permitted
|
||||
// additional terms in the b2/licenses/ directory.
|
||||
|
||||
// individual authors of this file include:
|
||||
//
|
||||
// James Collins
|
||||
// West Texas A&M University
|
||||
// Spring 2016
|
||||
//
|
||||
// silviana amethyst
|
||||
// UWEC
|
||||
// Spring 2018
|
||||
//
|
||||
|
||||
#include "function_tree.hpp"
|
||||
|
||||
using namespace boost::python;
|
||||
|
||||
using dbl = std::complex<double>;
|
||||
using mpfr = bertini::complex;
|
||||
|
||||
// BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(NodeEvalOverloadsMpfr, bertini::node::Node::template Eval<mpfr>, 0, 1);
|
||||
//BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(SumAddChildOverloads, bertini::node::SumOperator::AddChild, 1, 2);
|
||||
//BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(MultAddChildOverloads, bertini::node::MultOperator::AddChild, 1, 2);
|
||||
|
||||
|
||||
|
||||
namespace bertini{
|
||||
namespace python{
|
||||
using Nodeptr = std::shared_ptr<node::Node>;
|
||||
|
||||
|
||||
void SetupFunctionTree()
|
||||
{
|
||||
// Tell Python that pointers to derived Nodes can be used as Node pointers
|
||||
implicitly_convertible<std::shared_ptr<node::Float>, Nodeptr>();
|
||||
implicitly_convertible<std::shared_ptr<node::special_number::Pi>, Nodeptr>();
|
||||
implicitly_convertible<std::shared_ptr<node::special_number::E>, Nodeptr>();
|
||||
implicitly_convertible<std::shared_ptr<node::Variable>, Nodeptr>();
|
||||
implicitly_convertible<std::shared_ptr<node::Differential>, Nodeptr>();
|
||||
|
||||
implicitly_convertible<std::shared_ptr<node::SumOperator>, Nodeptr>();
|
||||
implicitly_convertible<std::shared_ptr<node::MultOperator>, Nodeptr>();
|
||||
implicitly_convertible<std::shared_ptr<node::PowerOperator>, Nodeptr>();
|
||||
implicitly_convertible<std::shared_ptr<node::NegateOperator>, Nodeptr>();
|
||||
implicitly_convertible<std::shared_ptr<node::IntegerPowerOperator>, Nodeptr>();
|
||||
implicitly_convertible<std::shared_ptr<node::SqrtOperator>, Nodeptr>();
|
||||
implicitly_convertible<std::shared_ptr<node::ExpOperator>, Nodeptr>();
|
||||
implicitly_convertible<std::shared_ptr<node::LogOperator>, Nodeptr>();
|
||||
implicitly_convertible<std::shared_ptr<node::TrigOperator>, Nodeptr>();
|
||||
implicitly_convertible<std::shared_ptr<node::SinOperator>, Nodeptr>();
|
||||
implicitly_convertible<std::shared_ptr<node::CosOperator>, Nodeptr>();
|
||||
implicitly_convertible<std::shared_ptr<node::TanOperator>, Nodeptr>();
|
||||
implicitly_convertible<std::shared_ptr<node::ArcSinOperator>, Nodeptr>();
|
||||
implicitly_convertible<std::shared_ptr<node::ArcCosOperator>, Nodeptr>();
|
||||
implicitly_convertible<std::shared_ptr<node::ArcTanOperator>, Nodeptr>();
|
||||
|
||||
implicitly_convertible<std::shared_ptr<node::Function>, Nodeptr>();
|
||||
implicitly_convertible<std::shared_ptr<node::Jacobian>, Nodeptr>();
|
||||
|
||||
|
||||
|
||||
// Expose the deque containers
|
||||
class_< std::deque< std::shared_ptr< node::Variable > > >("VariableGroup")
|
||||
.def(vector_indexing_suite< std::deque< std::shared_ptr< node::Variable > >, true >())
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
45
python/src/generic_observable.cpp
Normal file
45
python/src/generic_observable.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
//This file is part of Bertini 2.
|
||||
//
|
||||
//python/generic_observable.cpp is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//python/generic_observable.cpp is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with python/generic_observable.cpp. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright(C) 2018 by Bertini2 Development Team
|
||||
//
|
||||
// See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
// as well as COPYING. Bertini2 is provided with permitted
|
||||
// additional terms in the b2/licenses/ directory.
|
||||
|
||||
// individual authors of this file include:
|
||||
//
|
||||
// silviana amethyst
|
||||
// UWEC
|
||||
// Spring 2018
|
||||
//
|
||||
//
|
||||
// python/generic_observable.cpp: source file for exposing trackers to python.
|
||||
|
||||
|
||||
#include "generic_observable.hpp"
|
||||
|
||||
namespace bertini{
|
||||
namespace python{
|
||||
|
||||
|
||||
// template <typename T>
|
||||
// template <class PyClass>
|
||||
// void ObservableVisitor<T>::visit(PyClass& cl) const
|
||||
// {
|
||||
|
||||
// }
|
||||
|
||||
}} // namespaces
|
||||
44
python/src/generic_observer.cpp
Normal file
44
python/src/generic_observer.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
//This file is part of Bertini 2.
|
||||
//
|
||||
//python/generic_observers.cpp is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//python/generic_observers.cpp is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with python/generic_observers.cpp. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright(C) 2017-2018 by Bertini2 Development Team
|
||||
//
|
||||
// See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
// as well as COPYING. Bertini2 is provided with permitted
|
||||
// additional terms in the b2/licenses/ directory.
|
||||
|
||||
// individual authors of this file include:
|
||||
//
|
||||
// silviana amethyst
|
||||
// UWEC
|
||||
// Fall 2017, Spring 2018
|
||||
//
|
||||
//
|
||||
// python/generic_observers.cpp: source file for exposing trackers to python.
|
||||
|
||||
|
||||
#include "generic_observer.hpp"
|
||||
|
||||
namespace bertini{
|
||||
namespace python{
|
||||
|
||||
|
||||
void ExportObserver()
|
||||
{
|
||||
class_<ObserverWrapper<AnyObserver>, boost::noncopyable>("AnyAbstractObserver", init< >())
|
||||
;
|
||||
}
|
||||
|
||||
}} // namespaces
|
||||
79
python/src/logging.cpp
Normal file
79
python/src/logging.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
|
||||
//This file is part of Bertini 2.
|
||||
//
|
||||
//python/src/logging.cpp is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//python/src/logging.cpp is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with python/src/logging.cpp. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright(C) 2018 by Bertini2 Development Team
|
||||
//
|
||||
// See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
// as well as COPYING. Bertini2 is provided with permitted
|
||||
// additional terms in the b2/licenses/ directory.
|
||||
|
||||
// individual authors of this file include"
|
||||
//
|
||||
// silviana amethyst
|
||||
// UWEC
|
||||
// Spring 2018
|
||||
//
|
||||
//
|
||||
// python/src/logging.cpp: source file for exposing logging to python.
|
||||
|
||||
|
||||
#include "logging.hpp"
|
||||
|
||||
namespace bertini{ namespace python{
|
||||
|
||||
void ExportSeverityLevels()
|
||||
{
|
||||
enum_<logging::severity_level>("severity_level")
|
||||
.value("Debug", logging::severity_level::debug)
|
||||
.value("Trace", logging::severity_level::trace)
|
||||
.value("Info", logging::severity_level::info)
|
||||
.value("Warning", logging::severity_level::warning)
|
||||
.value("Error", logging::severity_level::error)
|
||||
.value("Fatal", logging::severity_level::fatal)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
void ExportLogging()
|
||||
{
|
||||
scope current_scope;
|
||||
std::string new_submodule_name(extract<const char*>(current_scope.attr("__name__")));
|
||||
new_submodule_name.append(".logging");
|
||||
object new_submodule(borrowed(PyImport_AddModule(new_submodule_name.c_str())));
|
||||
current_scope.attr("logging") = new_submodule;
|
||||
|
||||
scope new_submodule_scope = new_submodule;
|
||||
|
||||
|
||||
ExportSeverityLevels();
|
||||
|
||||
|
||||
def("init", &bertini::logging::Logging::Init,
|
||||
(boost::python::arg("pattern") = "pybertini_%N.log", boost::python::arg("format") = "%Message%", boost::python::arg("rotation_size") = 10*1024*1024, boost::python::arg("level") = logging::severity_level::info), "Initialize logging. See set_level and add_file.");
|
||||
|
||||
def("set_level", &bertini::logging::Logging::SetLevel, (boost::python::arg("level")), "Set the threshold severity level. Events with lower-than-this level will be ignored. All messages are written to files. Writing to strings back into Python is not currently enabled. If this is a problem, please file an issue on GitHub at github.com/bertiniteam/b2/issues . YAGNI");
|
||||
|
||||
def("add_file", &bertini::logging::Logging::AddFile,
|
||||
((boost::python::arg("pattern")), boost::python::arg("format"), boost::python::arg("rotation_size")),
|
||||
"Add a file-name pattern to be written to, with a given formatting, and a threshold rotation size. See Boost.Log for more information on these strings. This part of PyBertini is a direct shunt to Boost.Log.");
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}} // namespaces
|
||||
519
python/src/mpfr_export.cpp
Normal file
519
python/src/mpfr_export.cpp
Normal file
@@ -0,0 +1,519 @@
|
||||
//This file is part of Bertini 2.
|
||||
//
|
||||
//python/mpfr_export.cpp is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//python/mpfr_export.cpp is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with python/mpfr_export.cpp. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright(C) 2016-2018 by Bertini2 Development Team
|
||||
//
|
||||
// See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
// as well as COPYING. Bertini2 is provided with permitted
|
||||
// additional terms in the b2/licenses/ directory.
|
||||
|
||||
// individual authors of this file include:
|
||||
//
|
||||
// silviana amethyst
|
||||
// University of Wisconsin - Eau Claire
|
||||
// Fall 2017, Spring 2018
|
||||
//
|
||||
// James Collins
|
||||
// West Texas A&M University
|
||||
// Spring 2016
|
||||
//
|
||||
//
|
||||
//
|
||||
// python/mpfr_export.cpp: Source file for exposing all multiprecision data types, those from boost and bertini::complex.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include "mpfr_export.hpp"
|
||||
|
||||
|
||||
|
||||
namespace bertini{
|
||||
namespace python{
|
||||
|
||||
template<typename T>
|
||||
template<typename PyClass>
|
||||
void PrecisionVisitor<T>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
.def("precision", get_prec)
|
||||
.def("precision", set_prec)
|
||||
;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename PyClass>
|
||||
void RealStrVisitor<T>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
.def("__str__", &RealStrVisitor::__str__)
|
||||
.def("__repr__", &RealStrVisitor::__repr__)
|
||||
;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename PyClass>
|
||||
void EqualitySelfVisitor<T>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
.def(self == self)
|
||||
.def(self != self)
|
||||
;
|
||||
}
|
||||
|
||||
template<typename T, typename S>
|
||||
template<typename PyClass>
|
||||
void EqualityVisitor<T,S>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
.def(self == other<S>())
|
||||
.def(self != other<S>())
|
||||
|
||||
.def(other<S>() == self)
|
||||
.def(other<S>() != self)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
template<typename T, typename S>
|
||||
template<typename PyClass>
|
||||
void RingVisitor<T,S>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
.def("__add__",&RingVisitor::__add__)
|
||||
.def("__iadd__",&RingVisitor::__iadd__)
|
||||
.def("__radd__",&RingVisitor::__radd__)
|
||||
|
||||
.def("__sub__",&RingVisitor::__sub__)
|
||||
.def("__isub__",&RingVisitor::__isub__)
|
||||
.def("__rsub__",&RingVisitor::__rsub__)
|
||||
|
||||
.def("__mul__",&RingVisitor::__mul__)
|
||||
.def("__imul__",&RingVisitor::__imul__)
|
||||
.def("__rmul__",&RingVisitor::__rmul__)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
template<typename PyClass>
|
||||
void RingSelfVisitor<T>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
|
||||
.def("__add__",&RingSelfVisitor::__add__)
|
||||
.def("__iadd__",&RingSelfVisitor::__iadd__)
|
||||
|
||||
.def("__sub__",&RingSelfVisitor::__sub__)
|
||||
.def("__isub__",&RingSelfVisitor::__isub__)
|
||||
|
||||
.def("__mul__",&RingSelfVisitor::__mul__)
|
||||
.def("__imul__",&RingSelfVisitor::__imul__)
|
||||
|
||||
.def("__neg__",&RingSelfVisitor::__neg__)
|
||||
;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
template<typename PyClass>
|
||||
void RealFreeVisitor<T>::visit(PyClass& cl) const
|
||||
{
|
||||
def("abs", &RealFreeVisitor::__abs__); // free
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename T, typename S>
|
||||
template<typename PyClass>
|
||||
void FieldVisitor<T,S>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
.def("__div__",&FieldVisitor::__div__)
|
||||
.def("__idiv__",&FieldVisitor::__idiv__)
|
||||
.def("__rdiv__",&FieldVisitor::__rdiv__)
|
||||
|
||||
.def("__truediv__",&FieldVisitor::__div__)
|
||||
.def("__itruediv__",&FieldVisitor::__idiv__)
|
||||
.def("__rtruediv__",&FieldVisitor::__rdiv__)
|
||||
.def(RingVisitor<T,S>())
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
template<typename PyClass>
|
||||
void FieldSelfVisitor<T>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
.def("__div__",&FieldSelfVisitor::div)
|
||||
.def("__idiv__",&FieldSelfVisitor::idiv)
|
||||
|
||||
.def("__truediv__",&FieldSelfVisitor::div)
|
||||
.def("__itruediv__",&FieldSelfVisitor::idiv)
|
||||
|
||||
.def(RingSelfVisitor<T>())
|
||||
;
|
||||
}
|
||||
|
||||
template<typename T, typename S>
|
||||
template<typename PyClass>
|
||||
void PowVisitor<T,S>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
.def("__pow__",&PowVisitor::__pow__)
|
||||
;
|
||||
}
|
||||
|
||||
template<typename T, typename S>
|
||||
template<typename PyClass>
|
||||
void GreatLessVisitor<T,S>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
.def(self < other<S>())
|
||||
.def(self <= other<S>())
|
||||
.def(self > other<S>())
|
||||
.def(self >= other<S>())
|
||||
|
||||
.def(other<S>() < self)
|
||||
.def(other<S>() <= self)
|
||||
.def(other<S>() > self)
|
||||
.def(other<S>() >= self)
|
||||
;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename PyClass>
|
||||
void GreatLessSelfVisitor<T>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
.def(self < self)
|
||||
.def(self <= self)
|
||||
.def(self > self)
|
||||
.def(self >= self)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
template<typename PyClass>
|
||||
void TranscendentalVisitor<T>::visit(PyClass& cl) const
|
||||
{
|
||||
def("exp", &TranscendentalVisitor::__exp__);
|
||||
def("log", &TranscendentalVisitor::__log__);
|
||||
def("sqrt", &TranscendentalVisitor::__sqrt__);
|
||||
|
||||
def("sin", &TranscendentalVisitor::__sin__);
|
||||
def("cos", &TranscendentalVisitor::__cos__);
|
||||
def("tan", &TranscendentalVisitor::__tan__);
|
||||
|
||||
def("asin", &TranscendentalVisitor::__asin__);
|
||||
def("acos", &TranscendentalVisitor::__acos__);
|
||||
def("atan", &TranscendentalVisitor::__atan__);
|
||||
|
||||
def("sinh", &TranscendentalVisitor::__sinh__);
|
||||
def("cosh", &TranscendentalVisitor::__cosh__);
|
||||
def("tanh", &TranscendentalVisitor::__tanh__);
|
||||
|
||||
def("asinh",&TranscendentalVisitor::__asinh__);
|
||||
def("acosh",&TranscendentalVisitor::__acosh__);
|
||||
def("atanh",&TranscendentalVisitor::__atanh__);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
template<class PyClass>
|
||||
void ComplexVisitor<T>::visit(PyClass& cl) const
|
||||
{
|
||||
// MPFRFloatBaseVisitor<T>().visit(cl);
|
||||
|
||||
cl
|
||||
.add_property("real", &ComplexVisitor::get_real, &ComplexVisitor::set_real)
|
||||
.add_property("imag", &ComplexVisitor::get_imag, &ComplexVisitor::set_imag)
|
||||
|
||||
.def("__str__", &ComplexVisitor::__str__)
|
||||
.def("__repr__", &ComplexVisitor::__repr__)
|
||||
;
|
||||
|
||||
|
||||
// these complex-specific functions are free in python
|
||||
using boost::multiprecision::real;
|
||||
using boost::multiprecision::imag;
|
||||
|
||||
mpfr_float (*reeeal)(const T&) = &boost::multiprecision::real;
|
||||
mpfr_float (*imaaag)(const T&) = &boost::multiprecision::real;
|
||||
def("real",reeeal); //,return_value_policy<copy_const_reference>()
|
||||
def("imag",imaaag); //,return_value_policy<copy_const_reference>()
|
||||
|
||||
// and then a few more free functions
|
||||
// def("abs2",&T::abs2);
|
||||
|
||||
mpfr_complex (*pooolar)(const mpfr_float&,const mpfr_float&) = &boost::multiprecision::polar;
|
||||
|
||||
def("polar",pooolar);
|
||||
// def("norm",&T::norm);
|
||||
|
||||
def("conj",&ComplexVisitor::conj);
|
||||
|
||||
mpfr_float (*aaaarg)(const T&) = &boost::multiprecision::arg;
|
||||
def("arg",aaaarg);
|
||||
|
||||
// def("square",&square);
|
||||
// def("cube",&cube);
|
||||
// def("inverse", &inverse);
|
||||
|
||||
def("abs", &ComplexVisitor::__abs__); // free
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename T>
|
||||
unsigned get_precision_vector(Eigen::Ref<Vec<T>> x)
|
||||
{
|
||||
return bertini::Precision(x);
|
||||
}
|
||||
|
||||
|
||||
#define IMPLICITLY_CONVERTIBLE(T1,T2) \
|
||||
boost::python::implicitly_convertible<T1,T2>();
|
||||
|
||||
|
||||
|
||||
void ExposeFreeNumFns()
|
||||
{
|
||||
unsigned (*def_prec1)() = &bertini::DefaultPrecision;
|
||||
void (*def_prec2)(unsigned) = &bertini::DefaultPrecision;
|
||||
|
||||
def("default_precision", def_prec1);
|
||||
def("default_precision", def_prec2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void ExposeInt()
|
||||
{
|
||||
using T = mpz_int;
|
||||
|
||||
class_<mpz_int>("Int", init<>())
|
||||
.def(init<int>())
|
||||
.def(init<T>())
|
||||
.def(RealStrVisitor<T>())
|
||||
.def(RingSelfVisitor<T>())
|
||||
.def(PowVisitor<T,int>())
|
||||
.def(GreatLessSelfVisitor<T>())
|
||||
.def(GreatLessVisitor<T,int>())
|
||||
|
||||
.def(EqualitySelfVisitor<T>())
|
||||
.def(EqualityVisitor<T, int>())
|
||||
|
||||
.def(RealFreeVisitor<T>())
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void ExposeRational()
|
||||
{
|
||||
using T = mpq_rational;
|
||||
|
||||
class_<mpq_rational>("Rational", init<>())
|
||||
.def(init<int>())
|
||||
.def(init<int, int>())
|
||||
.def(init<mpz_int>())
|
||||
.def(init<mpz_int,mpz_int>())
|
||||
.def(init<mpq_rational>())
|
||||
.def(RealStrVisitor<T>())
|
||||
.def(FieldSelfVisitor<T>())
|
||||
.def(FieldVisitor<T, mpz_int>())
|
||||
// .def(PowVisitor<T,int>()) // deliberately commented out...
|
||||
// pow(Q,Z) not defined...
|
||||
.def(GreatLessSelfVisitor<T>())
|
||||
.def(GreatLessVisitor<T,int>())
|
||||
.def(GreatLessVisitor<T,mpz_int>())
|
||||
|
||||
.def(EqualitySelfVisitor<T>())
|
||||
.def(EqualityVisitor<T, int>())
|
||||
.def(EqualityVisitor<T, mpz_int>())
|
||||
|
||||
.def(RealFreeVisitor<T>())
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ExposeFloat()
|
||||
{
|
||||
using T = mpfr_float;
|
||||
|
||||
class_<T>("Float", init<>())
|
||||
.def(init<std::string>())
|
||||
.def(init<int>())
|
||||
.def(init<long int>())
|
||||
.def(init<T>())
|
||||
|
||||
.def(init<mpz_int>())
|
||||
|
||||
.def(RealStrVisitor<T>())
|
||||
.def(PrecisionVisitor<T>())
|
||||
|
||||
.def(FieldSelfVisitor<T>())
|
||||
|
||||
.def(FieldVisitor<T, int>())
|
||||
.def(FieldVisitor<T, mpz_int>())
|
||||
.def(FieldVisitor<T, mpq_rational>())
|
||||
|
||||
.def(PowVisitor<T,T>())
|
||||
.def(PowVisitor<T,int>())
|
||||
.def(TranscendentalVisitor<T>())
|
||||
|
||||
.def(GreatLessSelfVisitor<T>())
|
||||
.def(GreatLessVisitor<T,int>())
|
||||
.def(GreatLessVisitor<T,double>())
|
||||
|
||||
.def(RealFreeVisitor<T>())
|
||||
;
|
||||
|
||||
|
||||
eigenpy::registerNewType<T>();
|
||||
eigenpy::registerCommonUfunc<T>();
|
||||
|
||||
eigenpy::registerCast<T,long>(false);
|
||||
eigenpy::registerCast<long,T>(true);
|
||||
eigenpy::registerCast<T,int>(false);
|
||||
eigenpy::registerCast<int,T>(true);;
|
||||
eigenpy::registerCast<T,int64_t>(false);
|
||||
eigenpy::registerCast<int64_t,T>(true);
|
||||
|
||||
IMPLICITLY_CONVERTIBLE(int,T);
|
||||
IMPLICITLY_CONVERTIBLE(long,T);
|
||||
IMPLICITLY_CONVERTIBLE(int64_t,T);
|
||||
|
||||
eigenpy::EigenToPyConverter<Vec<T>>::registration();
|
||||
eigenpy::EigenToPyConverter<Mat<T>>::registration();
|
||||
eigenpy::EigenFromPyConverter<Vec<T>>::registration();
|
||||
eigenpy::EigenFromPyConverter<Mat<T>>::registration();
|
||||
|
||||
}
|
||||
|
||||
size_t get_default_align(){return EIGENPY_DEFAULT_ALIGN_BYTES;}
|
||||
|
||||
|
||||
void ExposeComplex()
|
||||
{
|
||||
|
||||
using T = bertini::mpfr_complex;
|
||||
|
||||
class_<T>("Complex", init<>())
|
||||
.def(init<double>()) // this should probably be made an explicit constructor rather than implicit
|
||||
.def(init<mpfr_float>())
|
||||
.def(init<std::string>())
|
||||
.def(init<mpfr_float,mpfr_float>())
|
||||
.def(init<double, double>()) // this should probably be made an explicit constructor rather than implicit
|
||||
.def(init<std::string, mpfr_float>())
|
||||
.def(init<mpfr_float, std::string>())
|
||||
.def(init<std::string, std::string>())
|
||||
.def(init<T>())
|
||||
|
||||
.def(init<mpz_int>())
|
||||
.def(init<mpz_int, mpz_int>())
|
||||
|
||||
.def(ComplexVisitor<T>())
|
||||
|
||||
.def(FieldSelfVisitor<T>())
|
||||
|
||||
.def(FieldVisitor<T, mpz_int>())
|
||||
.def(FieldVisitor<T, mpq_rational>())
|
||||
.def(FieldVisitor<T, mpfr_float>())
|
||||
|
||||
.def(FieldVisitor<T, int>())
|
||||
|
||||
.def(PowVisitor<T,T>())
|
||||
.def(PowVisitor<T,int>())
|
||||
.def(PowVisitor<T,mpfr_float>())
|
||||
|
||||
.def(TranscendentalVisitor<T>())
|
||||
|
||||
.def(PrecisionVisitor<T>())
|
||||
;
|
||||
|
||||
|
||||
eigenpy::registerNewType<T>();
|
||||
eigenpy::registerUfunct_without_comparitors<T>();
|
||||
|
||||
|
||||
// eigenpy::registerCast<T,long>(false);
|
||||
eigenpy::registerCast<long,T>(true);
|
||||
// eigenpy::registerCast<T,int>(false);
|
||||
eigenpy::registerCast<int,T>(true);
|
||||
// eigenpy::registerCast<T,int64_t>(false);
|
||||
eigenpy::registerCast<int64_t,T>(true);
|
||||
|
||||
|
||||
|
||||
|
||||
IMPLICITLY_CONVERTIBLE(int,T);
|
||||
IMPLICITLY_CONVERTIBLE(long,T);
|
||||
IMPLICITLY_CONVERTIBLE(int64_t,T);
|
||||
|
||||
|
||||
|
||||
eigenpy::EigenToPyConverter<Vec<T>>::registration();
|
||||
eigenpy::EigenToPyConverter<Mat<T>>::registration();
|
||||
eigenpy::EigenFromPyConverter<Vec<T>>::registration();
|
||||
eigenpy::EigenFromPyConverter<Mat<T>>::registration();
|
||||
|
||||
eigenpy::exposeType<T>();
|
||||
eigenpy::exposeType<T, Eigen::RowMajor>();
|
||||
|
||||
boost::python::def("precision", &get_precision_vector<mpfr_complex>, "get the precision of a vector of complexes");
|
||||
|
||||
boost::python::def("default_align_bytes", &get_default_align);
|
||||
|
||||
}
|
||||
|
||||
void ExportMpfr()
|
||||
{
|
||||
scope current_scope;
|
||||
std::string new_submodule_name(extract<const char*>(current_scope.attr("__name__")));
|
||||
new_submodule_name.append(".multiprec");
|
||||
object new_submodule(borrowed(PyImport_AddModule(new_submodule_name.c_str())));
|
||||
current_scope.attr("multiprec") = new_submodule;
|
||||
scope new_submodule_scope = new_submodule;
|
||||
|
||||
|
||||
|
||||
ExposeInt();
|
||||
ExposeFloat();
|
||||
ExposeRational();
|
||||
ExposeComplex();
|
||||
|
||||
ExposeFreeNumFns();
|
||||
};
|
||||
|
||||
|
||||
#undef IMPLICITLY_CONVERTIBLE
|
||||
|
||||
} //namespace python
|
||||
} // namespace bertini
|
||||
|
||||
|
||||
207
python/src/node_export.cpp
Normal file
207
python/src/node_export.cpp
Normal file
@@ -0,0 +1,207 @@
|
||||
//This file is part of Bertini 2.
|
||||
//
|
||||
//python/node_export.cpp is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//python/node_export.cpp is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with python/node_export.cpp. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright(C) 2016-2018 by Bertini2 Development Team
|
||||
//
|
||||
// See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
// as well as COPYING. Bertini2 is provided with permitted
|
||||
// additional terms in the b2/licenses/ directory.
|
||||
|
||||
// individual authors of this file include:
|
||||
//
|
||||
// James Collins
|
||||
// West Texas A&M University
|
||||
// Spring 2016
|
||||
//
|
||||
// silviana amethyst
|
||||
// UWEC
|
||||
// 2017, Spring 2018
|
||||
//
|
||||
//
|
||||
// python/node_export.cpp: Source file for exposing Node class to python.
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#include "node_export.hpp"
|
||||
|
||||
|
||||
namespace bertini{
|
||||
namespace python{
|
||||
|
||||
// Wrapper struct to allow derived classes to overide methods in python
|
||||
struct NodeWrap : Node, wrapper<Node>
|
||||
{
|
||||
void Reset()
|
||||
{
|
||||
if (override Reset = this->get_override("Reset"))
|
||||
Reset();
|
||||
|
||||
Node::Reset();
|
||||
}
|
||||
void default_Reset(){ return this->Node::Reset();}
|
||||
|
||||
void precision(unsigned int prec) { this->get_override("precision")(prec); }
|
||||
|
||||
int Degree(std::shared_ptr<Variable> const& v = nullptr) const {return this->get_override("Degree")(v); }
|
||||
int Degree(VariableGroup const& vars) const {return this->get_override("Degree")(vars); }
|
||||
|
||||
std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const {return this->get_override("Differentiate")(v); }
|
||||
|
||||
std::vector<int> MultiDegree(VariableGroup const& vars) const {return this->get_override("MultiDegree")(vars); }
|
||||
|
||||
void Homogenize(VariableGroup const& vars, std::shared_ptr<Variable> const& homvar) { this->get_override("Homogenize")(vars, homvar); }
|
||||
|
||||
bool IsHomogeneous(std::shared_ptr<Variable> const& v = nullptr) const {return this->get_override("IsHomogeneous")(v); }
|
||||
bool IsHomogeneous(VariableGroup const& vars) const {return this->get_override("IsHomogeneous")(vars); }
|
||||
|
||||
bool IsPolynomial(std::shared_ptr<Variable> const&v = nullptr) const {return this->get_override("IsPolynomial")(v); }
|
||||
bool IsPolynomial(VariableGroup const&v) const {return this->get_override("IsPolynomial")(v); }
|
||||
|
||||
|
||||
|
||||
}; // re: NodeWrap
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename NodeBaseT>
|
||||
template<class PyClass>
|
||||
void NodeVisitor<NodeBaseT>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
.def("reset", &NodeBaseT::Reset)
|
||||
.def("precision", &GetPrecision )
|
||||
.def("precision", SetPrecision )
|
||||
.def("degree", &Deg0 )
|
||||
.def("degree", Deg1)
|
||||
.def("degree", Deg2 )
|
||||
.def("differentiate", Diff0 )
|
||||
.def("differentiate", Diff1 )
|
||||
.def("multidegree", &NodeBaseT::MultiDegree )
|
||||
.def("homogenize", &NodeBaseT::Homogenize )
|
||||
.def("is_homogeneous", IsHom0 )
|
||||
.def("is_homogeneous", IsHom1 )
|
||||
.def("is_homogeneous", IsHom2 )
|
||||
.def("is_polynomial", IsPoly0 )
|
||||
.def("is_polynomial", IsPoly1 )
|
||||
.def("is_polynomial", IsPoly2 )
|
||||
|
||||
.def("eval_d", &Eval0<dbl> )
|
||||
.def("eval_d", return_Eval1_ptr<dbl>() )
|
||||
.def("eval_mp", &Eval0<mpfr_complex> )
|
||||
.def("eval_mp", return_Eval1_ptr<mpfr_complex>() )
|
||||
|
||||
.def(self_ns::str(self_ns::self))
|
||||
.def(self_ns::repr(self_ns::self))
|
||||
|
||||
.def("__add__",addNodeNode)
|
||||
.def("__add__",addNodeMpfr)
|
||||
.def("__radd__",&raddNodeMpfr)
|
||||
.def("__add__",addNodeRat)
|
||||
.def("__radd__",&raddNodeRat)
|
||||
.def("__add__",addNodeInt)
|
||||
.def("__radd__",raddNodeInt)
|
||||
.def("__iadd__",&NodeVisitor::iaddNodeNode)
|
||||
.def("__iadd__", &NodeVisitor::iaddSumNode)
|
||||
|
||||
.def("__sub__",subNodeNode)
|
||||
.def("__sub__",subNodeMpfr)
|
||||
.def("__rsub__",rsubNodeMpfr)
|
||||
.def("__sub__",subNodeRat)
|
||||
.def("__rsub__",rsubNodeRat)
|
||||
.def("__sub__",subNodeInt)
|
||||
.def("__rsub__",rsubNodeInt)
|
||||
.def("__isub__",&NodeVisitor::isubNodeNode)
|
||||
.def("__isub__", &NodeVisitor::isubSumNode)
|
||||
|
||||
.def("__mul__",multNodeNode)
|
||||
.def("__mul__",multNodeMpfr)
|
||||
.def("__rmul__",rmultNodeMpfr)
|
||||
.def("__mul__",multNodeRat)
|
||||
.def("__rmul__",rmultNodeRat)
|
||||
.def("__mul__",multNodeInt)
|
||||
.def("__rmul__",rmultNodeInt)
|
||||
.def("__imul__",&NodeVisitor::imultNodeNode)
|
||||
.def("__imul__",imultMultNode)
|
||||
|
||||
|
||||
.def("__div__",divNodeNode)
|
||||
.def("__truediv__",divNodeNode)
|
||||
.def("__itruediv__",&NodeVisitor::idivNodeNode)
|
||||
|
||||
|
||||
|
||||
|
||||
.def("__div__",divNodeMpfr)
|
||||
.def("__truediv__",divNodeMpfr)
|
||||
|
||||
.def("__rdiv__",rdivNodeMpfr)
|
||||
.def("__rtruediv__",rdivNodeMpfr)
|
||||
|
||||
.def("__rdiv__",rdivNodeRat)
|
||||
.def("__rtruediv__",rdivNodeRat)
|
||||
|
||||
.def("__div__",divNodeInt)
|
||||
.def("__truediv__",divNodeInt)
|
||||
|
||||
.def("__rdiv__",rdivNodeInt)
|
||||
.def("__rtruediv__",rdivNodeInt)
|
||||
|
||||
.def("__idiv__",&NodeVisitor::idivNodeNode)
|
||||
.def("__itruediv__",&NodeVisitor::idivNodeNode)
|
||||
|
||||
.def("__idiv__",idivMultNode)
|
||||
.def("__itruediv__",idivMultNode)
|
||||
|
||||
.def("__neg__", negNode)
|
||||
|
||||
.def("__pow__",powNodeNode)
|
||||
.def("__pow__",powNodeMpfr)
|
||||
.def("__pow__",powNodeRat)
|
||||
.def("__pow__",powNodeInt)
|
||||
;
|
||||
|
||||
|
||||
def("exp", expNodeNode);
|
||||
def("log", logNodeNode);
|
||||
def("sin", sinNodeNode);
|
||||
def("asin", asinNodeNode);
|
||||
def("cos", cosNodeNode);
|
||||
def("acos", acosNodeNode);
|
||||
def("tan", tanNodeNode);
|
||||
def("atan", atanNodeNode);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ExportNode()
|
||||
{
|
||||
class_<NodeWrap, boost::noncopyable, Nodeptr >("AbstractNode", no_init)
|
||||
.def(NodeVisitor<Node>())
|
||||
;
|
||||
};
|
||||
|
||||
|
||||
} //namespace python
|
||||
} // namespace bertini
|
||||
238
python/src/operator_export.cpp
Normal file
238
python/src/operator_export.cpp
Normal file
@@ -0,0 +1,238 @@
|
||||
//This file is part of Bertini 2.
|
||||
//
|
||||
//python/operator_export.cpp is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//python/operator_export.cpp is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with python/operator_export.cpp. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright(C) 2016-2018 by Bertini2 Development Team
|
||||
//
|
||||
// See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
// as well as COPYING. Bertini2 is provided with permitted
|
||||
// additional terms in the b2/licenses/ directory.
|
||||
|
||||
// individual authors of this file include:
|
||||
//
|
||||
// James Collins
|
||||
// West Texas A&M University
|
||||
// Spring 2016
|
||||
//
|
||||
// silviana amethyst
|
||||
// UWEC
|
||||
// Spring 2018
|
||||
//
|
||||
//
|
||||
//
|
||||
// python/operator_export.cpp: Source file for exposing operator nodes to python.
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include "operator_export.hpp"
|
||||
|
||||
|
||||
|
||||
namespace bertini{
|
||||
namespace python{
|
||||
|
||||
struct UnaryOpWrap : UnaryOperator, wrapper<UnaryOperator>
|
||||
{
|
||||
void SetOperand(std::shared_ptr<Node> new_child)
|
||||
{
|
||||
if (override SetOperand = this->get_override("SetOperand"))
|
||||
SetOperand(new_child); // *note*
|
||||
|
||||
UnaryOperator::SetOperand(new_child);
|
||||
}
|
||||
void default_SetChild(std::shared_ptr<Node> new_child){ return this->UnaryOperator::SetOperand(new_child);}
|
||||
}; // re: NodeWrap
|
||||
|
||||
|
||||
struct NaryOpWrap : NaryOperator, wrapper<NaryOperator>
|
||||
{
|
||||
void AddOperand(std::shared_ptr<Node> child)
|
||||
{
|
||||
if (override AddOperand = this->get_override("AddOperand"))
|
||||
AddOperand(child); // *note*
|
||||
|
||||
NaryOperator::AddOperand(child);
|
||||
}
|
||||
void default_AddOperand(std::shared_ptr<Node> child){ return this->NaryOperator::AddOperand(child);}
|
||||
}; // re: NodeWrap
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename NodeBaseT>
|
||||
template<class PyClass>
|
||||
void UnaryOpVisitor<NodeBaseT>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
.def("set_operand", &NodeBaseT::SetOperand )
|
||||
.def("operand", &NodeBaseT::Operand )
|
||||
;
|
||||
}
|
||||
|
||||
template<typename NodeBaseT>
|
||||
template<class PyClass>
|
||||
void NaryOpVisitor<NodeBaseT>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
.def("add_operand", &NodeBaseT::AddOperand )
|
||||
.def("first_operand", &NodeBaseT::FirstOperand )
|
||||
.def("num_operands", &NodeBaseT::NumOperands )
|
||||
;
|
||||
}
|
||||
|
||||
template<typename NodeBaseT>
|
||||
template<class PyClass>
|
||||
void SumMultOpVisitor<NodeBaseT>::visit(PyClass& cl) const
|
||||
{
|
||||
|
||||
cl
|
||||
.def("add_operand", AddOperand2)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
template<typename NodeBaseT>
|
||||
template<class PyClass>
|
||||
void PowerOpVisitor<NodeBaseT>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
.def("set_exponent", &PowerOperator::SetExponent)
|
||||
.def("set_base", &PowerOperator::SetBase)
|
||||
;
|
||||
}
|
||||
|
||||
template<typename NodeBaseT>
|
||||
template<class PyClass>
|
||||
void IntPowOpVisitor<NodeBaseT>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
.add_property("exponent", getexp, setexp)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ExportOperators()
|
||||
{
|
||||
scope current_scope;
|
||||
std::string new_submodule_name(extract<const char*>(current_scope.attr("__name__")));
|
||||
new_submodule_name.append(".operator");
|
||||
object new_submodule(borrowed(PyImport_AddModule(new_submodule_name.c_str())));
|
||||
current_scope.attr("operator") = new_submodule;
|
||||
|
||||
scope new_submodule_scope = new_submodule;
|
||||
|
||||
// Operator class
|
||||
class_<Operator, boost::noncopyable, bases<Node>, std::shared_ptr<Operator> >("AbstractOp", no_init)
|
||||
;
|
||||
|
||||
// UnaryOperator class
|
||||
class_<UnaryOpWrap, boost::noncopyable, bases<Operator>, std::shared_ptr<UnaryOperator> >("Unary", no_init)
|
||||
.def(UnaryOpVisitor<UnaryOperator>())
|
||||
;
|
||||
|
||||
// NaryOperator class
|
||||
class_<NaryOpWrap, boost::noncopyable, bases<Operator>, std::shared_ptr<NaryOperator> >("Nary", no_init)
|
||||
.def(NaryOpVisitor<NaryOperator>())
|
||||
;
|
||||
|
||||
// SumOperator class
|
||||
class_<SumOperator, bases<NaryOperator>, std::shared_ptr<SumOperator> >("Sum", no_init)
|
||||
.def("__init__", make_constructor(&SumOperator::template Make<const Nodeptr&, const Nodeptr &> ))
|
||||
.def("__init__", make_constructor(&SumOperator::template Make<const Nodeptr&, bool const&, const Nodeptr&, bool const&> ))
|
||||
.def(SumMultOpVisitor<SumOperator>())
|
||||
;
|
||||
|
||||
|
||||
// NegateOperator class
|
||||
class_<NegateOperator, bases<UnaryOperator>, std::shared_ptr<NegateOperator> >("Negate", no_init )
|
||||
.def("__init__", make_constructor(&NegateOperator::template Make<const Nodeptr&>))
|
||||
;
|
||||
|
||||
// MultOperator class
|
||||
class_<MultOperator, bases<NaryOperator>, std::shared_ptr<MultOperator> >("Mult", no_init )
|
||||
.def("__init__", make_constructor(&MultOperator::template Make<const Nodeptr&, const Nodeptr &>))
|
||||
.def("__init__", make_constructor(&MultOperator::template Make<const Nodeptr&, bool const&, const Nodeptr&, bool const&>))
|
||||
.def(SumMultOpVisitor<MultOperator>())
|
||||
;
|
||||
|
||||
// PowerOperator class
|
||||
class_<PowerOperator, bases<Operator>, std::shared_ptr<PowerOperator> >("Power", no_init )
|
||||
.def("__init__", make_constructor(&PowerOperator::template Make<const Nodeptr&, const Nodeptr &>))
|
||||
.def(PowerOpVisitor<PowerOperator>())
|
||||
;
|
||||
|
||||
// IntegerPowerOperator class
|
||||
class_<IntegerPowerOperator, bases<UnaryOperator>, std::shared_ptr<IntegerPowerOperator> >("IntegerPower", no_init )
|
||||
.def("__init__", make_constructor(&IntegerPowerOperator::template Make<const Nodeptr&, int const&>))
|
||||
.def(PowerOpVisitor<IntegerPowerOperator>())
|
||||
;
|
||||
|
||||
// SqrtOperator class
|
||||
class_<SqrtOperator, bases<UnaryOperator>, std::shared_ptr<SqrtOperator> >("Sqrt", no_init)
|
||||
.def("__init__", make_constructor(&SqrtOperator::template Make<const Nodeptr&>))
|
||||
;
|
||||
|
||||
// ExpOperator class
|
||||
class_<ExpOperator, bases<UnaryOperator>, std::shared_ptr<ExpOperator> >("Exp", no_init)
|
||||
.def("__init__", make_constructor(&ExpOperator::template Make<const Nodeptr&> ))
|
||||
;
|
||||
|
||||
// LogOperator class
|
||||
class_<LogOperator, bases<UnaryOperator>, std::shared_ptr<LogOperator> >("Log", no_init)
|
||||
.def("__init__", make_constructor(&LogOperator::template Make<const Nodeptr&> ))
|
||||
;
|
||||
|
||||
|
||||
|
||||
// TrigOperator class
|
||||
class_<TrigOperator, boost::noncopyable, bases<Node>, std::shared_ptr<TrigOperator> >("Trig", no_init)
|
||||
;
|
||||
|
||||
// SinOperator class
|
||||
class_<SinOperator, bases<TrigOperator, UnaryOperator>, std::shared_ptr<SinOperator> >("Sin", no_init)
|
||||
.def("__init__", make_constructor(&SinOperator::template Make<const Nodeptr&>))
|
||||
;
|
||||
// CosOperator class
|
||||
class_<CosOperator, bases<TrigOperator, UnaryOperator>, std::shared_ptr<CosOperator> >("Cos", no_init)
|
||||
.def("__init__", make_constructor(&CosOperator::template Make<const Nodeptr&>))
|
||||
;
|
||||
// TanOperator class
|
||||
class_<TanOperator, bases<TrigOperator, UnaryOperator>, std::shared_ptr<TanOperator> >("Tan", no_init)
|
||||
.def("__init__", make_constructor(&TanOperator::template Make<const Nodeptr&>))
|
||||
;
|
||||
|
||||
// ArcSinOperator class
|
||||
class_<ArcSinOperator, bases<TrigOperator, UnaryOperator>, std::shared_ptr<ArcSinOperator> >("ArcSin", no_init)
|
||||
.def("__init__", make_constructor(&ArcSinOperator::template Make<const Nodeptr&>))
|
||||
;
|
||||
// ArcCosOperator class
|
||||
class_<ArcCosOperator, bases<TrigOperator, UnaryOperator>, std::shared_ptr<ArcCosOperator> >("ArcCos", no_init)
|
||||
.def("__init__", make_constructor(&ArcCosOperator::template Make<const Nodeptr&>))
|
||||
;
|
||||
// ArcTanOperator class
|
||||
class_<ArcTanOperator, bases<TrigOperator, UnaryOperator>, std::shared_ptr<ArcTanOperator> >("ArcTan", no_init)
|
||||
.def("__init__", make_constructor(&ArcTanOperator::template Make<const Nodeptr&>))
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
} //namespace python
|
||||
} // namespace bertini
|
||||
|
||||
|
||||
|
||||
63
python/src/parser_export.cpp
Normal file
63
python/src/parser_export.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
//This file is part of Bertini 2.
|
||||
//
|
||||
//python/src/parser_export.cpp is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//python/src/parser_export.cpp is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with python/src/parser_export.cpp. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright(C) 2016-2018 by Bertini2 Development Team
|
||||
//
|
||||
// See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
// as well as COPYING. Bertini2 is provided with permitted
|
||||
// additional terms in the b2/licenses/ directory.
|
||||
|
||||
// individual authors of this file include:
|
||||
//
|
||||
// James Collins
|
||||
// West Texas A&M University
|
||||
// Spring 2016
|
||||
//
|
||||
// silviana amethyst
|
||||
// UWEC
|
||||
// Spring 2018
|
||||
//
|
||||
//
|
||||
// python/src/parser_export.cpp
|
||||
|
||||
|
||||
|
||||
#include "parser_export.hpp"
|
||||
|
||||
|
||||
namespace bertini{
|
||||
namespace python{
|
||||
|
||||
using namespace bertini;
|
||||
|
||||
|
||||
|
||||
void ExportParsers()
|
||||
{
|
||||
scope current_scope;
|
||||
std::string new_submodule_name(extract<const char*>(current_scope.attr("__name__")));
|
||||
new_submodule_name.append(".parse");
|
||||
object new_submodule(borrowed(PyImport_AddModule(new_submodule_name.c_str())));
|
||||
current_scope.attr("parse") = new_submodule;
|
||||
scope new_submodule_scope = new_submodule;
|
||||
new_submodule_scope.attr("__doc__") = "Parsing functions, to turn strings into other things.";
|
||||
|
||||
using namespace bertini::parsing;
|
||||
def("system", &Parser<System, classic::SystemParser<std::string::const_iterator> >);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
35
python/src/random_export.cpp
Normal file
35
python/src/random_export.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "random_export.hpp"
|
||||
|
||||
|
||||
namespace bertini{
|
||||
namespace python{
|
||||
|
||||
|
||||
|
||||
void ExportRandom(){
|
||||
|
||||
scope current_scope;
|
||||
std::string new_submodule_name(extract<const char*>(current_scope.attr("__name__")));
|
||||
new_submodule_name.append(".random");
|
||||
object new_submodule(borrowed(PyImport_AddModule(new_submodule_name.c_str())));
|
||||
current_scope.attr("random") = new_submodule;
|
||||
scope new_submodule_scope = new_submodule;
|
||||
|
||||
|
||||
|
||||
def("complex_in_minus_one_to_one", bertini::multiprecision::rand,"Make a random complex number uniformly distributed in [-1,1]x[-1,1], in the current default precision");
|
||||
def("complex_unit", bertini::multiprecision::rand_unit,"Make a random complex number of magnitude 1, in the current default precision");
|
||||
|
||||
|
||||
mpfr_complex (*RandRealNoArgs)() = &bertini::multiprecision::RandomReal;
|
||||
def("real_as_complex", RandRealNoArgs, "Make a random real number in [-1,1], as a complex number with imaginary part 0, in the current default precision");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} //namespace python
|
||||
} // namespace bertini
|
||||
121
python/src/root_export.cpp
Normal file
121
python/src/root_export.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
//This file is part of Bertini 2.
|
||||
//
|
||||
//python/root_export.cpp is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//python/root_export.cpp is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with python/root_export.cpp. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright(C) 2016-2018 by Bertini2 Development Team
|
||||
//
|
||||
// See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
// as well as COPYING. Bertini2 is provided with permitted
|
||||
// additional terms in the b2/licenses/ directory.
|
||||
|
||||
// individual authors of this file include:
|
||||
//
|
||||
// James Collins
|
||||
// West Texas A&M University
|
||||
// Spring 2016
|
||||
//
|
||||
// silviana amethyst
|
||||
// UWEC
|
||||
// Spring 2018, Fall 2023
|
||||
//
|
||||
//
|
||||
//
|
||||
// python/root_export.cpp: Source file for exposing root nodes to python.
|
||||
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include "root_export.hpp"
|
||||
|
||||
|
||||
namespace bertini{
|
||||
namespace python{
|
||||
|
||||
|
||||
|
||||
template<typename NodeBaseT>
|
||||
template<class PyClass>
|
||||
void HandleVisitor<NodeBaseT>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
.def("root", &Handle::EntryNode,return_value_policy<reference_existing_object>())
|
||||
.def("root", &Handle::SetRoot)
|
||||
.def("ensure_not_empy", &Handle::EnsureNotEmpty)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename NodeBaseT>
|
||||
template<class PyClass>
|
||||
void FunctionVisitor<NodeBaseT>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
template<typename NodeBaseT>
|
||||
template<class PyClass>
|
||||
void JacobianVisitor<NodeBaseT>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
.def("evalJ_d", &Jacobian::template EvalJ<dbl>)
|
||||
.def("evalJ_mp", &Jacobian::template EvalJ<mpfr_complex>)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ExportRoots()
|
||||
{
|
||||
scope current_scope;
|
||||
std::string new_submodule_name(extract<const char*>(current_scope.attr("__name__")));
|
||||
new_submodule_name.append(".root");
|
||||
object new_submodule(borrowed(PyImport_AddModule(new_submodule_name.c_str())));
|
||||
current_scope.attr("root") = new_submodule;
|
||||
|
||||
scope new_submodule_scope = new_submodule;
|
||||
|
||||
|
||||
// TrigOperator class
|
||||
class_<Handle, boost::noncopyable, bases<NamedSymbol>, std::shared_ptr<Handle> >("Handle", no_init)
|
||||
.def(HandleVisitor<Handle>())
|
||||
;
|
||||
|
||||
|
||||
// Function class
|
||||
class_<Function, bases<Handle>, std::shared_ptr<Function> >("Function", no_init)
|
||||
.def("__init__",make_constructor(&Function::template Make<std::string const&>))
|
||||
.def("__init__",make_constructor(&Function::template Make<const std::shared_ptr<Node> &> ))
|
||||
|
||||
.def(FunctionVisitor<Function>())
|
||||
|
||||
;
|
||||
|
||||
|
||||
// Jacobian class
|
||||
class_<Jacobian, bases<Handle>, std::shared_ptr<Jacobian> >("Jacobian", no_init)
|
||||
.def("__init__",make_constructor(&Jacobian::template Make<const Nodeptr&>))
|
||||
.def(JacobianVisitor<Jacobian>())
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
177
python/src/symbol_export.cpp
Normal file
177
python/src/symbol_export.cpp
Normal file
@@ -0,0 +1,177 @@
|
||||
//This file is part of Bertini 2.
|
||||
//
|
||||
//python/symbol_export.cpp is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//python/symbol_export.cpp is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with python/symbol_export.cpp. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright(C) 2016-2018 by Bertini2 Development Team
|
||||
//
|
||||
// See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
// as well as COPYING. Bertini2 is provided with permitted
|
||||
// additional terms in the b2/licenses/ directory.
|
||||
|
||||
// individual authors of this file include:
|
||||
//
|
||||
// James Collins
|
||||
// West Texas A&M University
|
||||
// Spring 2016
|
||||
//
|
||||
//
|
||||
//
|
||||
// python/symbol_export.cpp: Source file for exposing symbol nodes to python.
|
||||
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "symbol_export.hpp"
|
||||
|
||||
|
||||
|
||||
namespace bertini{
|
||||
namespace python{
|
||||
|
||||
template<typename NodeBaseT>
|
||||
template<class PyClass>
|
||||
void NamedSymbolVisitor<NodeBaseT>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
.add_property("name", getname, setname)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
template<typename NodeBaseT>
|
||||
template<class PyClass>
|
||||
void RationalVisitor<NodeBaseT>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
.def("rand", &NodeBaseT::template Rand<16>)
|
||||
.def("rand_real", &NodeBaseT::template RandReal<16>)
|
||||
.staticmethod("rand")
|
||||
.staticmethod("rand_real")
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename NodeBaseT>
|
||||
template<class PyClass>
|
||||
void VariableVisitor<NodeBaseT>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
.def("set_current_value", &NodeBaseT::template set_current_value<dbl>)
|
||||
.def("set_current_value", &NodeBaseT::template set_current_value<mpfr_complex>)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
template<typename NodeBaseT>
|
||||
template<class PyClass>
|
||||
void DifferentialVisitor<NodeBaseT>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
.def("get_variable", &NodeBaseT::GetVariable,return_value_policy<reference_existing_object>())
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ExportSymbols()
|
||||
{
|
||||
scope current_scope;
|
||||
std::string new_submodule_name(extract<const char*>(current_scope.attr("__name__")));
|
||||
new_submodule_name.append(".symbol");
|
||||
object new_submodule(borrowed(PyImport_AddModule(new_submodule_name.c_str())));
|
||||
current_scope.attr("symbol") = new_submodule;
|
||||
|
||||
scope new_submodule_scope = new_submodule;
|
||||
|
||||
|
||||
// Symbol class
|
||||
class_<Symbol, boost::noncopyable, bases<Node>, std::shared_ptr<Symbol> >("AbstractSymbol", no_init)
|
||||
;
|
||||
|
||||
// NamedSymbol class
|
||||
class_<NamedSymbol, boost::noncopyable, bases<Symbol>, std::shared_ptr<NamedSymbol> >("AbstractNamedSymbol", no_init)
|
||||
;
|
||||
|
||||
// Number class
|
||||
class_<Number, boost::noncopyable, bases<Symbol>, std::shared_ptr<Number> >("AbstractNumber", no_init)
|
||||
;
|
||||
|
||||
// Float class
|
||||
class_<Float, bases<Number>, std::shared_ptr<Float> >("Float", no_init)
|
||||
.def("__init__", make_constructor(&Float::template Make<mpfr_float const&, mpfr_float const&>))
|
||||
.def("__init__", make_constructor(&Float::template Make<std::string const&>))
|
||||
.def("__init__", make_constructor(&Float::template Make<std::string const&, std::string const&>))
|
||||
.def("__init__", make_constructor(&Float::template Make<mpfr_complex const&>))
|
||||
;
|
||||
|
||||
|
||||
// Pi class
|
||||
class_<special_number::Pi, bases<NamedSymbol>, std::shared_ptr<special_number::Pi> >("Pi", no_init)
|
||||
.def("__init__", make_constructor(&special_number::Pi::template Make<>))
|
||||
;
|
||||
|
||||
|
||||
// E class
|
||||
class_<special_number::E, bases<NamedSymbol>, std::shared_ptr<special_number::E> >("E", no_init)
|
||||
.def("__init__", make_constructor(&special_number::E::template Make<>))
|
||||
;
|
||||
|
||||
|
||||
// Integer class
|
||||
class_<Integer, bases<Number>, std::shared_ptr<Integer> >("Integer",no_init)
|
||||
.def("__init__", make_constructor(&Integer::template Make<int const&>))
|
||||
.def("__init__", make_constructor(&Integer::template Make<mpz_int const&>))
|
||||
.def("__init__", make_constructor(&Integer::template Make<std::string const&>))
|
||||
;
|
||||
|
||||
|
||||
// Rational class
|
||||
class_<Rational, bases<Number>, std::shared_ptr<Rational> >("Rational", no_init)
|
||||
.def("__init__", make_constructor(&Rational::template Make<int const&>))
|
||||
.def("__init__", make_constructor(&Rational::template Make<int const&, int const&, int const&, int const&>))
|
||||
.def("__init__", make_constructor(&Rational::template Make<std::string const&>))
|
||||
.def("__init__", make_constructor(&Rational::template Make<std::string const&, std::string const&>))
|
||||
.def("__init__", make_constructor(&Rational::template Make<mpq_rational const&, mpq_rational const&>))
|
||||
.def(RationalVisitor<Rational>())
|
||||
;
|
||||
|
||||
|
||||
// Variable class
|
||||
class_<Variable, bases<NamedSymbol>, std::shared_ptr<Variable> >("Variable", no_init)
|
||||
.def("__init__", make_constructor(&Variable::template Make< std::string const& >))
|
||||
.def(VariableVisitor<Variable>())
|
||||
;
|
||||
|
||||
|
||||
// Differential class
|
||||
class_<Differential, bases<NamedSymbol>,std::shared_ptr<node::Differential> >("Differential", no_init)
|
||||
.def("__init__", make_constructor(Differential::template Make<std::shared_ptr<Variable> const&,std::string const&>))
|
||||
.def(DifferentialVisitor<Differential>())
|
||||
;
|
||||
|
||||
|
||||
def("make_pi", &Pi);
|
||||
def("make_i", &I);
|
||||
def("make_e", &E);
|
||||
|
||||
};
|
||||
|
||||
|
||||
} //namespace python
|
||||
} // namespace bertini
|
||||
260
python/src/system_export.cpp
Normal file
260
python/src/system_export.cpp
Normal file
@@ -0,0 +1,260 @@
|
||||
//This file is part of Bertini 2.
|
||||
//
|
||||
//python/system_export.cpp is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//python/system_export.cpp is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with python/system_export.cpp. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright(C) 2016-2018 by Bertini2 Development Team
|
||||
//
|
||||
// See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
// as well as COPYING. Bertini2 is provided with permitted
|
||||
// additional terms in the b2/licenses/ directory.
|
||||
|
||||
// individual authors of this file include:
|
||||
//
|
||||
// James Collins
|
||||
// West Texas A&M University
|
||||
// Spring 2016
|
||||
//
|
||||
// silviana amethyst
|
||||
// UWEC
|
||||
// Spring 2018
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// python/system_export.cpp: Source file for exposing systems to python, including start systems.
|
||||
|
||||
#include <stdio.h>
|
||||
#include "system_export.hpp"
|
||||
|
||||
|
||||
|
||||
namespace bertini{
|
||||
namespace python{
|
||||
template<typename T> using Vec = Eigen::Matrix<T, Eigen::Dynamic, 1>;
|
||||
|
||||
|
||||
struct StartSystemWrap : start_system::StartSystem, wrapper<start_system::StartSystem>
|
||||
{
|
||||
unsigned long long NumStartPoints() const {return this->get_override("NumStartPoints")(); }
|
||||
}; // re: StartSystemWrap
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename SystemBaseT>
|
||||
template<class PyClass>
|
||||
void SystemVisitor<SystemBaseT>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
.def("precision", get_prec_,"Get the current precision of the system. Returns a postive number, representing the number of digits (not bits) at which the system is currently represented. (there is a reference-level precision stored, so you can change this up / down mostly fearlessly)")
|
||||
.def("precision", set_prec_,"Set / change the precision of the system. Feed in a positive number, representing the digits (not bits) of the precision. Double precision is 16, but that only effects the multi-precision precision... you can eval in double precision without changing the precision to 16.")
|
||||
.def("differentiate", &SystemBaseT::Differentiate)
|
||||
|
||||
.def("eval", return_Eval0_ptr<dbl>() ,"Evaluate the system in double precision, using already-set variable values.")
|
||||
.def("eval", return_Eval0_ptr<mpfr>() ,"Evaluate the system in multiple precision, using already-set variable values.")
|
||||
.def("eval", return_Eval1_ptr<dbl>() ,"Evaluate the system in double precision, using space variable values passed into this function.")
|
||||
.def("eval", return_Eval1_ptr<mpfr>() ,"Evaluate the system in multiple precision, using space variable values passed into this function.")
|
||||
.def("eval", return_Eval2_ptr<dbl>() ,"Evaluate the system in double precision using space and time values passed into this function. Throws if doesn't use a time variable")
|
||||
.def("eval", return_Eval2_ptr<mpfr>() ,"Evaluate the system in multiple precision using space and time values passed into this function. Throws if doesn't use a time variable")
|
||||
|
||||
// these two commented out because i don't need in-place Eigen::Ref wrapping here.
|
||||
// but if you did, you'd use two lines like this, ha.
|
||||
// .def("eval", &eval_wrap_1<mpfr>)
|
||||
// .def("eval", &eval_wrap_1<dbl>)
|
||||
|
||||
.def("eval_jacobian", return_Jac0_ptr<dbl>() ,"Evaluate the Jacobian (martix of partial derivatives) of the system, using already-set time and space value.")
|
||||
.def("eval_jacobian", return_Jac0_ptr<mpfr>() ,"Evaluate the Jacobian (martix of partial derivatives) of the system, using already-set time and space value.")
|
||||
.def("eval_jacobian", return_Jac1_ptr<dbl>() ,"Evaluate the Jacobian (martix of partial derivatives) of the system, using space values you pass in to this function")
|
||||
.def("eval_jacobian", return_Jac1_ptr<mpfr>() ,"Evaluate the Jacobian (martix of partial derivatives) of the system, using space values you pass in to this function")
|
||||
.def("eval_jacobian", return_Jac2_ptr<dbl>() , "Evaluate the Jacobian (martix of partial derivatives) of the system, using time and space values passed into this function. Throws if doesn't use a time variable")
|
||||
.def("eval_jacobian", return_Jac2_ptr<mpfr>() , "Evaluate the Jacobian (martix of partial derivatives) of the system, using time and space values passed into this function. Throws if doesn't use a time variable")
|
||||
|
||||
.def("homogenize", &SystemBaseT::Homogenize,"Homogenize the system, adding new homogenizing variables if necessary. This may change your polynomials; that is, it has side effects.")
|
||||
.def("is_homogeneous", &SystemBaseT::IsHomogeneous, "Determines whether all polynomials in the system have the same degree. Non-polynomial functions are not homogeneous.")
|
||||
.def("is_polynomial", &SystemBaseT::IsPolynomial, "Determines whether all polynomials are polynomial. Transcendental functions, e.g., are non-polynomial. Returns a bool.")
|
||||
|
||||
.def("num_functions", &SystemBaseT::NumTotalFunctions,"The total number of functions in the system. Does not include patches.")
|
||||
.def("num_variables", &SystemBaseT::NumVariables,"the *total* number of variables in the system. Includes homogenizing variables")
|
||||
.def("num_hom_variables", &SystemBaseT::NumHomVariables, "The number of homogenizing variables defined in the system. Should be equal to the number of homvargroups")
|
||||
.def("num_variable_groups", &SystemBaseT::NumVariableGroups,"The number of affine variable groups. This should probably be renamed to num_affine_variable_groups")
|
||||
.def("num_ungrouped_variables", &SystemBaseT::NumUngroupedVariables,"The number of variables, not grouped into an affine or projective space")
|
||||
.def("num_hom_variable_groups", &SystemBaseT::NumHomVariableGroups,"The number of homogeneous or projective variable groups. The number of homogenizing variables should eventually equal this.")
|
||||
// .def("num_constants", &SystemBaseT::NumConstants,"Has no impact on anything. The number of constants in the system.")
|
||||
// .def("num_parameters", &SystemBaseT::NumParameters,"Has no impact on anything. The number of 'parameters' in the system.")
|
||||
// .def("num_implicit_parameters", &SystemBaseT::NumImplicitParameters,"Has no impact on anything. The number of 'implicit parameters' in the system.") // commented out until implemented
|
||||
|
||||
.def("set_variables", &SystemBaseT::template SetVariables<dbl>,"Set the values of the variables. Expects a vector of doubles")
|
||||
.def("set_variables", &SystemBaseT::template SetVariables<mpfr>,"Set the values of the variables. Expects a vector of complex mpfr's")
|
||||
.def("set_path_variable", &SystemBaseT::template SetPathVariable<dbl>,"Set the value of the path variable. This one's double-precision. Throws if path variable not defined.")
|
||||
.def("set_path_variable", &SystemBaseT::template SetPathVariable<mpfr>,"Set the value of the path variable. This one's variable-precision. Throws if path variable not defined.")
|
||||
// .def("set_implicit_parameters", &SystemBaseT::template SetImplicitParameters<dbl>,"Doesn't do anything. Sets the values of algebraically constrained parameters")
|
||||
// .def("set_implicit_parameters", &SystemBaseT::template SetImplicitParameters<mpfr>,"Doesn't do anything. Sets the values of algebraically constrained parameters")
|
||||
|
||||
.def("add_variable_group", &SystemBaseT::AddVariableGroup,"Add a (affine) variable group to the System")
|
||||
.def("add_hom_variable_group", &SystemBaseT::AddHomVariableGroup,"Add a projective or homogeneous variable group to the System")
|
||||
// .def("add_ungrouped_variable", &SystemBaseT::AddUngroupedVariable,"Add an ungrouped variable to the system. I honestly don't know why you'd do that. This should be removed, and is a holdover from Bertini 1")
|
||||
// .def("add_ungrouped_variables", &SystemBaseT::AddUngroupedVariables,"Add some ungrouped variables to the system. I honestly don't know why you'd do that. This should be removed, and is a holdover from Bertini 1")
|
||||
// .def("add_implicit_parameter", &SystemBaseT::AddImplicitParameter)
|
||||
// .def("add_implicit_parameters", &SystemBaseT::AddImplicitParameters)
|
||||
// .def("add_parameter", &SystemBaseT::AddParameter)
|
||||
// .def("add_parameters", &SystemBaseT::AddParameters)
|
||||
// .def("add_subfunction", &SystemBaseT::AddSubfunction)
|
||||
// .def("add_subfunctions", &SystemBaseT::AddSubfunctions)
|
||||
.def("add_function", sysAddFunc1,"Add a function to the System")
|
||||
.def("add_function", AddFnAndName(),"Add a function to the System, naming it too")
|
||||
.def("add_function", AddJustFn,"Add a function to the System, giving it the default name")
|
||||
|
||||
.def("add_functions", &SystemBaseT::AddFunctions,"Add some functions to the System. Expects a list of functions")
|
||||
// .def("add_constant", &SystemBaseT::AddConstant)
|
||||
// .def("add_constants", &SystemBaseT::AddConstants)
|
||||
.def("add_path_variable", &SystemBaseT::AddPathVariable,"Add a path variable to the System")
|
||||
.def("have_path_variable", &SystemBaseT::HavePathVariable,"Asks whether the System has a path variable defined")
|
||||
|
||||
.def("function", &SystemBaseT::Function,"Get a function with a given index. Problems ensue if out of range -- uses un-rangechecked version of underlying getter")
|
||||
.def("variable_groups", &SystemBaseT::VariableGroups, "Get the list of (affine) variable_groups from the system")
|
||||
.def("hom_variable_groups", &SystemBaseT::HomVariableGroups, "Get the list of projective / homogeneous variable_groups from the system")
|
||||
.def("degrees", sysDeg1, "Get a list of the degrees of the functions in the system, with respect to all variables in all groups (and in fact overall)")
|
||||
.def("degrees", sysDeg2, "Get a list of the degrees of the functions in the system, with respect to a variable_group passed in to this function. Negative numbers indicate non-polynomial")
|
||||
.def("reorder_functions_by_degree_decreasing", &SystemBaseT::ReorderFunctionsByDegreeDecreasing,"Change the order of the functions to be in decreasing order")
|
||||
.def("reorder_functions_by_degree_increasing", &SystemBaseT::ReorderFunctionsByDegreeIncreasing,"Change the order of the functions to be in decreasing order")
|
||||
.def("clear_variables", &SystemBaseT::ClearVariables, "Remove the variable structure from the system")
|
||||
.def("copy_variable_structure", &SystemBaseT::CopyVariableStructure, "Copy the variable structure from another System")
|
||||
|
||||
.def("auto_patch",&SystemBaseT::AutoPatch,"Apply a patch to the system, given its current variable group structure.")
|
||||
.def("copy_patches",&SystemBaseT::CopyPatches,"Copy the patches from another system into this one.")
|
||||
.def("get_patch",&SystemBaseT::GetPatch,"Get (a reference to) the patches from the system.")
|
||||
.def("is_patched",&SystemBaseT::IsPatched,"Check whether the system is patched.")
|
||||
|
||||
.def("rescale_point_to_fit_patch",&SystemBaseT::template RescalePointToFitPatch<dbl>,"Return a rescaled version of the input point, which fits the patch for the system.")
|
||||
.def("rescale_point_to_fit_patch",&SystemBaseT::template RescalePointToFitPatch<mpfr>,"Return a rescaled version of the input point, which fits the patch for the system.")
|
||||
|
||||
.def("rescale_point_to_fit_patch_in_place",&SystemBaseT::template RescalePointToFitPatchInPlace<dbl>,"Re-scale the input point, in place, to fit the patch for the system. This assumes you have properly set the variable groups and auto-patched the system.")
|
||||
|
||||
// .def("rescale_point_to_fit_patch_in_place",&SystemBaseT::template RescalePointToFitPatchInPlace<mpfr>,"Re-scale the input point, in place, to fit the patch for the system. This assumes you have properly set the variable groups and auto-patched the system.")
|
||||
.def("rescale_point_to_fit_patch_in_place",&rescale_wrap_inplace_mpfr,"Re-scale the input point, in place, to fit the patch for the system. This assumes you have properly set the variable groups and auto-patched the system.")
|
||||
|
||||
.def("dehomogenize_point",&SystemBaseT::template DehomogenizePoint<dbl>, "Dehomogenize a vector of doubles (complex), using the variable structure in this System")
|
||||
.def("dehomogenize_point",&SystemBaseT::template DehomogenizePoint<mpfr>, "Dehomogenize a vector of mpfr's (complex), using the variable structure in this System")
|
||||
|
||||
.def(self_ns::str(self_ns::self))//, "String representation of the system"
|
||||
.def(self_ns::repr(self_ns::self))//, "Round-trippable representation of the system. Probably not functional"
|
||||
.def(self += self)
|
||||
.def(self + self)
|
||||
.def(self *= std::shared_ptr<node::Node>())//, "'Scalar-multiply' a system"
|
||||
.def(self * std::shared_ptr<node::Node>())//, "'Scalar-multiply' a system"
|
||||
.def(std::shared_ptr<node::Node>() * self)//, "'Scalar-multiply' a system"
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename SystemBaseT>
|
||||
template<class PyClass>
|
||||
void StartSystemVisitor<SystemBaseT>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
.def("num_start_points", &SystemBaseT::NumStartPoints, "Get the number of start points that would be required by the system. Non-negative, unsigned")
|
||||
.def("start_point_d", return_GenStart_ptr<dbl>(),"Get the k-th start point in double precision")
|
||||
.def("start_point_mp", return_GenStart_ptr<mpfr>(),"Get the k-th start point in current multiple precision")
|
||||
;
|
||||
|
||||
|
||||
};
|
||||
|
||||
void ExportAllSystems()
|
||||
{
|
||||
|
||||
scope current_scope;
|
||||
std::string new_submodule_name(extract<const char*>(current_scope.attr("__name__")));
|
||||
new_submodule_name.append(".system");
|
||||
object new_submodule(borrowed(PyImport_AddModule(new_submodule_name.c_str())));
|
||||
current_scope.attr("system") = new_submodule;
|
||||
|
||||
|
||||
scope new_submodule_scope = new_submodule;
|
||||
new_submodule_scope.attr("__doc__") = "Systems of functions, for tracking &c.";
|
||||
|
||||
ExportSystem();
|
||||
ExportStartSystems();
|
||||
}
|
||||
|
||||
void call_simplify(object obj){
|
||||
System& sys=extract<System&>(obj)();
|
||||
Simplify(sys);
|
||||
};
|
||||
|
||||
void ExportSystem()
|
||||
{
|
||||
|
||||
// System class
|
||||
class_<System, std::shared_ptr<System> >("System", init<>())
|
||||
.def(SystemVisitor<System>())
|
||||
;
|
||||
|
||||
// free functions
|
||||
def("concatenate", &Concatenate, "concatenate two Systems to produce a new one. Appends the second onto what was the first.");
|
||||
def("clone", &Clone, "Make a complete clone of a System. Includes all functions, variables, etc. Truly and genuinely distinct.");
|
||||
|
||||
|
||||
|
||||
|
||||
def("simplify", &call_simplify, "Perform all possible simplifications. Has side effects of modifying your functions, if held separately. Shared nodes between multiple systems may have adverse effects");
|
||||
|
||||
}
|
||||
|
||||
void ExportStartSystems()
|
||||
{
|
||||
|
||||
{ // enter a scope for config types
|
||||
scope current_scope;
|
||||
std::string new_submodule_name(extract<const char*>(current_scope.attr("__name__")));
|
||||
new_submodule_name.append(".start_system");
|
||||
object new_submodule(borrowed(PyImport_AddModule(new_submodule_name.c_str())));
|
||||
current_scope.attr("start_system") = new_submodule;
|
||||
|
||||
scope new_submodule_scope = new_submodule;
|
||||
|
||||
ExportStartSystemBase();
|
||||
ExportTotalDegree();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ExportStartSystemBase()
|
||||
{
|
||||
//
|
||||
// StartSystem class
|
||||
class_<StartSystemWrap, boost::noncopyable, bases<System>, std::shared_ptr<start_system::StartSystem> >("AbstractStartSystem", no_init)
|
||||
.def(StartSystemVisitor<start_system::StartSystem>())
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ExportTotalDegree()
|
||||
{
|
||||
class_<start_system::TotalDegree, bases<start_system::StartSystem>, std::shared_ptr<start_system::TotalDegree> >("TotalDegree",init<System const&>())//,"Only constructor for a TotalDegree start system, requires a system. You cannot construct one without. If this is a problem, please contact the authors for help.")
|
||||
.def("random_value", &start_system::TotalDegree::RandomValue<dbl>, "Get the k-th random value, in double precision")
|
||||
.def("random_value", &start_system::TotalDegree::RandomValue<mpfr>, "Get the k-th random value, in current multiple precision")
|
||||
.def("random_values", &start_system::TotalDegree::RandomValues, return_value_policy<copy_const_reference>(), "Get (a reference to) the random values for the start system, as Nodes")
|
||||
;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
281
python/src/tracker_export.cpp
Normal file
281
python/src/tracker_export.cpp
Normal file
@@ -0,0 +1,281 @@
|
||||
//This file is part of Bertini 2.
|
||||
//
|
||||
//python/tracker_export.cpp is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//python/tracker_export.cpp is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with python/tracker_export.cpp. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright(C) 2016-2018 by Bertini2 Development Team
|
||||
//
|
||||
// See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
// as well as COPYING. Bertini2 is provided with permitted
|
||||
// additional terms in the b2/licenses/ directory.
|
||||
|
||||
// individual authors of this file include:
|
||||
//
|
||||
// silviana amethyst
|
||||
// University of Notre Dame
|
||||
// Summer 2016, Spring 2018
|
||||
//
|
||||
//
|
||||
// python/tracker_export.cpp: source file for exposing trackers to python.
|
||||
|
||||
#include "tracker_export.hpp"
|
||||
|
||||
namespace bertini{
|
||||
namespace python{
|
||||
|
||||
template<typename TrackerT>
|
||||
template<class PyClass>
|
||||
void TrackerVisitor<TrackerT>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
.def("setup", &TrackerT::Setup, (boost::python::arg("predictor"), boost::python::arg("tolerance"), boost::python::arg("truncation"), boost::python::arg("stepping"),boost::python::arg("newton")), "Set values for the internal configuration of the tracker. tolerance and truncation are both real doubles. predictor is a valid value for predictor choice. stepping and newton are the config structs from pybertini.tracking.config.")
|
||||
|
||||
.def("track_path", &track_path_wrap,
|
||||
(boost::python::arg("result"), "start_time", "end_time", "start_point"),
|
||||
"The main function of the tracker, once its set up. The first argument is the output. Feed it, in (result, start_time, end_time, start_point")
|
||||
|
||||
.def("get_system",&TrackerT::GetSystem,return_internal_reference<>(), "Gets an internal reference to the tracked system.")
|
||||
|
||||
.def("predictor",get_predictor_,"Query the current predictor method used by the tracker.")
|
||||
.def("predictor",set_predictor_,"Set the predictor method used by the tracker.")
|
||||
|
||||
.def("set_stepsize", &TrackerT::SetStepSize)
|
||||
|
||||
.def("reinitialize_initial_step_size", &TrackerT::ReinitializeInitialStepSize, "Set whether the tracker should re-set the stepsize to the configured-initial stepsize when it starts tracking. Feed it a bool")
|
||||
.def("num_total_steps_taken", &TrackerT::NumTotalStepsTaken,"Ask how many steps have been taken so far, including failures")
|
||||
|
||||
.def("tracking_tolerance", &TrackerT::TrackingTolerance,"A step is labeled as a failure if newton correcting doesn't yield a residual less than this tolerance. A real number, the smaller the slower tracking, generally speaking")
|
||||
.def("tracking_tolerance", &TrackerT::SetTrackingTolerance,"Set the tracking tolerance for the tracker")
|
||||
|
||||
.def("infinite_truncation_tolerance", &TrackerT::SetInfiniteTruncationTolerance,"Set the path truncation tolerance for infinite paths for the tracker")
|
||||
.def("infinite_truncation_tolerance", &TrackerT::InfiniteTruncationTolerance,"Get the path truncation tolerance for infinite paths for the tracker")
|
||||
|
||||
.def("infinite_truncation", &TrackerT::SetInfiniteTruncation, "Decide whether the tracker should truncate infinite paths. See also infinite_truncation_tolerance")
|
||||
.def("infinite_truncation", &TrackerT::InfiniteTruncation, "Get the bool for whether the tracker should truncate infinite paths. See also infinite_truncation_tolerance")
|
||||
|
||||
.def("get_stepping",&TrackerT::template Get<tracking::SteppingConfig>,return_internal_reference<>(),"Get the tracker's internal configuration for things that control stepping behaviour")
|
||||
.def("get_newton",&TrackerT::template Get<tracking::NewtonConfig>,return_internal_reference<>(),"Get the tracker's internal configuration for Newton correction")
|
||||
.def("set_stepping",&TrackerT::template Set<tracking::SteppingConfig>,"Set the tracker's internal configuration for things that control stepping behaviour")
|
||||
.def("set_newton",&TrackerT::template Set<tracking::NewtonConfig>,"Set the tracker's internal configuration for Newton correction")
|
||||
|
||||
.def("current_point", &TrackerT::CurrentPoint)
|
||||
.def("current_time", &TrackerT::CurrentTime)
|
||||
.def("current_precision", &TrackerT::CurrentPrecision)
|
||||
|
||||
.def(ObservableVisitor<TrackerT>());
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
template<typename TrackerT>
|
||||
template<class PyClass>
|
||||
void AMPTrackerVisitor<TrackerT>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
.def("precision_setup", &TrackerT::PrecisionSetup)
|
||||
.def("precision_preservation", &TrackerT::PrecisionPreservation, "Turn on or off the preservation of precision. That is, if this is on (true), then the precision of the final point will be the precision of the start point. Generally, you want to let precision drift, methinks.")
|
||||
|
||||
.def("refine", return_Refine3_ptr<dbl>)
|
||||
.def("refine", return_Refine3_ptr<mpfr_complex>)
|
||||
.def("refine", return_Refine4_ptr<dbl>)
|
||||
.def("refine", return_Refine4_ptr<mpfr_complex>)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename TrackerT>
|
||||
template<class PyClass>
|
||||
void FixedDoubleTrackerVisitor<TrackerT>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
.def("refine", return_Refine3_ptr<dbl>)
|
||||
.def("refine", return_Refine4_ptr<dbl>)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
template<typename TrackerT>
|
||||
template<class PyClass>
|
||||
void FixedMultipleTrackerVisitor<TrackerT>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
.def("refine", return_Refine3_ptr<mpfr_complex>)
|
||||
.def("refine", return_Refine4_ptr<mpfr_complex>)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
template<class PyClass>
|
||||
void SteppingVisitor<T>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
.def_readwrite("initial_step_size", &tracking::SteppingConfig::initial_step_size,"The initial stepsize when tracking is started. See also tracking.AMPTracker.reinitialize_initial_step_size")
|
||||
.def_readwrite("max_step_size", &tracking::SteppingConfig::max_step_size,"The maximum allowed stepsize during tracking. See also min_num_steps")
|
||||
.def_readwrite("min_step_size", &tracking::SteppingConfig::min_step_size,"The minimum stepsize the tracker is allowed to take. See also max_step_size")
|
||||
.def_readwrite("step_size_success_factor", &tracking::SteppingConfig::step_size_success_factor,"The scale factor for stepsize, after some consecutive steps. See also consecutive_successful_steps_before_stepsize_increase")
|
||||
.def_readwrite("step_size_fail_factor", &tracking::SteppingConfig::step_size_fail_factor, "The scale factor for stepsize, after a fail happens. See also step_size_success_factor")
|
||||
.def_readwrite("consecutive_successful_steps_before_stepsize_increase", &tracking::SteppingConfig::consecutive_successful_steps_before_stepsize_increase,"This number of successful steps have to taken consecutively, and then the stepsize is permitted to increase")
|
||||
.def_readwrite("min_num_steps", &tracking::SteppingConfig::min_num_steps, "The minimum number of steps the tracker can take between now and then. This is useful if you are tracking closely between times, and want to guarantee some number of steps are taken. Then again, this could be wasteful, too.")
|
||||
.def_readwrite("max_num_steps", &tracking::SteppingConfig::max_num_steps, "The maximum number of steps. Tracking will die if it tries to take more than this number, sad day.")
|
||||
.def_readwrite("frequency_of_CN_estimation", &tracking::SteppingConfig::frequency_of_CN_estimation, "How frequently the condition number should be updated. Less frequently is faster (estimation requires an additional linear solve), but may cause precision adjustment to lag behind.")
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ExportTrackers()
|
||||
{
|
||||
scope current_scope;
|
||||
std::string new_submodule_name(extract<const char*>(current_scope.attr("__name__")));
|
||||
new_submodule_name.append(".tracking");
|
||||
object new_submodule(borrowed(PyImport_AddModule(new_submodule_name.c_str())));
|
||||
current_scope.attr("tracking") = new_submodule;
|
||||
|
||||
scope new_submodule_scope = new_submodule;
|
||||
new_submodule_scope.attr("__doc__") = "Tracking things for PyBertini. Includes the three fundamental trackers, and utility functions.";
|
||||
|
||||
ExportConfigSettings();
|
||||
ExportAMPTracker();
|
||||
ExportFixedTrackers();
|
||||
}
|
||||
|
||||
void ExportAMPTracker()
|
||||
{
|
||||
class_<AMPTracker, std::shared_ptr<AMPTracker> >("AMPTracker", "The adaptive multiple precision (AMP) tracker. Ambient numeric type is multiple-precision (mpfr_complex). Contruct one by feeding it a system -- cannot be constructed without feeding it a system. Adjust its settings via configs and the `setup` function. Then, call method `track_path`.", init<const System&>())
|
||||
.def(TrackerVisitor<AMPTracker>())
|
||||
.def(AMPTrackerVisitor<AMPTracker>())
|
||||
;
|
||||
}
|
||||
|
||||
void ExportFixedTrackers()
|
||||
{
|
||||
ExportFixedDoubleTracker();
|
||||
ExportFixedMultipleTracker();
|
||||
}
|
||||
|
||||
void ExportFixedDoubleTracker()
|
||||
{
|
||||
class_<DoublePrecisionTracker, std::shared_ptr<DoublePrecisionTracker> >("DoublePrecisionTracker", "The double precision tracker. Tracks using only complex doubles. Ambient numeric type is double. Contruct one by feeding it a system -- cannot be constructed without feeding it a system. Adjust its settings via configs and the `setup` function. Then, call method `track_path`.", init<const System&>())
|
||||
.def(TrackerVisitor<DoublePrecisionTracker>())
|
||||
.def(FixedDoubleTrackerVisitor<DoublePrecisionTracker>())
|
||||
;
|
||||
}
|
||||
|
||||
void ExportFixedMultipleTracker()
|
||||
{
|
||||
class_<MultiplePrecisionTracker, std::shared_ptr<MultiplePrecisionTracker> >("MultiplePrecisionTracker", "The fixed multiple precision tracker. Ambient numeric type is multiple-precision (mpfr_complex). Precision is the value of pybertini.default_precision() at contruction. Errors if you try to feed it things not at that precision. Contruct one by feeding it a system -- cannot be constructed without feeding it a system. Adjust its settings via configs and the `setup` function. Then, call method `track_path`.", init<const System&>())
|
||||
.def(TrackerVisitor<MultiplePrecisionTracker>())
|
||||
.def(FixedMultipleTrackerVisitor<MultiplePrecisionTracker>())
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ExportConfigSettings()
|
||||
{
|
||||
using namespace bertini::tracking;
|
||||
|
||||
enum_<Predictor>("Predictor")
|
||||
.value("Constant", Predictor::Constant)
|
||||
.value("Euler", Predictor::Euler)
|
||||
.value("Heun", Predictor::Heun)
|
||||
.value("RK4", Predictor::RK4)
|
||||
.value("HeunEuler", Predictor::HeunEuler)
|
||||
.value("RKNorsett34", Predictor::RKNorsett34)
|
||||
.value("RKF45", Predictor::RKF45)
|
||||
.value("RKCashKarp45", Predictor::RKCashKarp45)
|
||||
.value("RKDormandPrince56", Predictor::RKDormandPrince56)
|
||||
.value("RKVerner67", Predictor::RKVerner67)
|
||||
;
|
||||
|
||||
enum_<SuccessCode>("SuccessCode")
|
||||
.value("Success", SuccessCode::Success)
|
||||
.value("HigherPrecisionNecessary", SuccessCode::HigherPrecisionNecessary)
|
||||
.value("ReduceStepSize", SuccessCode::ReduceStepSize)
|
||||
.value("GoingToInfinity", SuccessCode::GoingToInfinity)
|
||||
.value("FailedToConverge", SuccessCode::FailedToConverge)
|
||||
.value("MatrixSolveFailure", SuccessCode::MatrixSolveFailure)
|
||||
.value("MatrixSolveFailureFirstPartOfPrediction", SuccessCode::MatrixSolveFailureFirstPartOfPrediction)
|
||||
.value("MaxNumStepsTaken", SuccessCode::MaxNumStepsTaken)
|
||||
.value("MaxPrecisionReached", SuccessCode::MaxPrecisionReached)
|
||||
.value("MinStepSizeReached", SuccessCode::MinStepSizeReached)
|
||||
.value("Failure", SuccessCode::Failure)
|
||||
.value("SingularStartPoint", SuccessCode::SingularStartPoint)
|
||||
.value("ExternallyTerminated", SuccessCode::ExternallyTerminated)
|
||||
.value("MinTrackTimeReached", SuccessCode::MinTrackTimeReached)
|
||||
.value("SecurityMaxNormReached", SuccessCode::SecurityMaxNormReached)
|
||||
.value("CycleNumTooHigh", SuccessCode::CycleNumTooHigh)
|
||||
;
|
||||
|
||||
{ // enter a scope for config types
|
||||
scope current_scope;
|
||||
std::string new_submodule_name(extract<const char*>(current_scope.attr("__name__")));
|
||||
new_submodule_name.append(".config");
|
||||
object new_submodule(borrowed(PyImport_AddModule(new_submodule_name.c_str())));
|
||||
current_scope.attr("config") = new_submodule;
|
||||
|
||||
scope new_submodule_scope = new_submodule;
|
||||
|
||||
|
||||
// class_<config::Tolerances<double>>("Tolerances_d",init<>())
|
||||
// .def(TolerancesVisitor<double>());
|
||||
|
||||
// class_<config::Tolerances<mpfr_float>>("Tolerances_mp",init<>())
|
||||
// .def(TolerancesVisitor<mpfr_float>());
|
||||
|
||||
class_<SteppingConfig, std::shared_ptr<SteppingConfig> >("SteppingConfig", init<>())
|
||||
.def(SteppingVisitor<double>())
|
||||
;
|
||||
|
||||
|
||||
class_<NewtonConfig, std::shared_ptr<NewtonConfig> >("NewtonConfig", init<>())
|
||||
.def_readwrite("max_num_newton_iterations", &NewtonConfig::max_num_newton_iterations)
|
||||
.def_readwrite("min_num_newton_iterations", &NewtonConfig::min_num_newton_iterations)
|
||||
;
|
||||
|
||||
|
||||
class_<FixedPrecisionConfig, std::shared_ptr<FixedPrecisionConfig> >("FixedPrecisionConfig", init<System const&>());
|
||||
|
||||
|
||||
|
||||
|
||||
class_<AdaptiveMultiplePrecisionConfig, std::shared_ptr<AdaptiveMultiplePrecisionConfig> >("AMPConfig", init<>())
|
||||
.def(init<System const&>())
|
||||
.def("set_amp_config_from", &AdaptiveMultiplePrecisionConfig::SetAMPConfigFrom)
|
||||
.def("set_phi_psi_from_bounds", &AdaptiveMultiplePrecisionConfig::SetPhiPsiFromBounds)
|
||||
.def("set_bounds_and_epsilon_from", &AdaptiveMultiplePrecisionConfig::SetBoundsAndEpsilonFrom)
|
||||
.def_readwrite("coefficient_bound", &AdaptiveMultiplePrecisionConfig::coefficient_bound)
|
||||
.def_readwrite("degree_bound", &AdaptiveMultiplePrecisionConfig::degree_bound)
|
||||
.def_readwrite("epsilon", &AdaptiveMultiplePrecisionConfig::epsilon)
|
||||
.def_readwrite("phi", &AdaptiveMultiplePrecisionConfig::Phi)
|
||||
.def_readwrite("psi", &AdaptiveMultiplePrecisionConfig::Psi)
|
||||
.def_readwrite("safety_digits_1", &AdaptiveMultiplePrecisionConfig::safety_digits_1)
|
||||
.def_readwrite("safety_digits_2", &AdaptiveMultiplePrecisionConfig::safety_digits_2)
|
||||
.def_readwrite("maximum_precision", &AdaptiveMultiplePrecisionConfig::maximum_precision)
|
||||
.def_readwrite("consecutive_successful_steps_before_precision_decrease", &AdaptiveMultiplePrecisionConfig::consecutive_successful_steps_before_precision_decrease)
|
||||
.def_readwrite("max_num_precision_decreases", &AdaptiveMultiplePrecisionConfig::max_num_precision_decreases)
|
||||
.def_readwrite("coefficient_bound", &AdaptiveMultiplePrecisionConfig::coefficient_bound)
|
||||
;
|
||||
|
||||
def("amp_config_from", &ConfigFrom, "make an AMPConfig from a System with generated settings for system-specific things, and default settings otherwise (such as safety digits).");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}} // namespaces
|
||||
|
||||
90
python/src/tracker_observers.cpp
Normal file
90
python/src/tracker_observers.cpp
Normal file
@@ -0,0 +1,90 @@
|
||||
//This file is part of Bertini 2.
|
||||
//
|
||||
//python/tracker_observers.cpp is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//python/tracker_observers.cpp is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with python/tracker_observers.cpp. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright(C) 2017-2018 by Bertini2 Development Team
|
||||
//
|
||||
// See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
// as well as COPYING. Bertini2 is provided with permitted
|
||||
// additional terms in the b2/licenses/ directory.
|
||||
|
||||
// individual authors of this file include:
|
||||
//
|
||||
// silviana amethyst
|
||||
// UWEC
|
||||
// Fall 2017, Spring 2018
|
||||
//
|
||||
//
|
||||
// python/tracker_observers.cpp: source file for exposing trackers to python.
|
||||
|
||||
|
||||
#include "tracker_observers.hpp"
|
||||
#include "generic_observer.hpp"
|
||||
|
||||
namespace bertini{
|
||||
namespace python{
|
||||
|
||||
|
||||
|
||||
|
||||
template <typename TrackerT>
|
||||
void ExportSpecificObservers(std::string scope_name)
|
||||
{
|
||||
scope scope_C;
|
||||
std::string submodule_name_C(extract<const char*>(scope_C.attr("__name__")));
|
||||
submodule_name_C.append("." + scope_name);
|
||||
object submodule_C(borrowed(PyImport_AddModule(submodule_name_C.c_str())));
|
||||
scope_C.attr(scope_name.c_str()) = submodule_C;
|
||||
scope new_submodule_scope_C = submodule_C;
|
||||
|
||||
class_<ObserverWrapper<Observer<TrackerT>>, bases<AnyObserver>, boost::noncopyable>("Abstract", init< >())
|
||||
;
|
||||
|
||||
class_< FirstPrecisionRecorder<TrackerT>, bases<Observer<TrackerT>> >("FirstPrecisionRecorder", init< >())
|
||||
.def(TrackingObserverVisitor<FirstPrecisionRecorder<TrackerT>>())
|
||||
;
|
||||
|
||||
class_<GoryDetailLogger<TrackerT>, bases<Observer<TrackerT>> >("GoryDetailLogger", init< >())
|
||||
.def(TrackingObserverVisitor<GoryDetailLogger<TrackerT>>())
|
||||
;
|
||||
}
|
||||
|
||||
void ExportTrackerObservers()
|
||||
{
|
||||
|
||||
scope current_scope;
|
||||
std::string new_submodule_name(extract<const char*>(current_scope.attr("__name__")));
|
||||
new_submodule_name.append(".tracking");
|
||||
object new_submodule(borrowed(PyImport_AddModule(new_submodule_name.c_str())));
|
||||
current_scope.attr("tracking") = new_submodule;
|
||||
|
||||
scope new_submodule_scope = new_submodule;
|
||||
new_submodule_scope.attr("__doc__") = "Tracking things for PyBertini. Includes the three fundamental trackers, and utility functions.";
|
||||
|
||||
{
|
||||
// this should be called in the tracking module namespace
|
||||
scope scope_B;
|
||||
std::string submodule_name_B(extract<const char*>(scope_B.attr("__name__")));
|
||||
submodule_name_B.append(".observers");
|
||||
object submodule_B(borrowed(PyImport_AddModule(submodule_name_B.c_str())));
|
||||
scope_B.attr("observers") = submodule_B;
|
||||
scope new_submodule_scope_B = submodule_B;
|
||||
|
||||
ExportSpecificObservers<AMPTracker>("amp");
|
||||
ExportSpecificObservers<DoublePrecisionTracker>("double");
|
||||
ExportSpecificObservers<MultiplePrecisionTracker>("multiple");
|
||||
}
|
||||
}
|
||||
|
||||
}} // namespaces
|
||||
251
python/src/zero_dim_export.cpp
Normal file
251
python/src/zero_dim_export.cpp
Normal file
@@ -0,0 +1,251 @@
|
||||
//This file is part of Bertini 2.
|
||||
//
|
||||
//python/zero_dim_export.cpp is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//python/zero_dim_export.cpp is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with python/zero_dim_export.cpp. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright(C) 2023 by Bertini2 Development Team
|
||||
//
|
||||
// See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
// as well as COPYING. Bertini2 is provided with permitted
|
||||
// additional terms in the b2/licenses/ directory.
|
||||
|
||||
// individual authors of this file include:
|
||||
//
|
||||
// silviana amethyst
|
||||
// University of Wisconsin-Eau Claire
|
||||
// 2023
|
||||
//
|
||||
//
|
||||
// python/zero_dim_export.cpp: source file for exposing the zero dim algorithm to python.
|
||||
|
||||
#include "zero_dim_export.hpp"
|
||||
|
||||
|
||||
|
||||
namespace bertini{
|
||||
namespace python{
|
||||
|
||||
template<typename AlgoT>
|
||||
template<class PyClass>
|
||||
void ZDVisitor<AlgoT>::visit(PyClass& cl) const
|
||||
{
|
||||
cl
|
||||
.def("solve", &AlgoT::Solve, "run the zero dim algorithm with currently stored settings")
|
||||
.def("get_tracker", GetTrackerMutable(), return_internal_reference<>(), "get a mutable reference to the Tracker being used")
|
||||
.def("get_endgame", GetEndgameMutable(), return_internal_reference<>(), "get a mutable reference to the Endgame being used")
|
||||
.def("solutions", &AlgoT::FinalSolutions, return_internal_reference<>(), "get the solutions at the target time")
|
||||
.def("solution_metadata", &AlgoT::FinalSolutionMetadata, return_internal_reference<>(), "get the metadata for the solutions at the target time")
|
||||
.def("endgame_boundary_data", &AlgoT::EndgameBoundaryData, return_internal_reference<>(), "get the data for the state at the endgame boundary (when we switch from regular tracking to endgame tracking")
|
||||
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void ExportZeroDim(){
|
||||
scope current_scope;
|
||||
std::string new_submodule_name(extract<const char*>(current_scope.attr("__name__")));
|
||||
new_submodule_name.append(".nag_algorithms");
|
||||
object new_submodule(borrowed(PyImport_AddModule(new_submodule_name.c_str())));
|
||||
current_scope.attr("nag_algorithms") = new_submodule;
|
||||
|
||||
|
||||
scope new_submodule_scope = new_submodule;
|
||||
new_submodule_scope.attr("__doc__") = "Algorithms for computing things, like point solutions to square systems (zerodim algorithm).";
|
||||
|
||||
|
||||
ExportZDConfigs();
|
||||
ExportZDAlgorithms();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// a helper function used immediately below. There is no declaration in the header file...
|
||||
template<typename TrackerT, typename EndgameT, typename SystemT, typename StartSystemT>
|
||||
void ExportZeroDimSpecific(std::string const& class_name){
|
||||
|
||||
using ZeroDimT = algorithm::ZeroDim<TrackerT, EndgameT, SystemT, StartSystemT>;
|
||||
|
||||
class_<ZeroDimT, std::shared_ptr<ZeroDimT> >(class_name.c_str(), init<SystemT>())
|
||||
.def(ZDVisitor<ZeroDimT>())
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void ExportZDAlgorithms(){
|
||||
|
||||
|
||||
|
||||
{
|
||||
using TrackerT = bertini::tracking::DoublePrecisionTracker;
|
||||
ExportZeroDimSpecific<TrackerT, bertini::endgame::EndgameSelector<TrackerT>::PSEG, bertini::System, bertini::start_system::TotalDegree>("ZeroDimPowerSeriesDoublePrecisionTotalDegree");
|
||||
ExportZeroDimSpecific<TrackerT, bertini::endgame::EndgameSelector<TrackerT>::Cauchy, bertini::System, bertini::start_system::TotalDegree>("ZeroDimCauchyDoublePrecisionTotalDegree");
|
||||
}
|
||||
|
||||
{
|
||||
using TrackerT = bertini::tracking::MultiplePrecisionTracker;
|
||||
ExportZeroDimSpecific<TrackerT, bertini::endgame::EndgameSelector<TrackerT>::PSEG, bertini::System, bertini::start_system::TotalDegree>("ZeroDimPowerSeriesFixedMultiplePrecisionTotalDegree");
|
||||
ExportZeroDimSpecific<TrackerT, bertini::endgame::EndgameSelector<TrackerT>::Cauchy, bertini::System, bertini::start_system::TotalDegree>("ZeroDimCauchyFixedMultiplePrecisionTotalDegree");
|
||||
}
|
||||
|
||||
{
|
||||
using TrackerT = bertini::tracking::AMPTracker;
|
||||
ExportZeroDimSpecific<TrackerT, bertini::endgame::EndgameSelector<TrackerT>::PSEG, bertini::System, bertini::start_system::TotalDegree>("ZeroDimPowerSeriesAdaptivePrecisionTotalDegree");
|
||||
ExportZeroDimSpecific<TrackerT, bertini::endgame::EndgameSelector<TrackerT>::Cauchy, bertini::System, bertini::start_system::TotalDegree>("ZeroDimCauchyAdaptivePrecisionTotalDegree");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ExportZDConfigs()
|
||||
{
|
||||
using namespace bertini::algorithm;
|
||||
|
||||
class_<TolerancesConfig>("TolerancesConfig", init<>())
|
||||
.def_readwrite("newton_before_endgame", &TolerancesConfig::newton_before_endgame)
|
||||
.def_readwrite("newton_during_endgame", &TolerancesConfig::newton_during_endgame)
|
||||
.def_readwrite("final_tolerance", &TolerancesConfig::final_tolerance)
|
||||
.def_readwrite("path_truncation_threshold", &TolerancesConfig::path_truncation_threshold)
|
||||
;
|
||||
|
||||
|
||||
class_<MidPathConfig>("MidPathConfig", init<>())
|
||||
.def_readwrite("same_point_tolerance", &MidPathConfig::same_point_tolerance)
|
||||
;
|
||||
|
||||
|
||||
class_<AutoRetrackConfig>("AutoRetrackConfig", init<>())
|
||||
.def_readwrite("midpath_decrease_tolerance_factor", &AutoRetrackConfig::midpath_decrease_tolerance_factor)
|
||||
;
|
||||
|
||||
|
||||
class_<SharpeningConfig>("SharpeningConfig", init<>())
|
||||
.def_readwrite("sharpendigits", &SharpeningConfig::sharpendigits)
|
||||
.def_readwrite("function_residual_tolerance", &SharpeningConfig::function_residual_tolerance)
|
||||
.def_readwrite("ratio_tolerance", &SharpeningConfig::ratio_tolerance)
|
||||
;
|
||||
|
||||
class_<RegenerationConfig>("RegenerationConfig", init<>())
|
||||
.def_readwrite("remove_infinite_endpoints", &RegenerationConfig::remove_infinite_endpoints)
|
||||
.def_readwrite("higher_dimension_check", &RegenerationConfig::higher_dimension_check)
|
||||
.def_readwrite("start_level", &RegenerationConfig::start_level)
|
||||
.def_readwrite("newton_before_endgame", &RegenerationConfig::newton_before_endgame)
|
||||
.def_readwrite("newton_during_endgame", &RegenerationConfig::newton_during_endgame)
|
||||
.def_readwrite("final_tolerance", &RegenerationConfig::final_tolerance)
|
||||
;
|
||||
|
||||
|
||||
class_<PostProcessingConfig>("PostProcessingConfig", init<>())
|
||||
.def_readwrite("real_threshold", &PostProcessingConfig::real_threshold)
|
||||
.def_readwrite("endpoint_finite_threshold", &PostProcessingConfig::endpoint_finite_threshold)
|
||||
.def_readwrite("same_point_tolerance", &PostProcessingConfig::same_point_tolerance)
|
||||
;
|
||||
|
||||
class_<ZeroDimConfig<dbl_complex>>("ZeroDimConfigDoublePrec", init<>())
|
||||
.def_readwrite("start_time", &ZeroDimConfig<dbl_complex>::start_time)
|
||||
.def_readwrite("target_time", &ZeroDimConfig<dbl_complex>::target_time)
|
||||
.def_readwrite("endgame_boundary", &ZeroDimConfig<dbl_complex>::endgame_boundary)
|
||||
;
|
||||
|
||||
class_<ZeroDimConfig<mpfr_complex>>("ZeroDimConfigMultiprec", init<>())
|
||||
.def_readwrite("start_time", &ZeroDimConfig<mpfr_complex>::start_time)
|
||||
.def_readwrite("target_time", &ZeroDimConfig<mpfr_complex>::target_time)
|
||||
.def_readwrite("endgame_boundary", &ZeroDimConfig<mpfr_complex>::endgame_boundary)
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename NumT>
|
||||
void ExposeSolutionMetaData(std::string const& class_name){
|
||||
using namespace bertini::algorithm;
|
||||
|
||||
using MDT = SolutionMetaData<NumT>;
|
||||
class_<MDT>(class_name.c_str(),init<>())
|
||||
.def_readwrite("path_index",&MDT::path_index)
|
||||
.def_readwrite("solution_index",&MDT::solution_index)
|
||||
|
||||
.def_readwrite("precision_changed",&MDT::precision_changed)
|
||||
.def_readwrite("time_of_first_prec_increase",&MDT::time_of_first_prec_increase)
|
||||
.def_readwrite("max_precision_used",&MDT::max_precision_used)
|
||||
|
||||
.def_readwrite("pre_endgame_success",&MDT::pre_endgame_success)
|
||||
|
||||
.def_readwrite("condition_number",&MDT::condition_number)
|
||||
.def_readwrite("newton_residual",&MDT::newton_residual)
|
||||
.def_readwrite("final_time_used",&MDT::final_time_used)
|
||||
.def_readwrite("accuracy_estimate",&MDT::accuracy_estimate)
|
||||
.def_readwrite("accuracy_estimate_user_coords",&MDT::accuracy_estimate_user_coords)
|
||||
.def_readwrite("cycle_num",&MDT::cycle_num)
|
||||
.def_readwrite("endgame_success",&MDT::endgame_success, "this is a SuccessCode. 0 means Success. Anything other than 0 means something happened.")
|
||||
|
||||
.def_readwrite("function_residual",&MDT::function_residual)
|
||||
|
||||
.def_readwrite("multiplicity",&MDT::multiplicity)
|
||||
.def_readwrite("is_real",&MDT::is_real)
|
||||
.def_readwrite("is_finite",&MDT::is_finite)
|
||||
.def_readwrite("is_singular",&MDT::is_singular)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename NumT>
|
||||
void ExposeEndgameBoundaryMetaData(std::string const& class_name){
|
||||
using namespace bertini::algorithm;
|
||||
|
||||
using MDT = EGBoundaryMetaData<NumT>;
|
||||
|
||||
class_<MDT>(class_name.c_str(),init<>())
|
||||
.def_readwrite("path_point",&MDT::path_point)
|
||||
.def_readwrite("success_code",&MDT::success_code)
|
||||
.def_readwrite("last_used_stepsize",&MDT::last_used_stepsize)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
void ExposeZDMetaData(){
|
||||
using namespace bertini::algorithm;
|
||||
|
||||
class_<AlgorithmMetaData>("AlgorithmMetaData",init<>())
|
||||
.def_readwrite("number_path_failures",&AlgorithmMetaData::number_path_failures)
|
||||
.def_readwrite("number_path_successes",&AlgorithmMetaData::number_path_successes)
|
||||
.def_readwrite("number_paths_tracked",&AlgorithmMetaData::number_paths_tracked)
|
||||
|
||||
.def_readwrite("start_time",&AlgorithmMetaData::start_time)
|
||||
.def_readwrite("elapsed_time",&AlgorithmMetaData::elapsed_time)
|
||||
;
|
||||
|
||||
ExposeSolutionMetaData<mpfr_complex>("SolutionMetaDataMultiPrec");
|
||||
ExposeSolutionMetaData<dbl_complex>("SolutionMetaDataDoublePrec");
|
||||
|
||||
|
||||
ExposeEndgameBoundaryMetaData<mpfr_complex>("EndgameBoundaryMetaDataMultiPrec");
|
||||
ExposeEndgameBoundaryMetaData<dbl_complex>("EndgameBoundaryMetaDataDoublePrec");
|
||||
|
||||
}
|
||||
|
||||
|
||||
}} // namespaces
|
||||
Reference in New Issue
Block a user