MADNESS 0.10.1
Public Member Functions | Private Member Functions | Private Attributes | List of all members
PyFunctor< T, NDIM > Class Template Reference

#include <py_functor.h>

Inheritance diagram for PyFunctor< T, NDIM >:
Inheritance graph
[legend]
Collaboration diagram for PyFunctor< T, NDIM >:
Collaboration graph
[legend]

Public Member Functions

 PyFunctor (py::object f)
 
 ~PyFunctor ()
 
void operator() (const madness::Vector< double *, 1 > &xvals, T *fvals, int npts) const override
 
void operator() (const madness::Vector< double *, 2 > &xvals, T *fvals, int npts) const override
 
void operator() (const madness::Vector< double *, 3 > &xvals, T *fvals, int npts) const override
 
void operator() (const madness::Vector< double *, 4 > &xvals, T *fvals, int npts) const override
 
void operator() (const madness::Vector< double *, 5 > &xvals, T *fvals, int npts) const override
 
void operator() (const madness::Vector< double *, 6 > &xvals, T *fvals, int npts) const override
 
T operator() (const madness::Vector< double, NDIM > &r) const override
 You should implement this to return f(x)
 
bool supports_vectorized () const override
 Does the interface support a vectorized operator()?
 
- Public Member Functions inherited from madness::FunctionFunctorInterface< T, NDIM >
 FunctionFunctorInterface ()
 
virtual ~FunctionFunctorInterface ()
 
virtual coeffT coeff (const keyT &) const
 
virtual bool provides_coeff () const
 does this functor directly provide sum coefficients? or only function values?
 
virtual bool screened (const Vector< double, NDIM > &c1, const Vector< double, NDIM > &c2) const
 Can we screen this function based on the bounding box information?
 
void set_length_scale (double lo)
 adapt the special level to resolve the smallest length scale
 
virtual Level special_level () const
 Override this to change the minimum level of refinement at special points (default is 6)
 
virtual std::vector< Vector< double, NDIM > > special_points () const
 Override this to return list of special points to be refined more deeply.
 
virtual coeffT values (const keyT &key, const Tensor< double > &tensor) const
 

Private Member Functions

void eval_scalar_loop (const py::array_t< double > &coords, T *fvals, int npts) const
 Evaluate the callable per-point using scalar convention (still 1 GIL acquisition).
 
void eval_vectorized (const madness::Vector< double *, NDIM > &xvals, T *fvals, int npts) const
 

Private Attributes

py::object py_callable_
 
std::atomic< int > vectorized_mode_ {0}
 

Additional Inherited Members

- Public Types inherited from madness::FunctionFunctorInterface< T, NDIM >
typedef GenTensor< TcoeffT
 
typedef Key< NDIMkeyT
 
typedef T value_type
 
- Public Attributes inherited from madness::FunctionFunctorInterface< T, NDIM >
Level special_level_
 

Detailed Description

template<typename T, std::size_t NDIM>
class PyFunctor< T, NDIM >

Wraps a Python callable as a MADNESS FunctionFunctorInterface<T,NDIM>.

Supports two calling conventions:

The vectorized path is always used (supports_vectorized() returns true). On the first batch call, we probe the callable to detect which convention it uses and cache the result.

Constructor & Destructor Documentation

◆ PyFunctor()

template<typename T , std::size_t NDIM>
PyFunctor< T, NDIM >::PyFunctor ( py::object  f)
inlineexplicit

◆ ~PyFunctor()

template<typename T , std::size_t NDIM>
PyFunctor< T, NDIM >::~PyFunctor ( )
inline

Member Function Documentation

◆ eval_scalar_loop()

template<typename T , std::size_t NDIM>
void PyFunctor< T, NDIM >::eval_scalar_loop ( const py::array_t< double > &  coords,
T fvals,
int  npts 
) const
inlineprivate

Evaluate the callable per-point using scalar convention (still 1 GIL acquisition).

References d, NDIM, npts, PyFunctor< T, NDIM >::py_callable_, and T().

Referenced by PyFunctor< T, NDIM >::eval_vectorized().

◆ eval_vectorized()

template<typename T , std::size_t NDIM>
void PyFunctor< T, NDIM >::eval_vectorized ( const madness::Vector< double *, NDIM > &  xvals,
T fvals,
int  npts 
) const
inlineprivate

◆ operator()() [1/7]

template<typename T , std::size_t NDIM>
void PyFunctor< T, NDIM >::operator() ( const madness::Vector< double *, 1 > &  xvals,
T fvals,
int  npts 
) const
inlineoverridevirtual

◆ operator()() [2/7]

template<typename T , std::size_t NDIM>
void PyFunctor< T, NDIM >::operator() ( const madness::Vector< double *, 2 > &  xvals,
T fvals,
int  npts 
) const
inlineoverridevirtual

◆ operator()() [3/7]

template<typename T , std::size_t NDIM>
void PyFunctor< T, NDIM >::operator() ( const madness::Vector< double *, 3 > &  xvals,
T fvals,
int  npts 
) const
inlineoverridevirtual

◆ operator()() [4/7]

template<typename T , std::size_t NDIM>
void PyFunctor< T, NDIM >::operator() ( const madness::Vector< double *, 4 > &  xvals,
T fvals,
int  npts 
) const
inlineoverridevirtual

◆ operator()() [5/7]

template<typename T , std::size_t NDIM>
void PyFunctor< T, NDIM >::operator() ( const madness::Vector< double *, 5 > &  xvals,
T fvals,
int  npts 
) const
inlineoverridevirtual

◆ operator()() [6/7]

template<typename T , std::size_t NDIM>
void PyFunctor< T, NDIM >::operator() ( const madness::Vector< double *, 6 > &  xvals,
T fvals,
int  npts 
) const
inlineoverridevirtual

◆ operator()() [7/7]

template<typename T , std::size_t NDIM>
T PyFunctor< T, NDIM >::operator() ( const madness::Vector< double, NDIM > &  x) const
inlineoverridevirtual

You should implement this to return f(x)

Implements madness::FunctionFunctorInterface< T, NDIM >.

References NDIM, PyFunctor< T, NDIM >::py_callable_, and T().

◆ supports_vectorized()

template<typename T , std::size_t NDIM>
bool PyFunctor< T, NDIM >::supports_vectorized ( ) const
inlineoverridevirtual

Does the interface support a vectorized operator()?

Reimplemented from madness::FunctionFunctorInterface< T, NDIM >.

Member Data Documentation

◆ py_callable_

template<typename T , std::size_t NDIM>
py::object PyFunctor< T, NDIM >::py_callable_
private

◆ vectorized_mode_

template<typename T , std::size_t NDIM>
std::atomic<int> PyFunctor< T, NDIM >::vectorized_mode_ {0}
mutableprivate

The documentation for this class was generated from the following file: