On Wed, Jun 24, 2015 at 5:23 AM, Nico <
nico.sc...@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
>