Questions tagged [pyobject]

This is a type which contains the information Python needs to treat a pointer to an object as an object.

Definition

All object types are extensions of this type. This is a type which contains the information Python needs to treat a pointer to an object as an object. In a normal “release” build, it contains only the object’s reference count and a pointer to the corresponding type object. It corresponds to the fields defined by the expansion of the PyObject_HEAD macro.

Documentation

Common Object Structures

70 questions
0
votes
0 answers

template T type can not convert size_t

I use template but I get error I dont know why. there is no PyInt_FromInt function. template void PyGiveArguments(PyObject* Obj,T arg) { Obj = PyTuple_New(PyTuple_GET_SIZE(Obj)+1); if (std::is_same::value) { …
0
votes
1 answer

Extracting char* from a str PyObject in Python 3

Have anybody tried extracting a char* from a Python 3 PyObject* having type name str? Normal strings in Python 3 have type name str in the C API. For Python 2 one can use PyString_Check() and PyString_AsStringAndSize present in the header…
Nordlöw
  • 11,838
  • 10
  • 52
  • 99
0
votes
1 answer

use ctypes.py_object to implement array class in python

This is first part of code. from ctypes import py_object from typing import TypeVar, Generic T = TypeVar('T') class ArrayR(Generic[T]): def __init__(self, length: int) -> None: """ Creates an array of references to objects of the…
Blue
  • 1
  • 2
0
votes
0 answers

C-Numpy: How to create non-fixed-width ndarray of strings from existing string vector?

I'm writing a Python extension module in C++ with PyObject and arrayobject. My question is based on "How to create fixed-width ndarray of strings", which provided a solution to create a fixed-width nparray of strings such as list = {"Rx", "Rx",…
Cyan
  • 319
  • 2
  • 8
0
votes
1 answer

pass a list as an argument from python to C++: Segmentation fault (core dumped) when running the second time

I am coding a self-defined python module embedding with C++. test.py import my_module column_names = ['ukey', 'OrderRef', 'orderSize'] print(my_module.my_func(column_names)) my_module.cpp (partial) static PyObject * my_func(PyObject *self, PyObject…
Cyan
  • 319
  • 2
  • 8
0
votes
1 answer

How does ctypes.c_int differs from ctypes.py_object?

I understand that multiplying a ctype with an integer is declaring an array. For example, ctypes.c_int * 4 is an array of 4 integers. Then what is py_object? Please help me understand how does ctypes.c_int differs from ctypes.py_object?
meallhour
  • 13,921
  • 21
  • 60
  • 117
0
votes
1 answer

Cast C++ PyTorch Tensor to Python PyTorch Tensor

For a project that I am working on, I need to call from C++ a Python function, which has as input a PyTorch Tensor. While searching for a way to achieve this, I found that using a function named THPVariable_Wrap (Information I have found link 1 and…
J.vR
  • 21
  • 4
0
votes
0 answers

What is the problem with `PySet_Contains` when calling Py func in C?

I write C source code like this, aiming to accelerate the Python code with C, so I include some py object and func in C: include header file Python.h and dynamic link file libpython3.8.so. // test.h #include "Python.h" #include //…
dongrixinyu
  • 172
  • 2
  • 14
0
votes
0 answers

Is it possible to use directly PyObject reference in a function?

I am a novice in Python and I am trying to create a little animation of the linear convolution. from matplotlib import pyplot as plt from matplotlib import animation import math def creer_y1(): y1=[] return y1 def update_y1(i,y1): …
0
votes
0 answers

Issues with accessing PyObjects after writing

I am trying to do some fairly simple list manipulation, using a Jupyter notebook that calls a DLL function. I'd like my Jupyter notebook/Python code to pass in a Python list to a C++ function, which modifies the list, and then I'd like the Python…
0
votes
0 answers

PyBytes_FromString returning a None object

I was wondering if I could get some help. Say I've got the following function to serialize an object: PyObject * CKKSwrapper::SerializeContext() { std::string s; std::ostringstream os(s); Serial::Serialize(m_cc, os, SerType::BINARY); …
IanQ
  • 1,831
  • 5
  • 20
  • 29
0
votes
0 answers

Struggling to install pyobject-1.0

I have developed some python code on Windows 3.9.0 environment. I run pip freeze prog.py > requirements.txt. I then tried to re-create a similar environment on my RaspberryPi running Python v3.7.3. However, sudo pip install -r requirements.txt is…
0
votes
0 answers

Cython: return double * heap array from cython function to python as a 1D np.ndarray

I am trying to generate time series noise. My noise array are ~350,000 in size so they must be heap allocated. How can I return my heap allocated array back to the python code that called the function when the function is called? I have tried…
Danny Diaz
  • 375
  • 1
  • 4
  • 12
0
votes
0 answers

How can I create and return an array of extensions in cython?

I want to create a function, which creates a 2d array of cdef class cdef PyObject* create(): cdef PyObject* cells[2][2] cdef Cell cell for i in range(2): for j in range(2): cell = Cell(i, j)# def class Cell: ... …
d-t
  • 153
  • 1
  • 1
  • 10
0
votes
2 answers

Is it possible to assign an C++ pointer to an attribute of a Python object, and retrieve it as a C++ pointer in another C++ function?

I'm making a C++ extension for Python, and I'm trying to do something like: // this function assigns a C++ pointer to as attribute of a python object void function1(PyObject* p){ // equivalent of p.attr = cpp_attr; MyClass* cpp_attr = new…
qwerty_99
  • 640
  • 5
  • 20