[NumPy-Tickets] [NumPy] #2214: impossible to define ufunc with builtin type input and user-defined output

NumPy Trac numpy-tickets@scipy....
Thu Sep 13 15:42:48 CDT 2012


#2214: impossible to define ufunc with builtin type input and user-defined output
--------------------------------+-------------------------------------------
 Reporter:  rainwoodman         |       Owner:  somebody   
     Type:  defect              |      Status:  new        
 Priority:  normal              |   Milestone:  Unscheduled
Component:  numpy.core          |     Version:  devel      
 Keywords:  ufunc user-defined  |  
--------------------------------+-------------------------------------------
 My use case is

   1. define a ufunc 'myufunc' takes one in and one out.
   2. define a user defined type 'mydtype'
   3. myufunc, when taking int64 as input, will give mydtype as output.

 This is impossible to achieve for two reasons:

  1.  with PyUFunc_FromFuncAndData(... char* types, ...) the user-defined
 types can not be supplied to char* types. Furthermore, the types element
 in PyUFuncObject is a char*.

  2.  with PyUFunc_RegisterLoopForType, we can register a signature with
 int64 as input and mydtype and output in the userloops dictionary, with
 mydtype as the key in userloops. However when we try to invoke the ufunc,
 an error is raised:

 {{{
                 "ufunc '%s' not supported for the input types, and the "
                 "inputs could not be safely coerced to any supported "
                 "types according to the casting rule '%s'",
 }}}

 This is because the type resolver only looks for the dtypes in input
 operands, but the input operand is int64 and is never going to be found in
 userloops.

 All in all, it becomes impossible to make use of myfunc.

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/2214>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list