Re: Trac patch 10249 isn't letting me run C++ Cython code in the Notebook

3 views
Skip to first unread message

William Stein

unread,
Nov 16, 2010, 2:47:21 PM11/16/10
to Simon Spicer, 581d...@googlegroups.com
Hi,

Pop the patch from 10249 and don't use it at all. Evidently, in
sage-4.6 it's simply not necessary. Sweet.
The example code should work without needing this patch.

- William

On Tue, Nov 16, 2010 at 10:53 AM, Simon Spicer <mlu...@uw.edu> wrote:
> Hi Prof Stein
> As per the instructions on your
> worksheet http://wstein.org/edu/2010/581d/notes/2010-11-12/581d-2010-11-12.sws,
> I've applied patch #10249 to my local copy of Sage in order to get the C++
> Cython code at the bottom of the worksheet to run.
> Sadly, it's not working. Specifically, when I try to execute this cell:
> %cython
> #clang c++
> cdef extern from "stdlib.h":
>     long random()
> cdef extern from "/tmp/a.h":
>     cdef cppclass Elt10:
>         long a, b
>     Elt10 operator+(Elt10 x, Elt10 y)
>     Elt10 operator*(Elt10 x, Elt10 y)
>     void iadd(Elt10* x, Elt10 y)
> cdef class Vec4:
>     cdef Elt10* elements
>     cdef long n
>     def __cinit__(self, Py_ssize_t n):
>         # dynamic memory allocation on the heap
>         self.elements = <Elt10*>malloc(n*sizeof(Elt10))
>         self.n = n
>     def __dealloc__(self):
>         free(self.elements)
>     def randomize(self):
>         cdef Py_ssize_t m
>         for m in range(self.n):
>             self.elements[m].a = random(); self.elements[m].b = random()
>     def dot(self, Vec4 other not None):
>         cdef Elt10 ans, tmp
>         ans.a = 0; ans.b = 0
>         cdef Py_ssize_t m
>         # This is the part that gets very worrisome, since the code does
>         # not look easy to read.  And it can easily get massively more
> complicated
>         # when the arithmetic isn't so simple!
>         for m in range(self.n):
>             ans = ans + self.elements[m] * other.elements[m]
>         return ans.a, ans.b
> I get the following error:
>
> cp:
> _Users_simonspicer__sage_sage_notebook_sagenb_home_admin_90_code_sage46_spyx_0.c:
> No such file or directory
> Traceback (most recent call last): cdef cppclass Elt10:
> File "", line 1, in <module>
>
> File "/Users/simonspicer/sage/devel/sagenb/sagenb/misc/support.py", line
> 519, in cython_import_all
> create_local_c_file=create_local_c_file)
> File "/Users/simonspicer/sage/devel/sagenb/sagenb/misc/support.py", line
> 496, in cython_import
> create_local_c_file=create_local_c_file)
> File
> "/Users/simonspicer/sage/local/lib/python2.6/site-packages/sage/misc/cython.py",
> line 372, in cython
> raise RuntimeError, "Error converting %s to C:\n%s\n%s"%(filename, log,
> err)
> RuntimeError: Error converting
> /Users/simonspicer/.sage/sage_notebook.sagenb/home/admin/90/code/sage46.spyx
> to C:
>
> I've looked at the Trac ticket, and it seems like I'm not the only one with
> this issue. Is there an easy fix to this?
> Regards
> Simon
>

--
William Stein
Professor of Mathematics
University of Washington
http://wstein.org

Reply all
Reply to author
Forward
0 new messages