[SciPy-user] weave and numpy.array(dtype=object)

C. Ball ceball@users.sourceforge....
Wed Jan 9 03:09:22 CST 2008


I wonder if someone could help me to use numpy arrays of type object_
(dtype="O") with weave?

I have the following class:

import weave
class TestClass(object):
    def __call__(self, some_array): 
        code = """
        weave.inline(code, ['some_array'], local_dict=locals(),verbose=1)

If I create an instance of this class and then call it with an array
of floats (or ints, etc), it compiles fine. 

But, if I try to call the class with an array of python objects,
I get the following error:

<weave: compiling>
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "test_weave.py", line 74, in __call__
    inline(code, ['some_array'], local_dict=locals())
  File "test_weave.py", line 16, in inline
  File "[weave location]/weave/inline_tools.py", line 333, in inline
  File "[weave location]/weave/inline_tools.py", line 459, in compile_function
    verbose=verbose, **kw)
  File "[weave location]/weave/ext_tools.py", line 353, in compile
    kw,file = self.build_kw_and_file(location,kw)
  File "[weave location]/weave/ext_tools.py", line 334, in build_kw_and_file
    file = self.generate_file(location=location)
  File "[weave location]/weave/ext_tools.py", line 295, in generate_file
    code = self.module_code()
  File "[weave location]/weave/ext_tools.py", line 203, in module_code
  File "[weave location]/weave/ext_tools.py", line 269, in function_code
    all_function_code += func.function_code()
  File "[weave location]/weave/inline_tools.py", line 77, in function_code
    decl_code = indent(self.arg_declaration_code(),4)
  File "[weave location]/weave/inline_tools.py", line 62, in arg_declaration_code
    for arg in self.arg_specs]
  File "[weave location]/weave/standard_array_spec.py", line 158, in
    res = self.template_vars(inline=inline)
  File "[weave location]/weave/standard_array_spec.py", line 151, in template_vars
    res['num_type'] = num_to_c_types[self.var_type]
KeyError: 'O'

I'm using a copy of weave that I just checked out from SVN:

URL: http://svn.scipy.org/svn/scipy/trunk/scipy/weave
Revision: 3809
Last Changed Rev: 3736
Last Changed Date: 2007-12-28 06:53:35 +0800 (Fri, 28 Dec 2007)
Properties Last Updated: 2008-01-09 15:16:42 +0800 (Wed, 09 Jan 2008)

(and Python 2.5.1 with numpy 1.0.2).

I couldn't find anything in the weave tutorial
the numpy book, or the Numeric documentation, so please tell me if I have missed
something obvious.


More information about the SciPy-user mailing list