Skip to content

Commit

Permalink
Moved dunders to impl__ implementation in trees (#104)
Browse files Browse the repository at this point in the history


Co-authored-by: Roberto Di Remigio Eikås <roberto@totaltrash.xyz>
  • Loading branch information
bjorgve and robertodr committed Aug 26, 2023
1 parent a446b2b commit c0eb87c
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 194 deletions.
7 changes: 7 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,10 @@ def version_from_file(f):
"notebook_interface": "jupyterlab",
},
}

html_sidebars = {
"**": [
"searchbox.html",
"sbt-sidebar-nav.html",
]
}
5 changes: 3 additions & 2 deletions src/vampyr/core/bases.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ void bases(pybind11::module &m) {

py::class_<PyWaveletFunction, RepresentableFunction<1>>(m, "WaveletFunction");

py::class_<ScalingBasis>(m, "ScalingBasis",
R"mydelimiter(
py::class_<ScalingBasis>(m,
"ScalingBasis",
R"mydelimiter(
Filler text
)mydelimiter")
.def(py::init<int, int>(), "order"_a, "type"_a)
Expand Down
5 changes: 3 additions & 2 deletions src/vampyr/functions/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ template <int D> void functions(pybind11::module &m) {
using namespace pybind11::literals;

// RepresentableFunction class
py::class_<RepresentableFunction<D>, PyRepresentableFunction<D>>(m, "RepresentableFunction",
R"mydelimiter(
py::class_<RepresentableFunction<D>, PyRepresentableFunction<D>>(m,
"RepresentableFunction",
R"mydelimiter(
Filler text
)mydelimiter")
.def(py::init<const std::vector<double> &, const std::vector<double> &>())
Expand Down
44 changes: 24 additions & 20 deletions src/vampyr/functions/gaussians.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ template <int D> void gaussians(pybind11::module &m) {
using namespace pybind11::literals;

// Gaussian class
py::class_<Gaussian<D>, PyGaussian<D>, RepresentableFunction<D>>(m, "Gaussian",
R"mydelimiter(
py::class_<Gaussian<D>, PyGaussian<D>, RepresentableFunction<D>>(m,
"Gaussian",
R"mydelimiter(
Parameters
----------
Expand All @@ -39,8 +40,9 @@ template <int D> void gaussians(pybind11::module &m) {
});

// GaussFunc class
py::class_<GaussFunc<D>, PyGaussian<D, GaussFunc<D>>, Gaussian<D>>(m, "GaussFunc",
R"mydelimiter(
py::class_<GaussFunc<D>, PyGaussian<D, GaussFunc<D>>, Gaussian<D>>(m,
"GaussFunc",
R"mydelimiter(
An analytic Gaussian function in d dimensions:
.. math::
Expand Down Expand Up @@ -73,33 +75,35 @@ template <int D> void gaussians(pybind11::module &m) {
.def(
"differentiate",
[](const GaussFunc<D> &gauss, int dir) { return gauss.differentiate(dir).asGaussExp(); },
"dir"_a, "Differentiates the Gaussian along the specified axis.")
"dir"_a,
"Differentiates the Gaussian along the specified axis.")
.def("squaredNorm", &GaussFunc<D>::calcSquareNorm)
.def("calcCoulombEnergy", &GaussFunc<D>::calcCoulombEnergy,
.def("calcCoulombEnergy",
&GaussFunc<D>::calcCoulombEnergy,
R"mydelimiter(
Calculate energy interaction between this Gaussian and an input Gaussian.
Warning: power has to be a zero vector)mydelimiter");

// GaussExp class
py::class_<GaussExp<D>, RepresentableFunction<D>>(m, "GaussExp")
.def(py::init())
.def("size",
py::overload_cast<>(&GaussExp<D>::size, py::const_),
"Number of Gaussians in the GaussExp")
.def("size", py::overload_cast<>(&GaussExp<D>::size, py::const_), "Number of Gaussians in the GaussExp")
.def("func",
py::overload_cast<int>(&GaussExp<D>::getFunc),
"term"_a,
py::return_value_policy::reference_internal)
py::overload_cast<int>(&GaussExp<D>::getFunc),
"term"_a,
py::return_value_policy::reference_internal)
.def("append",
py::overload_cast<const Gaussian<D> &>(&GaussExp<D>::append),
"Append Gaussians to the end of the GaussExp")
.def("periodify", &GaussExp<D>::periodify,
"period"_a,
"std_dev"_a = 4.0,
"Make copies of the Gaussian to simulate periodicity, then append it to the GaussExp")
py::overload_cast<const Gaussian<D> &>(&GaussExp<D>::append),
"Append Gaussians to the end of the GaussExp")
.def("periodify",
&GaussExp<D>::periodify,
"period"_a,
"std_dev"_a = 4.0,
"Make copies of the Gaussian to simulate periodicity, then append it to the GaussExp")
.def("differentiate",
&GaussExp<D>::differentiate,
"dir"_a, "Differentiate all Gaussians in GaussExp along the specified axis")
&GaussExp<D>::differentiate,
"dir"_a,
"Differentiate all Gaussians in GaussExp along the specified axis")
.def("squaredNorm", &GaussExp<D>::calcSquareNorm)
.def("calcCoulombEnergy", &GaussExp<D>::calcCoulombEnergy)
.def("__str__", [](const GaussExp<D> &func) {
Expand Down
12 changes: 3 additions & 9 deletions src/vampyr/operators/convolutions.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

#include <pybind11/pybind11.h>

#include <MRCPP/operators/CartesianConvolution.h>
#include <MRCPP/operators/HelmholtzOperator.h>
#include <MRCPP/operators/IdentityConvolution.h>
#include <MRCPP/operators/PoissonOperator.h>
#include <MRCPP/operators/CartesianConvolution.h>
#include <MRCPP/treebuilders/apply.h>

namespace vampyr {
Expand All @@ -20,10 +20,7 @@ template <int D> void convolutions(pybind11::module &m) {
using namespace pybind11::literals;

py::class_<ConvolutionOperator<D>>(m, "ConvolutionOperator")
.def(py::init<const MultiResolutionAnalysis<D> &, GaussExp<1> &, double>(),
"mra"_a,
"kernel"_a,
"prec"_a)
.def(py::init<const MultiResolutionAnalysis<D> &, GaussExp<1> &, double>(), "mra"_a, "kernel"_a, "prec"_a)
.def(
"__call__",
[](ConvolutionOperator<D> &O, FunctionTree<D> *inp) {
Expand Down Expand Up @@ -60,10 +57,7 @@ void cartesian_convolution(pybind11::module &m) {
using namespace pybind11::literals;

py::class_<CartesianConvolution, ConvolutionOperator<3>>(m, "CartesianConvolution")
.def(py::init<const MultiResolutionAnalysis<3> &, GaussExp<1> &, double>(),
"mra"_a,
"kernel"_a,
"prec"_a)
.def(py::init<const MultiResolutionAnalysis<3> &, GaussExp<1> &, double>(), "mra"_a, "kernel"_a, "prec"_a)
.def(
"__call__",
[](CartesianConvolution &O, FunctionTree<3> *inp) {
Expand Down
6 changes: 3 additions & 3 deletions src/vampyr/treebuilders/project.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ template <int D> void project(pybind11::module &m) {
namespace py = pybind11;
using namespace pybind11::literals;

m.def("ZeroTree",
[](const MultiResolutionAnalysis<D> &mra,
const std::string &name) {
m.def(
"ZeroTree",
[](const MultiResolutionAnalysis<D> &mra, const std::string &name) {
auto out = std::make_unique<FunctionTree<D>>(mra, name);
out->setZero();
return out;
Expand Down

0 comments on commit c0eb87c

Please sign in to comment.