本文整理汇总了C++中boost::python::object::ptr方法的典型用法代码示例。如果您正苦于以下问题:C++ object::ptr方法的具体用法?C++ object::ptr怎么用?C++ object::ptr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::python::object
的用法示例。
在下文中一共展示了object::ptr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MaxMinPicks
// REVIEW: the poolSize can be pulled from the numeric array
RDKit::INT_VECT MaxMinPicks(MaxMinPicker *picker, python::object distMat,
int poolSize, int pickSize,
python::object firstPicks, int seed) {
if (pickSize >= poolSize) {
throw ValueErrorException("pickSize must be less than poolSize");
}
if (!PyArray_Check(distMat.ptr())) {
throw ValueErrorException("distance mat argument must be a numpy matrix");
}
PyArrayObject *copy;
copy = (PyArrayObject *)PyArray_ContiguousFromObject(distMat.ptr(),
PyArray_DOUBLE, 1, 1);
double *dMat = (double *)copy->data;
RDKit::INT_VECT firstPickVect;
for (unsigned int i = 0;
i < python::extract<unsigned int>(firstPicks.attr("__len__")()); ++i) {
firstPickVect.push_back(python::extract<int>(firstPicks[i]));
}
RDKit::INT_VECT res =
picker->pick(dMat, poolSize, pickSize, firstPickVect, seed);
Py_DECREF(copy);
return res;
}
示例2: it
TypeGeneral::EdgeData::EdgeData(const py::object& obj)
{
typedef TypeGeneral::REAL REAL;
bool isiterable = PyObject_HasAttrString(obj.ptr(), "__iter__");
if(isiterable)
{
py::stl_input_iterator<REAL> it(obj), end;
bool haslen = PyObject_HasAttrString(obj.ptr(), "__len__");
m_type = GENERAL;
if(haslen)
{
m_dataGeneral.resize(py::len(obj));
std::copy(it, end, m_dataGeneral.begin());
}
else
{
for(; it!=end; ++it)
{
m_dataGeneral.push_back(*it);
std::cout << *it << " ";
}
}
}
else
{
m_type = POTTS;
m_lambdaPotts = py::extract<REAL>(obj);
}
}
示例3: if
void SequenceTypeHandler<ContainerType>::set(Kernel::IPropertyManager* alg, const std::string &name,
const boost::python::object & value) const
{
using boost::python::len;
typedef typename ContainerType::value_type DestElementType;
// Current workaround for things that still pass back wrapped vectors...
if(boost::starts_with(value.ptr()->ob_type->tp_name, "std_vector"))
{
alg->setProperty(name, StdVectorExtractor<DestElementType>::extract(value));
}
// numpy arrays requires special handling to extract their types. Hand-off to a more appropriate handler
else if( PyArray_Check(value.ptr()) )
{
alg->setProperty(name, Converters::NDArrayToVector<DestElementType>(value)());
}
else if( PySequence_Check(value.ptr()) )
{
alg->setProperty(name, Converters::PySequenceToVector<DestElementType>(value)());
}
else // assume it is a scalar and try to convert into a vector of length one
{
DestElementType scalar = boost::python::extract<DestElementType>(value.ptr());
alg->setProperty(name, std::vector<DestElementType>(1, scalar));
}
}
示例4: call
void OutputHook::call(std::string name, boost::python::object obj)
{
Hooks::checkName(name);
auto repr_ = PyObject_Repr(obj.ptr());
if (PyErr_Occurred())
{
PyErr_Clear();
throw Hooks::Exception("Failed to get __repr__ of argument");
}
auto repr = std::string(PyUnicode_AsUTF8(repr_));
Py_DECREF(repr_);
PyObject* g = Py_BuildValue(
"{sO}", "__builtins__", PyEval_GetBuiltins());
node->parent->loadDatumHooks(g);
auto out = PyRun_String(repr.c_str(), Py_eval_input, g, g);
Py_DECREF(g);
Py_XDECREF(out);
if (PyErr_Occurred())
{
PyErr_Clear();
throw Hooks::Exception("Could not evaluate __repr__ of output");
}
const bool result = node->makeDatum(
name, obj.ptr()->ob_type, Datum::SIGIL_OUTPUT + repr, true);
if (!result)
throw Hooks::Exception("Datum was already defined in this script.");
}
示例5: pySurf
inGtsSurface(py::object _surf, bool _noPad=false): pySurf(_surf), noPad(_noPad), noPadWarned(false) {
if(!pygts_surface_check(_surf.ptr())) throw std::invalid_argument("Ctor must receive a gts.Surface() instance.");
surf=PYGTS_SURFACE_AS_GTS_SURFACE(PYGTS_SURFACE(_surf.ptr()));
if(!gts_surface_is_closed(surf)) throw std::invalid_argument("Surface is not closed.");
is_open=gts_surface_volume(surf)<0.;
if((tree=gts_bb_tree_surface(surf))==NULL) throw std::runtime_error("Could not create GTree.");
}
示例6: import
std::valarray<T> convert2valarray(boost::python::object arr)
{
import(); // ### WARNING: forgetting this will end up in segmentation fault!
std::size_t vec_size = PyArray_Size(arr.ptr());
T * data = (T *) PyArray_DATA(arr.ptr());
std::valarray<T> vec(vec_size);
memcpy(&vec[0],data, PyArray_ITEMSIZE((PyArrayObject*) arr.ptr()) * vec_size);
return vec;
}
示例7: send_alive
void send_alive(boost::python::object ad_obj=boost::python::object(), boost::python::object pid_obj=boost::python::object(), boost::python::object timeout_obj=boost::python::object())
{
std::string addr;
if (ad_obj.ptr() == Py_None)
{
char *inherit_var = getenv("CONDOR_INHERIT");
if (!inherit_var) {
THROW_EX(RuntimeError, "No location specified and $CONDOR_INHERIT not in Unix environment.");
}
std::string inherit(inherit_var);
boost::python::object inherit_obj(inherit);
boost::python::object inherit_split = inherit_obj.attr("split")();
if (py_len(inherit_split) < 2) {
THROW_EX(RuntimeError, "$CONDOR_INHERIT Unix environment variable malformed.");
}
addr = boost::python::extract<std::string>(inherit_split[1]);
}
else
{
const ClassAdWrapper ad = boost::python::extract<ClassAdWrapper>(ad_obj);
if (!ad.EvaluateAttrString(ATTR_MY_ADDRESS, addr))
{
THROW_EX(ValueError, "Address not available in location ClassAd.");
}
}
int pid = getpid();
if (pid_obj.ptr() != Py_None)
{
pid = boost::python::extract<int>(pid_obj);
}
int timeout;
if (timeout_obj.ptr() == Py_None)
{
timeout = param_integer("NOT_RESPONDING_TIMEOUT");
}
else
{
timeout = boost::python::extract<int>(timeout_obj);
}
if (timeout < 1) {
timeout = 1;
}
classy_counted_ptr<Daemon> daemon = new Daemon(DT_ANY, addr.c_str());
classy_counted_ptr<ChildAliveMsg> msg = new ChildAliveMsg(pid, timeout, 0, 0, true);
{
condor::ModuleLock ml;
daemon->sendBlockingMsg(msg.get());
}
if (msg->deliveryStatus() != DCMsg::DELIVERY_SUCCEEDED)
{
THROW_EX(RuntimeError, "Failed to deliver keepalive message.");
}
}
示例8: sequence_len
inline index_type sequence_len(boost::python::object const& obj){
if( !PySequence_Check( obj.ptr() ) ){
raise_error( PyExc_TypeError, "Sequence expected" );
}
index_type result = PyObject_Length( obj.ptr() );
if( PyErr_Occurred() ){
boost::python::throw_error_already_set();
}
return result;
}
示例9: checkRadii
// Used by multiple profile classes to ensure at most one radius is given.
static void checkRadii(const bp::object & r1, const bp::object & r2, const bp::object & r3)
{
int nRad = (r1.ptr() != Py_None) + (r2.ptr() != Py_None) + (r3.ptr() != Py_None);
if (nRad > 1) {
PyErr_SetString(PyExc_TypeError, "Multiple radius parameters given");
bp::throw_error_already_set();
}
if (nRad == 0) {
PyErr_SetString(PyExc_TypeError, "No radius parameter given");
bp::throw_error_already_set();
}
}
示例10: startd
void
delegateGSI(boost::python::object fname)
{
if (m_claim.empty()) {THROW_EX(ValueError, "No claim set for object.");}
std::string proxy_file;
if (fname.ptr() == Py_None)
{
proxy_file = get_x509_proxy_filename();
}
else
{
proxy_file = boost::python::extract<std::string>(fname);
}
DCStartd startd(m_addr.c_str());
startd.setClaimId(m_claim);
compat_classad::ClassAd reply;
int irval;
{
condor::ModuleLock ml;
irval = startd.delegateX509Proxy(proxy_file.c_str(), 0, NULL);
}
if (irval != OK) {THROW_EX(RuntimeError, "Startd failed to delegate GSI proxy.");}
}
示例11: A
boost::python::object test4( boost::python::object M, range const & R1, int j) {
cerr<<" entring test4 "<<endl;
array_view<long,2> A(M.ptr());
array_view<long,1> V(A(R1,j));
cerr<<" array python "<<A<<endl<<" return view "<<V<<endl;
return boost::python::object(V);
}
示例12: infoGain
double infoGain(python::object resArr) {
PyObject *matObj = resArr.ptr();
if (!PyArray_Check(matObj)) {
throw_value_error("Expecting a Numeric array object");
}
PyArrayObject *copy;
copy = (PyArrayObject *)PyArray_ContiguousFromObject(
matObj, PyArray_DESCR((PyArrayObject *)matObj)->type_num, 2, 2);
long int rows = (long int)PyArray_DIM((PyArrayObject *)matObj, 0);
long int cols = (long int)PyArray_DIM((PyArrayObject *)matObj, 1);
double res = 0.0;
if (PyArray_DESCR((PyArrayObject *)matObj)->type_num == NPY_DOUBLE) {
double *data = (double *)PyArray_DATA(copy);
res = InfoEntropyGain(data, rows, cols);
} else if (PyArray_DESCR((PyArrayObject *)matObj)->type_num == NPY_FLOAT) {
float *data = (float *)PyArray_DATA(copy);
res = InfoEntropyGain(data, rows, cols);
} else if (PyArray_DESCR((PyArrayObject *)matObj)->type_num == NPY_INT) {
int *data = (int *)PyArray_DATA(copy);
res = InfoEntropyGain(data, rows, cols);
} else if (PyArray_DESCR((PyArrayObject *)matObj)->type_num == NPY_LONG) {
long int *data = (long int *)PyArray_DATA(copy);
res = InfoEntropyGain(data, rows, cols);
} else {
throw_value_error(
"Numeric array object of type int or long or float or double");
}
Py_DECREF(copy);
return res;
}
示例13: infoEntropy
double infoEntropy(python::object resArr) {
PyObject *matObj = resArr.ptr();
if (!PyArray_Check(matObj)) {
throw_value_error("Expecting a Numeric array object");
}
PyArrayObject *copy;
copy = (PyArrayObject *)PyArray_ContiguousFromObject(
matObj, ((PyArrayObject *)matObj)->descr->type_num, 1, 1);
double res = 0.0;
// we are expecting a 1 dimensional array
long int ncols = (long int)((PyArrayObject *)matObj)->dimensions[0];
CHECK_INVARIANT(ncols > 0, "");
if (((PyArrayObject *)matObj)->descr->type_num == PyArray_DOUBLE) {
double *data = (double *)copy->data;
res = InfoEntropy(data, ncols);
} else if (((PyArrayObject *)matObj)->descr->type_num == PyArray_FLOAT) {
float *data = (float *)copy->data;
res = InfoEntropy(data, ncols);
} else if (((PyArrayObject *)matObj)->descr->type_num == PyArray_INT) {
int *data = (int *)copy->data;
res = InfoEntropy(data, ncols);
} else if (((PyArrayObject *)matObj)->descr->type_num == PyArray_LONG) {
long int *data = (long int *)copy->data;
res = InfoEntropy(data, ncols);
}
Py_DECREF(copy);
return res;
}
示例14: chiSquare
double chiSquare(python::object resArr) {
PyObject *matObj = resArr.ptr();
if (!PyArray_Check(matObj)) {
throw_value_error("Expecting a Numeric array object");
}
PyArrayObject *copy;
copy = (PyArrayObject *)PyArray_ContiguousFromObject(
matObj, ((PyArrayObject *)matObj)->descr->type_num, 2, 2);
long int rows = (long int)((PyArrayObject *)matObj)->dimensions[0];
long int cols = (long int)((PyArrayObject *)matObj)->dimensions[1];
double res = 0.0;
if (((PyArrayObject *)matObj)->descr->type_num == PyArray_DOUBLE) {
double *data = (double *)copy->data;
res = ChiSquare(data, rows, cols);
} else if (((PyArrayObject *)matObj)->descr->type_num == PyArray_FLOAT) {
float *data = (float *)copy->data;
res = ChiSquare(data, rows, cols);
} else if (((PyArrayObject *)matObj)->descr->type_num == PyArray_INT) {
int *data = (int *)copy->data;
res = ChiSquare(data, rows, cols);
} else if (((PyArrayObject *)matObj)->descr->type_num == PyArray_LONG) {
long int *data = (long int *)copy->data;
res = ChiSquare(data, rows, cols);
} else {
throw_value_error(
"Numeric array object of type int or long or float or double");
}
Py_DECREF(copy);
return res;
}
示例15: runtime_error
static py::object unpack( py::object bytes )
{
auto p = bytes.ptr();
if( !p )
{
throw std::runtime_error( "can't unpack: no object" );
}
const void * data = nullptr;
Py_ssize_t size = 0;
if( PyObject_AsReadBuffer( p, &data, &size ) )
{
py::throw_error_already_set();
}
if( !data || !size )
{
throw std::runtime_error( "can't unpack: no data" );
}
Unpacker unpacker( reinterpret_cast< char const * >( data ), size );
return unpacker.unpack();
}