unary_ufunc
-
template<typename TUnaryFunctor, typename TArgument = typename TUnaryFunctor::argument_type, typename TResult = typename TUnaryFunctor::result_type>
struct unary_ufunc unary_ufunc
は、単一引数をブロードキャストするための中間ステップとして使う構造体である。これにより C++ 関数が ufunc ライクな関数に変換可能となる。<boost/python/numpy/ufunc.hpp>
はunary_ufunc
構造体の定義をもつ。
概要
namespace boost
{
namespace python
{
namespace numpy
{
template <typename TUnaryFunctor,
typename TArgument=typename TUnaryFunctor::argument_type,
typename TResult=typename TUnaryFunctor::result_type>
struct unary_ufunc
{
static object call(TUnaryFunctor & self,
object const & input,
object const & output) ;
static object make();
};
}
}
}
コンストラクタ
アクセッサ
-
template<typename TUnaryFunctor, typename TArgument = typename TUnaryFunctor::argument_type, typename TResult = typename TUnaryFunctor::result_type>
static object call(TUnaryFunctor &self, object const &input, object const &output) - 要件
TUnaryFunctor
。および引数の型を表すTArgument
と戻り値の型を表すTResult
(いずれも省略可能)。- 効果
Python オブジェクトを、引数をブロードキャストした後 C++ 関数子に渡す。
-
template<typename TUnaryFunctor, typename TArgument = typename TUnaryFunctor::argument_type, typename TResult = typename TUnaryFunctor::result_type>
static object make() - 要件
TUnaryFunctor
。および引数の型を表すTArgument
と戻り値の型を表すTResult
(いずれも省略可能)。- 戻り値
(典型的な使い方として)構造体内で多重定義した
()
演算子を呼び出すための Python オブジェクト。
使用例
namespace p = boost::python;
namespace np = boost::python::numpy;
struct UnarySquare
{
typedef double argument_type;
typedef double result_type;
double operator()(double r) const { return r * r;}
};
p::object ud = p::class_<UnarySquare, boost::shared_ptr<UnarySquare> >("UnarySquare").def("__call__", np::unary_ufunc<UnarySquare>::make());
p::object inst = ud();
std::cout << "単項スカラー 1.0 の正方行列は " << p::extract <char const * > (p::str(inst.attr("__call__")(1.0))) << std::endl ;