Fix formatting issues in the Reference Manual.
This commit is contained in:
parent
beaa4b0e4d
commit
2a8823f745
@ -13,24 +13,29 @@ synopsis
|
||||
|
||||
::
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace numpy
|
||||
{
|
||||
namespace boost
|
||||
{
|
||||
namespace numpy
|
||||
{
|
||||
|
||||
template <typename TBinaryFunctor,typename TArgument1=typename TBinaryFunctor::first_argument_type,typename TArgument2=typename
|
||||
TBinaryFunctor::second_argument_type,typename TResult=typename TBinaryFunctor::result_type>
|
||||
template <typename TBinaryFunctor,
|
||||
typename TArgument1=typename TBinaryFunctor::first_argument_type,
|
||||
typename TArgument2=typename TBinaryFunctor::second_argument_type,
|
||||
typename TResult=typename TBinaryFunctor::result_type>
|
||||
|
||||
struct binary_ufunc
|
||||
{
|
||||
struct binary_ufunc
|
||||
{
|
||||
|
||||
static python::object call(TBinaryFunctor & self, python::object const & input1, python::object const & input2,python::object const & output)
|
||||
static python::object call(TBinaryFunctor & self,
|
||||
python::object const & input1,
|
||||
python::object const & input2,
|
||||
python::object const & output);
|
||||
|
||||
static python::object make();
|
||||
static python::object make();
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
constructors
|
||||
@ -38,12 +43,12 @@ constructors
|
||||
|
||||
::
|
||||
|
||||
struct example_binary_ufunc
|
||||
{
|
||||
typedef any_valid first_argument_type;
|
||||
typedef any_valid second_argument_type;
|
||||
typedef any_valid result_type;
|
||||
};
|
||||
struct example_binary_ufunc
|
||||
{
|
||||
typedef any_valid first_argument_type;
|
||||
typedef any_valid second_argument_type;
|
||||
typedef any_valid result_type;
|
||||
};
|
||||
|
||||
:Requirements: The ``any_valid`` type must be defined using typedef as a valid C++ type in order to use the struct methods correctly
|
||||
|
||||
@ -54,9 +59,13 @@ accessors
|
||||
|
||||
::
|
||||
|
||||
template <typename TBinaryFunctor,typename TArgument1=typename TBinaryFunctor::first_argument_type,typename TArgument2=typename
|
||||
TBinaryFunctor::second_argument_type,typename TResult=typename TBinaryFunctor::result_type>
|
||||
static python::object call(TBinaryFunctor & self, python::object const & input, python::object const & output) ;
|
||||
template <typename TBinaryFunctor,
|
||||
typename TArgument1=typename TBinaryFunctor::first_argument_type,
|
||||
typename TArgument2=typename TBinaryFunctor::second_argument_type,
|
||||
typename TResult=typename TBinaryFunctor::result_type>
|
||||
static python::object call(TBinaryFunctor & self,
|
||||
python::object const & input,
|
||||
python::object const & output);
|
||||
|
||||
:Requires: Typenames ``TBinaryFunctor`` and optionally ``TArgument1`` and ``TArgument2`` for argument type and ``TResult`` for result type
|
||||
|
||||
@ -64,32 +73,32 @@ accessors
|
||||
|
||||
::
|
||||
|
||||
template <typename TBinaryFunctor,typename TArgument1=typename TBinaryFunctor::first_argument_type,typename TArgument2=typename,
|
||||
TBinaryFunctor::second_argument_type,typename TResult=typename TBinaryFunctor::result_type>
|
||||
static python::object make();
|
||||
template <typename TBinaryFunctor,
|
||||
typename TArgument1=typename TBinaryFunctor::first_argument_type,
|
||||
typename TArgument2=typename TBinaryFunctor::second_argument_type,
|
||||
typename TResult=typename TBinaryFunctor::result_type>
|
||||
static python::object make();
|
||||
|
||||
:Requires: Typenames ``TBinaryFunctor`` and optionally ``TArgument1`` and ``TArgument2`` for argument type and ``TResult`` for result type
|
||||
|
||||
:Returns: A Python function object to call the overloaded () operator in the struct (in typical usage)
|
||||
|
||||
|
||||
|
||||
Example(s)
|
||||
----------
|
||||
|
||||
::
|
||||
|
||||
struct BinarySquare
|
||||
{
|
||||
typedef double first_argument_type;
|
||||
typedef double second_argument_type;
|
||||
typedef double result_type;
|
||||
struct BinarySquare
|
||||
{
|
||||
typedef double first_argument_type;
|
||||
typedef double second_argument_type;
|
||||
typedef double result_type;
|
||||
|
||||
double operator()(double a,double b) const { return (a*a + b*b) ; }
|
||||
};
|
||||
double operator()(double a,double b) const { return (a*a + b*b) ; }
|
||||
};
|
||||
|
||||
p::object ud = p::class_<BinarySquare, boost::shared_ptr<BinarySquare> >("BinarySquare").def("__call__", np::binary_ufunc<BinarySquare>::make());
|
||||
p::object inst = ud();
|
||||
result_array = inst.attr("__call__")(demo_array,demo_array) ;
|
||||
std::cout << "Square of list with binary ufunc is " << p::extract <char const * > (p::str(result_array)) << std::endl ;
|
||||
p::object ud = p::class_<BinarySquare, boost::shared_ptr<BinarySquare> >("BinarySquare").def("__call__", np::binary_ufunc<BinarySquare>::make());
|
||||
p::object inst = ud();
|
||||
result_array = inst.attr("__call__")(demo_array,demo_array) ;
|
||||
std::cout << "Square of list with binary ufunc is " << p::extract <char const * > (p::str(result_array)) << std::endl ;
|
||||
|
||||
|
@ -15,38 +15,39 @@ synopsis
|
||||
|
||||
::
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace numpy
|
||||
{
|
||||
namespace boost
|
||||
{
|
||||
namespace numpy
|
||||
{
|
||||
|
||||
class dtype : public python::object
|
||||
{
|
||||
static python::detail::new_reference convert(python::object::object_cref arg, bool align);
|
||||
public:
|
||||
class dtype : public python::object
|
||||
{
|
||||
static python::detail::new_reference convert(python::object::object_cref arg, bool align);
|
||||
public:
|
||||
|
||||
// Convert an arbitrary Python object to a data-type descriptor object.
|
||||
template <typename T>
|
||||
explicit dtype(T arg, bool align=false);
|
||||
// Convert an arbitrary Python object to a data-type descriptor object.
|
||||
template <typename T>
|
||||
explicit dtype(T arg, bool align=false);
|
||||
|
||||
// Get the built-in numpy dtype associated with the given scalar template type.
|
||||
template <typename T> static dtype get_builtin();
|
||||
// Get the built-in numpy dtype associated with the given scalar template type.
|
||||
template <typename T> static dtype get_builtin();
|
||||
|
||||
// Return the size of the data type in bytes.
|
||||
int get_itemsize() const;
|
||||
};
|
||||
// Return the size of the data type in bytes.
|
||||
int get_itemsize() const;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
constructors
|
||||
------------
|
||||
|
||||
::
|
||||
|
||||
template <typename T>
|
||||
explicit dtype(T arg, bool align=false)
|
||||
template <typename T>
|
||||
explicit dtype(T arg, bool align=false)
|
||||
|
||||
:Requirements: ``T`` must be either :
|
||||
|
||||
:Requirements: The typename supplied, ``T`` must be either :
|
||||
* a built-in C++ typename convertible to object
|
||||
* a valid python object or convertible to object
|
||||
|
||||
@ -57,7 +58,7 @@ constructors
|
||||
|
||||
::
|
||||
|
||||
template <typename T> static dtype get_builtin();
|
||||
template <typename T> static dtype get_builtin();
|
||||
|
||||
:Requirements: The typename supplied, ``T`` must be a builtin C++ type also supported by numpy
|
||||
|
||||
@ -68,7 +69,7 @@ accessors
|
||||
|
||||
::
|
||||
|
||||
int get_itemsize() const;
|
||||
int get_itemsize() const;
|
||||
|
||||
:Returns: the size of the data type in bytes.
|
||||
|
||||
@ -78,10 +79,8 @@ Example(s)
|
||||
|
||||
::
|
||||
|
||||
namespace np = boost::numpy ;
|
||||
|
||||
np::dtype dtype = np::dtype::get_builtin<double>();
|
||||
|
||||
p::tuple for_custom_dtype = p::make_tuple("ha",dtype) ;
|
||||
np::dtype custom_dtype = np::dtype(list_for_dtype) ;
|
||||
namespace np = boost::numpy;
|
||||
np::dtype dtype = np::dtype::get_builtin<double>();
|
||||
p::tuple for_custom_dtype = p::make_tuple("ha",dtype);
|
||||
np::dtype custom_dtype = np::dtype(list_for_dtype);
|
||||
|
||||
|
@ -13,32 +13,29 @@ synopsis
|
||||
|
||||
::
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace numpy
|
||||
{
|
||||
namespace boost
|
||||
{
|
||||
namespace numpy
|
||||
{
|
||||
|
||||
class multi_iter : public python::object
|
||||
{
|
||||
public:
|
||||
void next();
|
||||
bool not_done() const;
|
||||
char * get_data(int n) const;
|
||||
int const get_nd() const;
|
||||
Py_intptr_t const * get_shape() const;
|
||||
Py_intptr_t const shape(int n) const;
|
||||
|
||||
};
|
||||
class multi_iter : public python::object
|
||||
{
|
||||
public:
|
||||
void next();
|
||||
bool not_done() const;
|
||||
char * get_data(int n) const;
|
||||
int const get_nd() const;
|
||||
Py_intptr_t const * get_shape() const;
|
||||
Py_intptr_t const shape(int n) const;
|
||||
};
|
||||
|
||||
|
||||
multi_iter make_multi_iter(python::object const & a1);
|
||||
multi_iter make_multi_iter(python::object const & a1);
|
||||
multi_iter make_multi_iter(python::object const & a1, python::object const & a2);
|
||||
multi_iter make_multi_iter(python::object const & a1, python::object const & a2, python::object const & a3);
|
||||
|
||||
multi_iter make_multi_iter(python::object const & a1, python::object const & a2);
|
||||
|
||||
multi_iter make_multi_iter(python::object const & a1, python::object const & a2, python::object const & a3);
|
||||
|
||||
}
|
||||
} // namespace boost::numpy
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
constructors
|
||||
@ -46,11 +43,9 @@ constructors
|
||||
|
||||
::
|
||||
|
||||
multi_iter make_multi_iter(python::object const & a1);
|
||||
|
||||
multi_iter make_multi_iter(python::object const & a1, python::object const & a2);
|
||||
|
||||
multi_iter make_multi_iter(python::object const & a1, python::object const & a2, python::object const & a3);
|
||||
multi_iter make_multi_iter(python::object const & a1);
|
||||
multi_iter make_multi_iter(python::object const & a1, python::object const & a2);
|
||||
multi_iter make_multi_iter(python::object const & a1, python::object const & a2, python::object const & a3);
|
||||
|
||||
:Returns: A Python iterator object broadcasting over one, two or three sequences as supplied
|
||||
|
||||
@ -59,37 +54,37 @@ accessors
|
||||
|
||||
::
|
||||
|
||||
void next();
|
||||
void next();
|
||||
|
||||
:Effects: Increments the iterator
|
||||
|
||||
::
|
||||
|
||||
bool not_done() const;
|
||||
bool not_done() const;
|
||||
|
||||
:Returns: boolean value indicating whether the iterator is at its end
|
||||
|
||||
::
|
||||
|
||||
char * get_data(int n) const;
|
||||
char * get_data(int n) const;
|
||||
|
||||
:Returns: a pointer to the element of the nth broadcasted array.
|
||||
|
||||
::
|
||||
|
||||
int const get_nd() const;
|
||||
int const get_nd() const;
|
||||
|
||||
:Returns: the number of dimensions of the broadcasted array expression
|
||||
|
||||
::
|
||||
|
||||
Py_intptr_t const * get_shape() const;
|
||||
Py_intptr_t const * get_shape() const;
|
||||
|
||||
:Returns: the shape of the broadcasted array expression as an array of integers.
|
||||
|
||||
::
|
||||
|
||||
Py_intptr_t const shape(int n) const;
|
||||
Py_intptr_t const shape(int n) const;
|
||||
|
||||
:Returns: the shape of the broadcasted array expression in the nth dimension.
|
||||
|
||||
|
@ -17,73 +17,70 @@ synopsis
|
||||
|
||||
::
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace numpy
|
||||
{
|
||||
namespace boost
|
||||
{
|
||||
namespace numpy
|
||||
{
|
||||
|
||||
class ndarray : public python::object
|
||||
{
|
||||
class ndarray : public python::object
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
enum bitflag
|
||||
{
|
||||
NONE=0x0, C_CONTIGUOUS=0x1, F_CONTIGUOUS=0x2, V_CONTIGUOUS=0x1|0x2,
|
||||
ALIGNED=0x4, WRITEABLE=0x8, BEHAVED=0x4|0x8,
|
||||
CARRAY_RO=0x1|0x4, CARRAY=0x1|0x4|0x8, CARRAY_MIS=0x1|0x8,
|
||||
FARRAY_RO=0x2|0x4, FARRAY=0x2|0x4|0x8, FARRAY_MIS=0x2|0x8,
|
||||
UPDATE_ALL=0x1|0x2|0x4, VARRAY=0x1|0x2|0x8, ALL=0x1|0x2|0x4|0x8
|
||||
};
|
||||
public:
|
||||
|
||||
enum bitflag
|
||||
{
|
||||
NONE=0x0, C_CONTIGUOUS=0x1, F_CONTIGUOUS=0x2, V_CONTIGUOUS=0x1|0x2,
|
||||
ALIGNED=0x4, WRITEABLE=0x8, BEHAVED=0x4|0x8,
|
||||
CARRAY_RO=0x1|0x4, CARRAY=0x1|0x4|0x8, CARRAY_MIS=0x1|0x8,
|
||||
FARRAY_RO=0x2|0x4, FARRAY=0x2|0x4|0x8, FARRAY_MIS=0x2|0x8,
|
||||
UPDATE_ALL=0x1|0x2|0x4, VARRAY=0x1|0x2|0x8, ALL=0x1|0x2|0x4|0x8
|
||||
};
|
||||
|
||||
ndarray view(dtype const & dt) const;
|
||||
ndarray copy() const;
|
||||
int const shape(int n) const;
|
||||
int const strides(int n) const;
|
||||
char * get_data() const;
|
||||
dtype get_dtype() const;
|
||||
python::object get_base() const;
|
||||
void set_base(object const & base);
|
||||
Py_intptr_t const * get_shape() const;
|
||||
Py_intptr_t const * get_strides() const;
|
||||
int const get_nd() const;
|
||||
|
||||
bitflag const get_flags() const;
|
||||
|
||||
ndarray transpose() const;
|
||||
|
||||
ndarray squeeze() const;
|
||||
|
||||
ndarray reshape(python::tuple const & shape) const;
|
||||
|
||||
python::object scalarize() const;
|
||||
};
|
||||
ndarray view(dtype const & dt) const;
|
||||
ndarray copy() const;
|
||||
int const shape(int n) const;
|
||||
int const strides(int n) const;
|
||||
char * get_data() const;
|
||||
dtype get_dtype() const;
|
||||
python::object get_base() const;
|
||||
void set_base(object const & base);
|
||||
Py_intptr_t const * get_shape() const;
|
||||
Py_intptr_t const * get_strides() const;
|
||||
int const get_nd() const;
|
||||
|
||||
bitflag const get_flags() const;
|
||||
|
||||
ndarray transpose() const;
|
||||
ndarray squeeze() const;
|
||||
ndarray reshape(python::tuple const & shape) const;
|
||||
python::object scalarize() const;
|
||||
};
|
||||
|
||||
ndarray zeros(python::tuple const & shape, dtype const & dt);
|
||||
ndarray zeros(int nd, Py_intptr_t const * shape, dtype const & dt);
|
||||
ndarray zeros(python::tuple const & shape, dtype const & dt);
|
||||
ndarray zeros(int nd, Py_intptr_t const * shape, dtype const & dt);
|
||||
|
||||
ndarray empty(python::tuple const & shape, dtype const & dt);
|
||||
ndarray empty(int nd, Py_intptr_t const * shape, dtype const & dt);
|
||||
ndarray empty(python::tuple const & shape, dtype const & dt);
|
||||
ndarray empty(int nd, Py_intptr_t const * shape, dtype const & dt);
|
||||
|
||||
ndarray array(python::object const & obj);
|
||||
ndarray array(python::object const & obj, dtype const & dt);
|
||||
ndarray array(python::object const & obj);
|
||||
ndarray array(python::object const & obj, dtype const & dt);
|
||||
|
||||
template <typename Container>
|
||||
ndarray from_data(void * data,dtype const & dt,Container shape,Container strides,python::object const & owner);
|
||||
template <typename Container>
|
||||
ndarray from_data(void const * data, dtype const & dt, Container shape, Container strides, python::object const & owner);
|
||||
template <typename Container>
|
||||
ndarray from_data(void * data,dtype const & dt,Container shape,Container strides,python::object const & owner);
|
||||
template <typename Container>
|
||||
ndarray from_data(void const * data, dtype const & dt, Container shape, Container strides, python::object const & owner);
|
||||
|
||||
ndarray from_object(python::object const & obj, dtype const & dt,int nd_min, int nd_max, ndarray::bitflag flags=ndarray::NONE);
|
||||
ndarray from_object(python::object const & obj, dtype const & dt,int nd, ndarray::bitflag flags=ndarray::NONE);
|
||||
ndarray from_object(python::object const & obj, dtype const & dt, ndarray::bitflag flags=ndarray::NONE);
|
||||
ndarray from_object(python::object const & obj, int nd_min, int nd_max,ndarray::bitflag flags=ndarray::NONE);
|
||||
ndarray from_object(python::object const & obj, int nd, ndarray::bitflag flags=ndarray::NONE);
|
||||
ndarray from_object(python::object const & obj, ndarray::bitflag flags=ndarray::NONE)
|
||||
ndarray from_object(python::object const & obj, dtype const & dt,int nd_min, int nd_max, ndarray::bitflag flags=ndarray::NONE);
|
||||
ndarray from_object(python::object const & obj, dtype const & dt,int nd, ndarray::bitflag flags=ndarray::NONE);
|
||||
ndarray from_object(python::object const & obj, dtype const & dt, ndarray::bitflag flags=ndarray::NONE);
|
||||
ndarray from_object(python::object const & obj, int nd_min, int nd_max,ndarray::bitflag flags=ndarray::NONE);
|
||||
ndarray from_object(python::object const & obj, int nd, ndarray::bitflag flags=ndarray::NONE);
|
||||
ndarray from_object(python::object const & obj, ndarray::bitflag flags=ndarray::NONE)
|
||||
|
||||
ndarray::bitflag operator|(ndarray::bitflag a, ndarray::bitflag b) ;
|
||||
ndarray::bitflag operator&(ndarray::bitflag a, ndarray::bitflag b);
|
||||
ndarray::bitflag operator|(ndarray::bitflag a, ndarray::bitflag b) ;
|
||||
ndarray::bitflag operator&(ndarray::bitflag a, ndarray::bitflag b);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
constructors
|
||||
@ -91,31 +88,31 @@ constructors
|
||||
|
||||
::
|
||||
|
||||
ndarray view(dtype const & dt) const;
|
||||
ndarray view(dtype const & dt) const;
|
||||
|
||||
:Returns: new ndarray with old ndarray data cast as supplied dtype
|
||||
|
||||
::
|
||||
|
||||
ndarray copy() const;
|
||||
ndarray copy() const;
|
||||
|
||||
:Returns: Copy of calling ndarray object
|
||||
|
||||
::
|
||||
|
||||
ndarray transpose() const;
|
||||
ndarray transpose() const;
|
||||
|
||||
:Returns: An ndarray with the rows and columns interchanged
|
||||
|
||||
::
|
||||
|
||||
ndarray squeeze() const;
|
||||
ndarray squeeze() const;
|
||||
|
||||
:Returns: An ndarray with all unit-shaped dimensions removed
|
||||
|
||||
::
|
||||
|
||||
ndarray reshape(python::tuple const & shape) const;
|
||||
ndarray reshape(python::tuple const & shape) const;
|
||||
|
||||
:Requirements: The new ``shape`` of the ndarray must be supplied as a tuple
|
||||
|
||||
@ -124,16 +121,17 @@ constructors
|
||||
|
||||
::
|
||||
|
||||
python::object scalarize() const;
|
||||
python::object scalarize() const;
|
||||
|
||||
:Returns: A scalar if the ndarray has only one element, otherwise it returns the entire array
|
||||
|
||||
::
|
||||
|
||||
ndarray zeros(python::tuple const & shape, dtype const & dt);
|
||||
ndarray zeros(int nd, Py_intptr_t const * shape, dtype const & dt);
|
||||
ndarray zeros(python::tuple const & shape, dtype const & dt);
|
||||
ndarray zeros(int nd, Py_intptr_t const * shape, dtype const & dt);
|
||||
|
||||
:Requirements: The following parameters must be supplied as required :
|
||||
|
||||
* the ``shape`` or the size of all dimensions, as a tuple
|
||||
* the ``dtype`` of the data
|
||||
* the ``nd`` size for a square shaped ndarray
|
||||
@ -143,11 +141,12 @@ constructors
|
||||
|
||||
::
|
||||
|
||||
ndarray empty(python::tuple const & shape, dtype const & dt);
|
||||
ndarray empty(int nd, Py_intptr_t const * shape, dtype const & dt);
|
||||
ndarray empty(python::tuple const & shape, dtype const & dt);
|
||||
ndarray empty(int nd, Py_intptr_t const * shape, dtype const & dt);
|
||||
|
||||
|
||||
:Requirements: The following parameters must be supplied :
|
||||
|
||||
* the ``shape`` or the size of all dimensions, as a tuple
|
||||
* the ``dtype`` of the data
|
||||
* the ``shape`` Py_intptr_t
|
||||
@ -156,17 +155,18 @@ constructors
|
||||
|
||||
::
|
||||
|
||||
ndarray array(python::object const & obj);
|
||||
ndarray array(python::object const & obj, dtype const & dt);
|
||||
ndarray array(python::object const & obj);
|
||||
ndarray array(python::object const & obj, dtype const & dt);
|
||||
|
||||
:Returns: A new ndarray from an arbitrary Python sequence, with dtype of each element specified optionally
|
||||
|
||||
::
|
||||
|
||||
template <typename Container>
|
||||
inline ndarray from_data(void * data,dtype const & dt,Container shape,Container strides,python::object const & owner)
|
||||
template <typename Container>
|
||||
inline ndarray from_data(void * data,dtype const & dt,Container shape,Container strides,python::object const & owner)
|
||||
|
||||
:Requirements: The following parameters must be supplied :
|
||||
|
||||
* the ``data`` which is a generic C++ data container
|
||||
* the dtype ``dt`` of the data
|
||||
* the ``shape`` of the ndarray as Python object
|
||||
@ -179,9 +179,10 @@ constructors
|
||||
|
||||
::
|
||||
|
||||
ndarray from_object(python::object const & obj, dtype const & dt,int nd_min, int nd_max, ndarray::bitflag flags=ndarray::NONE);
|
||||
ndarray from_object(python::object const & obj, dtype const & dt,int nd_min, int nd_max, ndarray::bitflag flags=ndarray::NONE);
|
||||
|
||||
:Requirements: The following parameters must be supplied :
|
||||
|
||||
* the ``obj`` Python object to convert to ndarray
|
||||
* the dtype ``dt`` of the data
|
||||
* minimum number of dimensions ``nd_min`` of the ndarray as Python object
|
||||
@ -192,9 +193,10 @@ constructors
|
||||
|
||||
::
|
||||
|
||||
inline ndarray from_object(python::object const & obj, dtype const & dt, int nd, ndarray::bitflag flags=ndarray::NONE);
|
||||
inline ndarray from_object(python::object const & obj, dtype const & dt, int nd, ndarray::bitflag flags=ndarray::NONE);
|
||||
|
||||
:Requirements: The following parameters must be supplied :
|
||||
|
||||
* the ``obj`` Python object to convert to ndarray
|
||||
* the dtype ``dt`` of the data
|
||||
* number of dimensions ``nd`` of the ndarray as Python object
|
||||
@ -204,9 +206,10 @@ constructors
|
||||
|
||||
::
|
||||
|
||||
inline ndarray from_object(python::object const & obj, dtype const & dt, ndarray::bitflag flags=ndarray::NONE)
|
||||
inline ndarray from_object(python::object const & obj, dtype const & dt, ndarray::bitflag flags=ndarray::NONE)
|
||||
|
||||
:Requirements: The following parameters must be supplied :
|
||||
|
||||
* the ``obj`` Python object to convert to ndarray
|
||||
* the dtype ``dt`` of the data
|
||||
* optional ``flags`` bitflags
|
||||
@ -215,9 +218,10 @@ constructors
|
||||
|
||||
::
|
||||
|
||||
ndarray from_object(python::object const & obj, int nd_min, int nd_max, ndarray::bitflag flags=ndarray::NONE);
|
||||
ndarray from_object(python::object const & obj, int nd_min, int nd_max, ndarray::bitflag flags=ndarray::NONE);
|
||||
|
||||
:Requirements: The following parameters must be supplied :
|
||||
|
||||
* the ``obj`` Python object to convert to ndarray
|
||||
* minimum number of dimensions ``nd_min`` of the ndarray as Python object
|
||||
* maximum number of dimensions ``nd_max`` of the ndarray as Python object
|
||||
@ -229,9 +233,10 @@ constructors
|
||||
|
||||
::
|
||||
|
||||
inline ndarray from_object(python::object const & obj, int nd, ndarray::bitflag flags=ndarray::NONE);
|
||||
inline ndarray from_object(python::object const & obj, int nd, ndarray::bitflag flags=ndarray::NONE);
|
||||
|
||||
:Requirements: The following parameters must be supplied :
|
||||
|
||||
* the ``obj`` Python object to convert to ndarray
|
||||
* the dtype ``dt`` of the data
|
||||
* number of dimensions ``nd`` of the ndarray as Python object
|
||||
@ -241,9 +246,10 @@ constructors
|
||||
|
||||
::
|
||||
|
||||
inline ndarray from_object(python::object const & obj, ndarray::bitflag flags=ndarray::NONE)
|
||||
inline ndarray from_object(python::object const & obj, ndarray::bitflag flags=ndarray::NONE)
|
||||
|
||||
:Requirements: The following parameters must be supplied :
|
||||
|
||||
* the ``obj`` Python object to convert to ndarray
|
||||
* optional ``flags`` bitflags
|
||||
|
||||
@ -255,19 +261,19 @@ accessors
|
||||
|
||||
::
|
||||
|
||||
int const shape(int n) const;
|
||||
int const shape(int n) const;
|
||||
|
||||
:Returns: The size of the n-th dimension of the ndarray
|
||||
|
||||
::
|
||||
|
||||
int const strides(int n) const;
|
||||
int const strides(int n) const;
|
||||
|
||||
:Returns: The stride of the nth dimension.
|
||||
|
||||
::
|
||||
|
||||
char * get_data() const;
|
||||
char * get_data() const;
|
||||
|
||||
:Returns: Array's raw data pointer as a char
|
||||
|
||||
@ -275,61 +281,61 @@ accessors
|
||||
|
||||
::
|
||||
|
||||
dtype get_dtype() const;
|
||||
dtype get_dtype() const;
|
||||
|
||||
:Returns: Array's data-type descriptor object (dtype)
|
||||
|
||||
|
||||
::
|
||||
|
||||
python::object get_base() const;
|
||||
python::object get_base() const;
|
||||
|
||||
:Returns: Object that owns the array's data, or None if the array owns its own data.
|
||||
|
||||
|
||||
::
|
||||
|
||||
void set_base(object const & base);
|
||||
void set_base(object const & base);
|
||||
|
||||
:Returns: Set the object that owns the array's data. Exercise caution while using this
|
||||
|
||||
|
||||
::
|
||||
|
||||
Py_intptr_t const * get_shape() const;
|
||||
Py_intptr_t const * get_shape() const;
|
||||
|
||||
:Returns: Shape of the array as an array of integers
|
||||
|
||||
|
||||
::
|
||||
|
||||
Py_intptr_t const * get_strides() const;
|
||||
Py_intptr_t const * get_strides() const;
|
||||
|
||||
:Returns: Stride of the array as an array of integers
|
||||
|
||||
|
||||
::
|
||||
|
||||
int const get_nd() const;
|
||||
int const get_nd() const;
|
||||
|
||||
:Returns: Number of array dimensions
|
||||
|
||||
|
||||
::
|
||||
|
||||
bitflag const get_flags() const;
|
||||
bitflag const get_flags() const;
|
||||
|
||||
:Returns: Array flags
|
||||
|
||||
::
|
||||
|
||||
inline ndarray::bitflag operator|(ndarray::bitflag a, ndarray::bitflag b)
|
||||
inline ndarray::bitflag operator|(ndarray::bitflag a, ndarray::bitflag b)
|
||||
|
||||
:Returns: bitflag logically OR-ed as (a | b)
|
||||
|
||||
::
|
||||
|
||||
inline ndarray::bitflag operator&(ndarray::bitflag a, ndarray::bitflag b)
|
||||
inline ndarray::bitflag operator&(ndarray::bitflag a, ndarray::bitflag b)
|
||||
|
||||
:Returns: bitflag logically AND-ed as (a & b)
|
||||
|
||||
@ -339,26 +345,26 @@ Example(s)
|
||||
|
||||
::
|
||||
|
||||
p::object tu = p::make_tuple('a','b','c') ;
|
||||
np::ndarray example_tuple = np::array (tu) ;
|
||||
p::object tu = p::make_tuple('a','b','c') ;
|
||||
np::ndarray example_tuple = np::array (tu) ;
|
||||
|
||||
p::list l ;
|
||||
np::ndarray example_list = np::array (l) ;
|
||||
p::list l ;
|
||||
np::ndarray example_list = np::array (l) ;
|
||||
|
||||
np::dtype dt = np::dtype::get_builtin<int>();
|
||||
np::ndarray example_list1 = np::array (l,dt);
|
||||
np::dtype dt = np::dtype::get_builtin<int>();
|
||||
np::ndarray example_list1 = np::array (l,dt);
|
||||
|
||||
int data[] = {1,2,3,4} ;
|
||||
p::tuple shape = p::make_tuple(4) ;
|
||||
p::tuple stride = p::make_tuple(4) ;
|
||||
p::object own ;
|
||||
np::ndarray data_ex = np::from_data(data,dt,shape,stride,own);
|
||||
int data[] = {1,2,3,4} ;
|
||||
p::tuple shape = p::make_tuple(4) ;
|
||||
p::tuple stride = p::make_tuple(4) ;
|
||||
p::object own ;
|
||||
np::ndarray data_ex = np::from_data(data,dt,shape,stride,own);
|
||||
|
||||
uint8_t mul_data[][4] = {{1,2,3,4},{5,6,7,8},{1,3,5,7}};
|
||||
shape = p::make_tuple(3,2) ;
|
||||
stride = p::make_tuple(4,2) ;
|
||||
np::dtype dt1 = np::dtype::get_builtin<uint8_t>();
|
||||
uint8_t mul_data[][4] = {{1,2,3,4},{5,6,7,8},{1,3,5,7}};
|
||||
shape = p::make_tuple(3,2) ;
|
||||
stride = p::make_tuple(4,2) ;
|
||||
np::dtype dt1 = np::dtype::get_builtin<uint8_t>();
|
||||
|
||||
np::ndarray mul_data_ex = np::from_data(mul_data,dt1, p::make_tuple(3,4),p::make_tuple(4,1),p::object());
|
||||
mul_data_ex = np::from_data(mul_data,dt1, shape,stride,p::object());
|
||||
np::ndarray mul_data_ex = np::from_data(mul_data,dt1, p::make_tuple(3,4),p::make_tuple(4,1),p::object());
|
||||
mul_data_ex = np::from_data(mul_data,dt1, shape,stride,p::object());
|
||||
|
||||
|
@ -13,22 +13,26 @@ synopsis
|
||||
|
||||
::
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace numpy
|
||||
{
|
||||
namespace boost
|
||||
{
|
||||
namespace numpy
|
||||
{
|
||||
|
||||
template <typename TUnaryFunctor, typename TArgument=typename TUnaryFunctor::argument_type, typename TResult=typename TUnaryFunctor::result_type>
|
||||
struct unary_ufunc
|
||||
{
|
||||
template <typename TUnaryFunctor,
|
||||
typename TArgument=typename TUnaryFunctor::argument_type,
|
||||
typename TResult=typename TUnaryFunctor::result_type>
|
||||
struct unary_ufunc
|
||||
{
|
||||
|
||||
static python::object call(TUnaryFunctor & self, python::object const & input, python::object const & output) ;
|
||||
static python::object call(TUnaryFunctor & self,
|
||||
python::object const & input,
|
||||
python::object const & output) ;
|
||||
|
||||
static python::object make();
|
||||
static python::object make();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
constructors
|
||||
@ -36,11 +40,11 @@ constructors
|
||||
|
||||
::
|
||||
|
||||
struct example_unary_ufunc
|
||||
{
|
||||
typedef any_valid_type argument_type;
|
||||
typedef any_valid_type result_type;
|
||||
};
|
||||
struct example_unary_ufunc
|
||||
{
|
||||
typedef any_valid_type argument_type;
|
||||
typedef any_valid_type result_type;
|
||||
};
|
||||
|
||||
:Requirements: The ``any_valid`` type must be defined using typedef as a valid C++ type in order to use the struct methods correctly
|
||||
|
||||
@ -51,8 +55,12 @@ accessors
|
||||
|
||||
::
|
||||
|
||||
template <typename TUnaryFunctor, typename TArgument=typename TUnaryFunctor::argument_type,typename TResult=typename TUnaryFunctor::result_type>
|
||||
static python::object call(TUnaryFunctor & self, python::object const & input, python::object const & output) ;
|
||||
template <typename TUnaryFunctor,
|
||||
typename TArgument=typename TUnaryFunctor::argument_type,
|
||||
typename TResult=typename TUnaryFunctor::result_type>
|
||||
static python::object call(TUnaryFunctor & self,
|
||||
python::object const & input,
|
||||
python::object const & output);
|
||||
|
||||
:Requires: Typenames ``TUnaryFunctor`` and optionally ``TArgument`` for argument type and ``TResult`` for result type
|
||||
|
||||
@ -60,8 +68,10 @@ accessors
|
||||
|
||||
::
|
||||
|
||||
template <typename TUnaryFunctor, typename TArgument=typename TUnaryFunctor::argument_type,typename TResult=typename TUnaryFunctor::result_type>
|
||||
static python::object make();
|
||||
template <typename TUnaryFunctor,
|
||||
typename TArgument=typename TUnaryFunctor::argument_type,
|
||||
typename TResult=typename TUnaryFunctor::result_type>
|
||||
static python::object make();
|
||||
|
||||
:Requires: Typenames ``TUnaryFunctor`` and optionally ``TArgument`` for argument type and ``TResult`` for result type
|
||||
|
||||
@ -74,14 +84,14 @@ Example(s)
|
||||
|
||||
::
|
||||
|
||||
struct UnarySquare
|
||||
{
|
||||
typedef double argument_type;
|
||||
typedef double result_type;
|
||||
double operator()(double r) const { return r * r;}
|
||||
};
|
||||
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 << "Square of unary scalar 1.0 is " << p::extract <char const * > (p::str(inst.attr("__call__")(1.0))) << std::endl ;
|
||||
p::object ud = p::class_<UnarySquare, boost::shared_ptr<UnarySquare> >("UnarySquare").def("__call__", np::unary_ufunc<UnarySquare>::make());
|
||||
p::object inst = ud();
|
||||
std::cout << "Square of unary scalar 1.0 is " << p::extract <char const * > (p::str(inst.attr("__call__")(1.0))) << std::endl ;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user