Beispiel #1
0
python::detail::new_reference dtype::convert(python::object const & arg, bool align) {
  PyArray_Descr* obj=NULL;
  if (align) {
    if (PyArray_DescrAlignConverter(arg.ptr(), &obj) < 0)
      python::throw_error_already_set();
  } else {
    if (PyArray_DescrConverter(arg.ptr(), &obj) < 0)
      python::throw_error_already_set();
  }
  return python::detail::new_reference(reinterpret_cast<PyObject*>(obj));
}
void set_type_mask(PairQuantity& obj,
        python::object smbli, python::object smblj, python::object msk,
        python::object others)
{
    using namespace std;
    if (Py_None != others.ptr())  mask_all_pairs(obj, others);
    python::extract<string> getsmbli(smbli);
    python::extract<string> getsmblj(smblj);
    bool mask = msk;
    // short circuit for normal call
    if (getsmbli.check() && getsmblj.check())
    {
        obj.setTypeMask(getsmbli(), getsmblj(), mask);
        return;
    }
    vector<string> isymbols = parsepairtypes(getsmbli, smbli);
    vector<string> jsymbols = parsepairtypes(getsmblj, smblj);
    vector<string>::const_iterator tii, tjj;
    for (tii = isymbols.begin(); tii != isymbols.end(); ++tii)
    {
        for (tjj = jsymbols.begin(); tjj != jsymbols.end(); ++tjj)
        {
            obj.setTypeMask(*tii, *tjj, mask);
        }
    }
}
void set_pair_mask(PairQuantity& obj,
        python::object i, python::object j, python::object msk,
        python::object others)
{
    if (Py_None != others.ptr())  mask_all_pairs(obj, others);
    python::extract<int> geti(i);
    python::extract<int> getj(j);
    bool mask = msk;
    // short circuit for normal call
    if (geti.check() && getj.check())
    {
        obj.setPairMask(geti(), getj(), mask);
        return;
    }
    std::vector<int> iindices = parsepairindex(i);
    std::vector<int> jindices = parsepairindex(j);
    std::vector<int>::const_iterator ii, jj;
    for (ii = iindices.begin(); ii != iindices.end(); ++ii)
    {
        for (jj = jindices.begin(); jj != jindices.end(); ++jj)
        {
            obj.setPairMask(*ii, *jj, mask);
        }
    }
}
 static
 python::object
 apply(python::object const & out_obj, OutArrService const & out_arr_service)
 {
     if(out_obj.ptr() == Py_None)
         return static_cast<python::object>(out_arr_service.get_arr());
     else
         return python::object();
 }
Beispiel #5
0
TailGF::TailGF(int OrderMinMIN_, int OrderMaxMAX_, python::object Arr, int OrderMax_, 
	       python::list IndicesL_,  python::list IndicesR_ ) :
  IndicesL(IndicesL_),IndicesR(IndicesR_),
  N1(int(PySequence_Size(IndicesL_.ptr()))),// int for 64bits
  N2(int(PySequence_Size(IndicesR_.ptr()))),// int for 64bits
  OrderMinMIN(OrderMinMIN_),OrderMaxMAX(OrderMaxMAX_),
  M(Arr.ptr()),
  OrderMaxArray(N1,N2,COrder)
 {
   if (M.shape() != TinyVector<int,3>(OrderMaxMAX - OrderMinMIN +1,N1,N2)) TRIQS_RUNTIME_ERROR<<"Reconstruction : size mismatch";
   M.reindexSelf(TinyVector<int,3>(OrderMinMIN,1,1));
   OrderMaxArray = OrderMax_;
 } 
std::vector<string> PythonConsoleViewImpl::getMemberNames(python::object& moduleObject)
{
    PyObject* pPyObject = moduleObject.ptr();
    if(pPyObject == NULL){
        return std::vector<string>();
    }
    python::handle<> h( PyObject_Dir(pPyObject) );
    python::list memberNames = python::extract<python::list>(python::object(h));
    std::vector<string> retNames;
    for(int i=0; i < python::len(memberNames); ++i){
        if(!strstr(string(python::extract<string>(memberNames[i])).c_str(), "__" )) retNames.push_back(string(python::extract<string>(memberNames[i])));
    }
    return retNames;
}
Beispiel #7
0
	Poco::SharedPtr<Poco::DynamicAny> RecordHelper::pythonObjectToAny(python::object obj)
	{
		if (PyBool_Check(obj.ptr()))
		{
			return new Poco::DynamicAny(python::extract<bool>(obj)());
		}
		else if (PyInt_Check(obj.ptr()))
		{
			return new Poco::DynamicAny(python::extract<long>(obj)());
		}
		else if (PyLong_Check(obj.ptr()))
		{
			return new Poco::DynamicAny(python::extract<long>(obj)());
		}
		else if (PyFloat_Check(obj.ptr()))
		{
			return new Poco::DynamicAny(python::extract<double>(obj)());
		}
		else if (PyString_Check(obj.ptr()))
		{
			return new Poco::DynamicAny(python::extract<std::string>(obj)());
		}
		else if (PyUnicode_Check(obj.ptr()))
		{
			return new Poco::DynamicAny(python::extract<std::string>(python::str(obj))());
		}
		else if (PyList_Check(obj.ptr()) || PyTuple_Check(obj.ptr()))
		{
			ssize_t max = python::len(obj);
			ssize_t i = 0;
			std::vector<Poco::DynamicAny> result;
			for (; i < max; ++i)
			{
				python::object item = obj[i];
				result.push_back(*pythonObjectToAny(item));
			}
			return new Poco::DynamicAny(result);
		}
		else
		{
			throw SmartCubeError("Unsupported Python object type.");
		}
		return NULL;
	}
Beispiel #8
0
  System::System(python::object _pyobj) {

    //This is defined in mpi4py.h
    //struct __pyx_obj_6mpi4py_3MPI_Comm {
    //  PyObject_HEAD
    //  MPI_Comm ob_mpi;
    //  int flags;
    //};
    
    // Following is some extreme typecasting which we need to convert the
    // pmi python object pmi._MPIcomm into a shared_ptr< boost::mpi::communicator >
    // I have not yet figured out how to do it in a more elegant way
    PyObject *pyobj = _pyobj.ptr();
    // in mpi4py.1.2.1 this has to be:
    // __pyx_obj_6mpi4py_3MPI_Comm * pyMPIComm = (__pyx_obj_6mpi4py_3MPI_Comm *) pyobj;
    // in version >= mpi4py.1.2.2 this has to be:
    PyMPICommObject* pyMPIComm = (PyMPICommObject*) pyobj;
    MPI_Comm * comm_p = &pyMPIComm->ob_mpi;
    shared_ptr< mpi::communicator > newcomm = make_shared< mpi::communicator >(*comm_p, mpi::comm_attach);

    comm = newcomm;
    maxCutoff = 0.0;
  }