I tried to use ctypes pythonapi to extract PyCapsule_New objects using
PyCapsule_GetPointer. But got erorr :
*ArgumentError: argument 1: TypeError: Don't know how to
convert parameter 1*
Attaching file
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Also, please tell me about the implementations for accessing opaque C
objects I will go through it
On Tuesday, January 30, 2024 at 8:58:43 PM UTC+5:30 Dima Pasechnik wrote:
> IMHO opaque C objects may be accessed from Python, it just needs an
> implementation
>
>
> On 29 January 2024 22:51:48 GMT, Nils Bruin <[email protected]> wrote:
>
>> By the looks of it, the routines you'd be using would be coming from
>> umfpack. cvxopt has chosen to package the details of LU factorization in
>> opaque objects and instead offer routines to use these decompositions (via
>> taking the opaque object as input). In scipy, umfpack is also used:
>> https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.linalg.spsolve.html#scipy.sparse.linalg.spsolve
>>
>> . Scipy also offers LU decomposition routines:
>> https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.linalg.splu.html#scipy.sparse.linalg.splu
>>
>> but that uses a different library. It looks suspicious that two packages
>> offer umfpack for solving sparse problems, but don't give explicit access
>> to LU factorizations produced in the process, when using UMFPACK. Perhaps
>> UMFPACK isn't suited to provide the explicit factorization (but it may be
>> very good at using its internally computed data).
>>
>>
>>
>>
--
You received this message because you are subscribed to the Google Groups
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sage-devel/b01b5f6c-bed7-4cc6-aa4d-37662587673cn%40googlegroups.com.
sage: a = cvxopt.spmatrix([int(1),int(1),int(1)], [int(0),int(1),int(2)],
[int(0),int(1),int(2)], (3,4))
sage: print(a)
[ 1.00e+00 0 0 0 ]
[ 0 1.00e+00 0 0 ]
[ 0 0 1.00e+00 0 ]
sage: b = cvxopt.umfpack.symbolic(a)
sage: c = cvxopt.umfpack.numeric(a, b)
sage: type(c)
<class 'PyCapsule'>
sage: pointer = ctypes.pythonapi.PyCapsule_GetPointer(c)
---------------------------------------------------------------------------
ArgumentError Traceback (most recent call last)
Cell In[40], line 1
----> 1 pointer = ctypes.pythonapi.PyCapsule_GetPointer(c)
ArgumentError: argument 1: TypeError: Don't know how to convert parameter 1
sage:
sage:
sage:
sage:
sage:
sage:
sage:
sage: lib_path_so = cvxopt.umfpack.__file__
sage: lib = ctypes.CDLL(lib_path_so)
sage: type(lib)
<class 'ctypes.CDLL'>
sage: lib
<CDLL
'/home/shay/sage/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/cvxopt/umfpack.cpython-310-x86_64-linux-gnu.so',
handle 555e561ab2d0 at 0x7f5a455c6320>
sage: cvxopt.umfpack.__dir__()
['__name__',
'__doc__',
'__package__',
'__loader__',
'__spec__',
'linsolve',
'symbolic',
'numeric',
'solve',
'__file__']
sage: lib.__dir__()
['_name',
'_FuncPtr',
'_handle',
'__module__',
'__doc__',
'_func_flags_',
'_func_restype_',
'__init__',
'__repr__',
'__getattr__',
'__getitem__',
'__dict__',
'__weakref__',
'__new__',
'__hash__',
'__str__',
'__getattribute__',
'__setattr__',
'__delattr__',
'__lt__',
'__le__',
'__eq__',
'__ne__',
'__gt__',
'__ge__',
'__reduce_ex__',
'__reduce__',
'__subclasshook__',
'__init_subclass__',
'__format__',
'__sizeof__',
'__dir__',
'__class__']
sage:
sage:
sage:
sage: lib.numeric.argtypes
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[47], line 1
----> 1 lib.numeric.argtypes
File /usr/lib/python3.10/ctypes/__init__.py:387, in CDLL.__getattr__(self, name)
385 if name.startswith('__') and name.endswith('__'):
386 raise AttributeError(name)
--> 387 func = self.__getitem__(name)
388 setattr(self, name, func)
389 return func
File /usr/lib/python3.10/ctypes/__init__.py:392, in CDLL.__getitem__(self,
name_or_ordinal)
391 def __getitem__(self, name_or_ordinal):
--> 392 func = self._FuncPtr((name_or_ordinal, self))
393 if not isinstance(name_or_ordinal, int):
394 func.__name__ = name_or_ordinal
AttributeError:
/home/shay/sage/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/cvxopt/umfpack.cpython-310-x86_64-linux-gnu.so:
undefined symbol: numeric
sage:
sage:
sage:
sage:
sage:
sage:
sage:
sage:
sage:
sage:
sage:
sage:
sage:
sage: pointer = ctypes.pythonapi.PyCapsule_GetPointer(c)
---------------------------------------------------------------------------
ArgumentError Traceback (most recent call last)
Cell In[48], line 1
----> 1 pointer = ctypes.pythonapi.PyCapsule_GetPointer(c)
ArgumentError: argument 1: TypeError: Don't know how to convert parameter 1
sage: