On Wed, Jun 24, 2015 at 5:23 AM, Nico <nico.schloe...@gmail.com> wrote: > Hi everyone, > > I'd like to convert a Python function that returns an array, e.g., > > def test(x, y, z): > return [[x, y], [y, z]] > > into C++ code, e.g., a function that returns a > std::vector<std::vector<double>>. Right now, I call `test()` with SymPy > symbols `x`, `y`, `z`, then translate every entry into C code using codegen, > and then after that _regexp_ the function body out. Then from the four > function bodies, I build the C++ function.
Also note that std::vector<std::vector<double>> will be slow, as each row will be dynamically allocated on a heap. If you care about efficiency, use a proper 2D array in a contiguous block of memory (there are many libraries in C++ that provide this functionality), or just use a single 1D std::vector<double> and index it using a 2D indexing (i.e. i+ncol*j). Ondrej > > Is there a better way to do this, in particular one that works without > regexping around the output code? > > Cheers, > Nico > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sympy+unsubscr...@googlegroups.com. > To post to this group, send email to sympy@googlegroups.com. > Visit this group at http://groups.google.com/group/sympy. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/41d60169-a7e0-49f9-9ef6-0c790bf5c7d9%40googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sympy+unsubscr...@googlegroups.com. To post to this group, send email to sympy@googlegroups.com. Visit this group at http://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CADDwiVCXaP8jkx3or1NTB4YdK%2BJXtqGMJyW4%2B2M4hx_hjgjaZw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.