#15820: Implement sequences of bounded integers
--------------------------------------------+------------------------
Reporter: SimonKing | Owner:
Type: enhancement | Status: new
Priority: major | Milestone: sage-6.3
Component: algebra | Resolution:
Keywords: sequence bounded integer | Merged in:
Authors: | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
Dependencies: | Stopgaps:
--------------------------------------------+------------------------
Comment (by SimonKing):
Or perhaps a better example, showing that the fused type is used to choose
code at compile time: Put the following into a cell of the notebook
{{{
%cython
cimport cython
ctypedef fused str_or_int:
str
int
cpdef str_or_int times_two(str_or_int var):
if str_or_int is int:
return var*2
else:
return var+var
def test():
cdef int a = 3
cdef str b = 'b'
a = times_two(a)
b = times_two(b)
}}}
and look at the resulting code. The line `a = times_two(a)` becomes
{{{
__pyx_v_a =
__pyx_fuse_1__pyx_f_68_home_king__sage_sage_notebook_sagenb_home_admin_2_code_sage4_spyx_0_times_two(__pyx_v_a,
0);
}}}
whereas `b = times_two(b)` becomes
{{{
__pyx_t_1 =
__pyx_fuse_0__pyx_f_68_home_king__sage_sage_notebook_sagenb_home_admin_2_code_sage4_spyx_0_times_two(__pyx_v_b,
0);
}}}
and one can check that Cython created two different C-functions
`__pyx_fuse_0...` and `__pyx_fuse_1...` for the two possible (type-
dependent!) versions of `times_two`.
--
Ticket URL: <http://trac.sagemath.org/ticket/15820#comment:39>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.