3

I'm struggling with the situation when I need a code like this to work:

from custom_lib import custom_type, custom_dtype
import numpy as np
a = custom_type(1)
arr = np.array([a,a],dtype=custom_dtype)
arr+a // doesn't work ( No cast function available. )
arr+np.array(a,dtype=custom_dtype) // works and just broadcasts properly

And my wrapped type is double-like type but has a special behavior on math operations so I need a full CPython wrapping of this type and numpy compatibility ( that is why boost.python doesn't work for me ).

Any numpy c-api masters here? Any help appreciated.

  • What does `np.array(a).dtype` give? Is `a` a subclass of `np.generic`? – Eric Jun 30 '17 at 15:43
  • 2
    a in an object of type custom_type, custom_dtype is a PyArray_Descr .... ob_type = &PyArrayDescr_Type; np.array(a).dtype returns dtype('O') ( it takes my type as object, another not solved problem... ) np.array(a,dtype=custom_dtype ).dtype returns dtype(custom_type) a is not a subclass of generic, it's a custom type declared in C and exposed to python through c-api – vladislav odobesku Jun 30 '17 at 17:09
  • _"another not solved problem"_ - this is almost certainly the same problem. If you can fix this, I imagine that ufuncs will come for free. Implementing `__array__` might work. – Eric Jun 30 '17 at 18:25

0 Answers0