better exceptions for ts types with no cython type

17 views
Skip to first unread message

Geoffrey Irving

unread,
Jul 29, 2014, 8:29:44 PM7/29/14
to xdress
I have a template of the form

   template<class T,int d> class Vector;

which I want to autoconvert to numpy arrays.  As a first step, I wrote

    from xdress.types.system import TypeSystem
    ts = TypeSystem.empty()
    ts.register_class('Vector',('T','d'),cpp_type='Vector')

When wrapping a function where Vector appears, I get the exception shown below, presumably because I have neither wrapped Vector nor given a cython_py2c argument to register_class.  However, the exception is fairly opaque.  What's the right place to catch this error and give a more useful error?

Thanks,
Geoffrey

--------------------------------------

(xdress) cayley:geode% cns
Warning: clang doesn't know how to do OpenMP, so many things will be slower
configuring blas: using openblas
disabling openexr: no imath
scons: building associated VariantDir targets: build/native/release
xdress --rc geode/xdressrc.py --packagedir build/native/release/geode/xdress --builddir build/native/release/geode/xdress/tmp -p clang --extra-parser-args=-std=c++11 -I. -Ibuild/native/release -I. -I/usr/local/include -I/usr/local/include -Ibuild/native/release
autoall: discovering API names
autoall: no API names to discover!
dtypes: registering numpy dtypes
stlwrap: registering C++ standard library types
autodescribe: scraping C/C++ APIs from source
autodescribe: describing predicate_tests
autodescribe: describing log_initialized
autodescribe: describing log_configure
autodescribe: describing log_cache_initial_output
autodescribe: describing log_copy_to_file
autodescribe: describing log_finish
autodescribe: describing log_push_scope
autodescribe: describing log_pop_scope
autodescribe: describing log_print
autodescribe: describing log_error
autodescribe: describing log_flush
autodescribe: describing str_repr_test
autodescribe: describing partition_loop_test
autodescribe: describing large_partition_loop_test
autodescribe: describing format_test
autodescribe: describing cpu_times
autodescribe: describing memory_usage
autodescribe: describing max_memory_usage
cythongen: creating C/C++ API wrappers
Traceback (most recent call last):
  File "/home/irving/.local/bin/xdress", line 10, in <module>
    execfile(__file__)
  File "/home/irving/xdress/scripts/xdress", line 6, in <module>
    main()
  File "/home/irving/xdress/xdress/main.py", line 222, in main
    plugins.execute()
  File "/home/irving/xdress/xdress/plugins.py", line 374, in execute
    self.exit(e)
  File "/home/irving/xdress/xdress/plugins.py", line 372, in execute
    plugin.execute(rc)
  File "/home/irving/xdress/xdress/cythongen.py", line 1611, in execute
    cpppxds = gencpppxd(env, ts=rc.ts)
  File "/home/irving/xdress/xdress/cythongen.py", line 72, in gencpppxd
    cpppxds[name] = modcpppxd(mod, exceptions, ts=ts)
  File "/home/irving/xdress/xdress/cythongen.py", line 166, in modcpppxd
    ci_tup, attr_str = funccpppxd(desc, exceptions, ts)
  File "/home/irving/xdress/xdress/cythongen.py", line 303, in funccpppxd
    rtype = ts.cython_ctype(frtn)
  File "/home/irving/xdress/xdress/utils.py", line 737, in __call__
    cache[key] = self.meth(*args, **kwargs)
  File "/home/irving/xdress/xdress/types/system.py", line 930, in cython_ctype
    template_name = self.cython_ctypes[t[0]]
  File "/home/irving/xdress/xdress/types/containers.py", line 35, in __getitem__
    value = self._d[key]
KeyError: 'Vector'
scons: *** [build/native/release/geode/xdress/wrap.pxd] Error 1

Anthony Scopatz

unread,
Jul 31, 2014, 5:55:27 PM7/31/14
to Geoffrey Irving, xdress
Hi Geoffrey, 

My opinion is that that this should be the error should be thrown in cythongen (on line 303). This is the point of use where not having a py2c registered causes problems. It is possible to run xdress without cythongen, so the lack of a py2c isn't an error in and of itself. It is only an error when you try to use it and it is not there :).  

Be Well
Anthony

Also, sorry for the delay getting back to you - I was on a rare vacation :)


--
You received this message because you are subscribed to the Google Groups "xdress" group.
To view this discussion on the web visit https://groups.google.com/d/msgid/xdress/CAJ1ofpdes2rdzYn386rjgb5PMmOBYbzsSoTzxFFE4Sg%3De11SJw%40mail.gmail.com.

Geoffrey Irving

unread,
Jul 31, 2014, 6:11:36 PM7/31/14
to Anthony Scopatz, xdress
On Thu, Jul 31, 2014 at 2:55 PM, Anthony Scopatz <sco...@gmail.com> wrote:
Hi Geoffrey, 

My opinion is that that this should be the error should be thrown in cythongen (on line 303). This is the point of use where not having a py2c registered causes problems. It is possible to run xdress without cythongen, so the lack of a py2c isn't an error in and of itself. It is only an error when you try to use it and it is not there :).

Wrapping a try-except around line 303 seems problematic, since ts.cython_ctype is used in other places in similar ways (most notably on line 295 right above 303).  Would it be better to make cython_ctype catch the error itself?  It's probably also better if you write at least the error message for me, since I'm still quite new to actually using xdress despite having written a nontrivial piece of internals. :)

Be Well
Anthony

Also, sorry for the delay getting back to you - I was on a rare vacation :)

No worries!  Asynchronous communication is a beautiful thing. :)
 

Anthony Scopatz

unread,
Aug 1, 2014, 4:18:47 AM8/1/14
to Geoffrey Irving, xdress
On Thu, Jul 31, 2014 at 3:11 PM, Geoffrey Irving <irv...@naml.us> wrote:
On Thu, Jul 31, 2014 at 2:55 PM, Anthony Scopatz <sco...@gmail.com> wrote:
Hi Geoffrey, 

My opinion is that that this should be the error should be thrown in cythongen (on line 303). This is the point of use where not having a py2c registered causes problems. It is possible to run xdress without cythongen, so the lack of a py2c isn't an error in and of itself. It is only an error when you try to use it and it is not there :).

Wrapping a try-except around line 303 seems problematic, since ts.cython_ctype is used in other places in similar ways (most notably on line 295 right above 303).  Would it be better to make cython_ctype catch the error itself?

Yeah, I agree with that.  And the same goes for similar methods on the type system.
 
  It's probably also better if you write at least the error message for me, since I'm still quite new to actually using xdress despite having written a nontrivial piece of internals. :)

Sure thing!  I'll take a stab at it tomorrow.

Anthony Scopatz

unread,
Aug 14, 2014, 8:49:08 PM8/14/14
to Geoffrey Irving, xdress
See #264
Reply all
Reply to author
Forward
0 new messages