I am afraid I didn't explain my problem well enough.
My problem is not to write c++ code with mpfr. That is solved
It is also not to call c++ libraries from cython code that involves plain
mpfr numbers. That is also solved.
My problem is to do so with functions that involve *arrays *(or lists, or
vectors) of mpfr numbers.
In particular, assume that i have writen a c++ library that provides a
function my_function that takes an array of mpfr numbers and returns
another array of mpfr numbers. So I try to write some cython code to
interface in from sage:
#clang C++
#clib my_library
include 'cysignals/signals.pxi'
from sage.libs.mpfr cimport *
from sage.rings.real_mpfr cimport RealNumber
from sage.rings.real_mpfr import RealField
cdef extern from "my_library.h":
mpfr_t* my_function (mpfr_t *_coef)
def my_cython_function(values):
cdef mpfr_t* cvalues = <mpfr_t*>
sage_malloc(sizeof(mpfr_t)*len(values))
cdef mpfr_t tempnum
cdef mpfr_t* rop
for i,v in enumerate(values):
tempnum = values[i].value
mpfr_init(cvalues[i])
mpfr_set(cvalues[i], tempnum, MPFR_RNDN)
sig_on
rop = my_function(cvalues)
sig_off
This code is suppopsed to just create an array of mpfr objects to be
passed
to my_function, and another array to get the result of that function.
When
I try to compile it I get the following error:
---------------------------------------------------------------------------
UnicodeDecodeError Traceback (most recent call
last)
/home/mmarco/sage/local/lib/python2.7/site-packages/IPython/core/
interactiveshell.pyc in run_code(self, code_obj, result)
2896 if result is not None:
2897 result.error_in_exec = sys.exc_info()[1]
-> 2898 self.showtraceback()
2899 else:
2900 outflag = 0
/home/mmarco/sage/local/lib/python2.7/site-packages/IPython/core/
interactiveshell.pyc in showtraceback(self, exc_tuple, filename,
tb_offset,
exception_only)
1822 except Exception:
1823 stb = self.InteractiveTB.
structured_traceback(etype,
-> 1824 value, tb, tb_offset=
tb_offset)
1825
1826 self._showtraceback(etype, value, stb)
/home/mmarco/sage/local/lib/python2.7/site-packages/IPython/core/ultratb.pyc
in structured_traceback(self, etype, value, tb, tb_offset,
number_of_lines_of_context)
1404 self.tb = tb
1405 return FormattedTB.structured_traceback(
-> 1406 self, etype, value, tb, tb_offset,
number_of_lines_of_context)
1407
1408
/home/mmarco/sage/local/lib/python2.7/site-packages/IPython/core/ultratb.pyc
in structured_traceback(self, etype, value, tb, tb_offset,
number_of_lines_of_context)
1312 # Verbose modes need a full traceback
1313 return VerboseTB.structured_traceback(
-> 1314 self, etype, value, tb, tb_offset,
number_of_lines_of_context
1315 )
1316 else:
/home/mmarco/sage/local/lib/python2.7/site-packages/IPython/core/ultratb.pyc
in structured_traceback(self, etype, evalue, etb, tb_offset,
number_of_lines_of_context)
1162
1163 formatted_exception =
self.format_exception_as_a_whole(etype
, evalue, etb, number_of_lines_of_context,
-> 1164
tb_offset)
1165
1166 colors = self.Colors # just a shorthand + quicker name
lookup
/home/mmarco/sage/local/lib/python2.7/site-packages/IPython/core/ultratb.pyc
in format_exception_as_a_whole(self, etype, evalue, etb,
number_of_lines_of_context, tb_offset)
1111 return ""
1112
-> 1113 last_unique, recursion_repeat =
find_recursion(orig_etype,
evalue, records)
1114
1115 frames = self.format_records(records, last_unique,
recursion_repeat)
/home/mmarco/sage/local/lib/python2.7/site-packages/IPython/core/ultratb.pyc
in find_recursion(etype, value, records)
453 # quarter of the traceback (250 frames by default) is
repeats,
and find the
454 # first frame (from in to out) that looks different.
--> 455 if not is_recursion_error(etype, value, records):
456 return len(records), 0
457
/home/mmarco/sage/local/lib/python2.7/site-packages/IPython/core/ultratb.pyc
in is_recursion_error(etype, value, records)
439 # a recursion error.
440 return (etype is recursion_error_type) \
--> 441 and "recursion" in str(value).lower() \
442 and len(records) > 500
443
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
1158:
ordinal not in range(128)
I tried to circunvent this problem by using c++ vectors instead of
malloc'ed arrays, but then it is the c++ compilet which complains abput
creating vectors of mpfr_t objects.
Thoughts?