Skip to content
Joris Gillis edited this page Apr 4, 2023 · 3 revisions

Standard documentation for Function.mapaccum,Function.fold:

 [INTERNAL] 

::

 mapaccum(self, int N, dict opts) -> Function
 mapaccum(self, str name, int N, dict opts) -> Function
 mapaccum(self, str name, int N, int n_accum, dict opts) -> Function
 mapaccum(self, str name, int n, [str] accum_in, [str] accum_out, dict opts) -> Function
 mapaccum(self, str name, int n, [int] accum_in, [int] accum_out, dict opts) -> Function

Create a mapaccumulated version of this function.

Suppose the function has a signature of:

::

    f: (x, u) -> (x_next , y )

The the mapaccumulated version has the signature:

::

    F: (x0, U) -> (X , Y )

     with
         U: horzcat([u0, u1, ..., u_(N-1)])
         X: horzcat([x1, x2, ..., x_N])
         Y: horzcat([y0, y1, ..., y_(N-1)])

     and
         x1, y0 <- f(x0, u0)
         x2, y1 <- f(x1, u1)
         ...
         x_N, y_(N-1) <- f(x_(N-1), u_(N-1))

Mapaccum has the following benefits over writing an equivalent for- loop:

much faster at construction time

potentially much faster compilation times (for codegen)

offers a trade-off between memory and evaluation time

The base (settable through the options dictionary, default 10), is used to create a tower of function calls, containing unrolled for- loops of length maximum base.

This technique is much more scalable in terms of memory-usage, but slightly slower at evaluation, than a plain for-loop. The effect is similar to that of a for-loop with a check-pointing instruction after each chunk of iterations with size base.

Set base to -1 to unroll all the way; no gains in memory efficiency here.

Extra doc: https://github.com/casadi/casadi/wiki/L_1wi

Doc source: https://github.com/casadi/casadi/blob/develop/casadi/core/function.hpp#L697

Implementation: https://github.com/casadi/casadi/blob/develop/casadi/core/function.cpp#L484-L486

.......

::

 mapaccum(self, int N, dict opts)

[INTERNAL] Create a mapaccumulated version of this function.

Suppose the function has a signature of:

::

    f: (x, u) -> (x_next , y )

The the mapaccumulated version has the signature:

::

    F: (x0, U) -> (X , Y )

     with
         U: horzcat([u0, u1, ..., u_(N-1)])
         X: horzcat([x1, x2, ..., x_N])
         Y: horzcat([y0, y1, ..., y_(N-1)])

     and
         x1, y0 <- f(x0, u0)
         x2, y1 <- f(x1, u1)
         ...
         x_N, y_(N-1) <- f(x_(N-1), u_(N-1))

Mapaccum has the following benefits over writing an equivalent for- loop:

much faster at construction time

potentially much faster compilation times (for codegen)

offers a trade-off between memory and evaluation time

The base (settable through the options dictionary, default 10), is used to create a tower of function calls, containing unrolled for- loops of length maximum base.

This technique is much more scalable in terms of memory-usage, but slightly slower at evaluation, than a plain for-loop. The effect is similar to that of a for-loop with a check-pointing instruction after each chunk of iterations with size base.

Set base to -1 to unroll all the way; no gains in memory efficiency here.

Extra doc: https://github.com/casadi/casadi/wiki/L_1wi

Doc source: https://github.com/casadi/casadi/blob/develop/casadi/core/function.hpp#L697

Implementation: https://github.com/casadi/casadi/blob/develop/casadi/core/function.cpp#L484-L486

.............

.......

::

 mapaccum(self, str name, int N, dict opts)

[INTERNAL] Create a mapaccumulated version of this function.

Suppose the function has a signature of:

::

    f: (x, u) -> (x_next , y )

The the mapaccumulated version has the signature:

::

    F: (x0, U) -> (X , Y )

     with
         U: horzcat([u0, u1, ..., u_(N-1)])
         X: horzcat([x1, x2, ..., x_N])
         Y: horzcat([y0, y1, ..., y_(N-1)])

     and
         x1, y0 <- f(x0, u0)
         x2, y1 <- f(x1, u1)
         ...
         x_N, y_(N-1) <- f(x_(N-1), u_(N-1))

Mapaccum has the following benefits over writing an equivalent for- loop:

much faster at construction time

potentially much faster compilation times (for codegen)

offers a trade-off between memory and evaluation time

The base (settable through the options dictionary, default 10), is used to create a tower of function calls, containing unrolled for- loops of length maximum base.

This technique is much more scalable in terms of memory-usage, but slightly slower at evaluation, than a plain for-loop. The effect is similar to that of a for-loop with a check-pointing instruction after each chunk of iterations with size base.

Set base to -1 to unroll all the way; no gains in memory efficiency here.

Extra doc: https://github.com/casadi/casadi/wiki/L_1wi

Doc source: https://github.com/casadi/casadi/blob/develop/casadi/core/function.hpp#L686

Implementation: https://github.com/casadi/casadi/blob/develop/casadi/core/function.cpp#L487-L489

.............

.......

::

 mapaccum(self, str name, int N, int n_accum, dict opts)

[INTERNAL] Create a mapaccumulated version of this function.

Suppose the function has a signature of:

::

    f: (x, u) -> (x_next , y )

The the mapaccumulated version has the signature:

::

    F: (x0, U) -> (X , Y )

     with
         U: horzcat([u0, u1, ..., u_(N-1)])
         X: horzcat([x1, x2, ..., x_N])
         Y: horzcat([y0, y1, ..., y_(N-1)])

     and
         x1, y0 <- f(x0, u0)
         x2, y1 <- f(x1, u1)
         ...
         x_N, y_(N-1) <- f(x_(N-1), u_(N-1))

Mapaccum has the following benefits over writing an equivalent for- loop:

much faster at construction time

potentially much faster compilation times (for codegen)

offers a trade-off between memory and evaluation time

The base (settable through the options dictionary, default 10), is used to create a tower of function calls, containing unrolled for- loops of length maximum base.

This technique is much more scalable in terms of memory-usage, but slightly slower at evaluation, than a plain for-loop. The effect is similar to that of a for-loop with a check-pointing instruction after each chunk of iterations with size base.

Set base to -1 to unroll all the way; no gains in memory efficiency here.

Extra doc: https://github.com/casadi/casadi/wiki/L_1wi

Doc source: https://github.com/casadi/casadi/blob/develop/casadi/core/function.hpp#L687

Implementation: https://github.com/casadi/casadi/blob/develop/casadi/core/function.cpp#L490-L518

.............

.......

::

 mapaccum(self, str name, int n, [str] accum_in, [str] accum_out, dict opts)

[INTERNAL] Create a mapaccumulated version of this function.

Suppose the function has a signature of:

::

    f: (x, u) -> (x_next , y )

The the mapaccumulated version has the signature:

::

    F: (x0, U) -> (X , Y )

     with
         U: horzcat([u0, u1, ..., u_(N-1)])
         X: horzcat([x1, x2, ..., x_N])
         Y: horzcat([y0, y1, ..., y_(N-1)])

     and
         x1, y0 <- f(x0, u0)
         x2, y1 <- f(x1, u1)
         ...
         x_N, y_(N-1) <- f(x_(N-1), u_(N-1))

Mapaccum has the following benefits over writing an equivalent for- loop:

much faster at construction time

potentially much faster compilation times (for codegen)

offers a trade-off between memory and evaluation time

The base (settable through the options dictionary, default 10), is used to create a tower of function calls, containing unrolled for- loops of length maximum base.

This technique is much more scalable in terms of memory-usage, but slightly slower at evaluation, than a plain for-loop. The effect is similar to that of a for-loop with a check-pointing instruction after each chunk of iterations with size base.

Set base to -1 to unroll all the way; no gains in memory efficiency here.

Extra doc: https://github.com/casadi/casadi/wiki/L_1wi

Doc source: https://github.com/casadi/casadi/blob/develop/casadi/core/function.hpp#L693

Implementation: https://github.com/casadi/casadi/blob/develop/casadi/core/function.cpp#L595-L603

.............

.......

::

 mapaccum(self, str name, int n, [int] accum_in, [int] accum_out, dict opts)

[INTERNAL] Create a mapaccumulated version of this function.

Suppose the function has a signature of:

::

    f: (x, u) -> (x_next , y )

The the mapaccumulated version has the signature:

::

    F: (x0, U) -> (X , Y )

     with
         U: horzcat([u0, u1, ..., u_(N-1)])
         X: horzcat([x1, x2, ..., x_N])
         Y: horzcat([y0, y1, ..., y_(N-1)])

     and
         x1, y0 <- f(x0, u0)
         x2, y1 <- f(x1, u1)
         ...
         x_N, y_(N-1) <- f(x_(N-1), u_(N-1))

Mapaccum has the following benefits over writing an equivalent for- loop:

much faster at construction time

potentially much faster compilation times (for codegen)

offers a trade-off between memory and evaluation time

The base (settable through the options dictionary, default 10), is used to create a tower of function calls, containing unrolled for- loops of length maximum base.

This technique is much more scalable in terms of memory-usage, but slightly slower at evaluation, than a plain for-loop. The effect is similar to that of a for-loop with a check-pointing instruction after each chunk of iterations with size base.

Set base to -1 to unroll all the way; no gains in memory efficiency here.

Extra doc: https://github.com/casadi/casadi/wiki/L_1wi

Doc source: https://github.com/casadi/casadi/blob/develop/casadi/core/function.hpp#L689

Implementation: https://github.com/casadi/casadi/blob/develop/casadi/core/function.cpp#L565-L593

.............

 [INTERNAL] 

::

 fold(self, int N, dict opts) -> Function

Create a mapaccumulated version of this function.

Suppose the function has a signature of:

::

    f: (x, u) -> (x_next , y )

The the mapaccumulated version has the signature:

::

    F: (x0, U) -> (X , Y )

     with
         U: horzcat([u0, u1, ..., u_(N-1)])
         X: horzcat([x1, x2, ..., x_N])
         Y: horzcat([y0, y1, ..., y_(N-1)])

     and
         x1, y0 <- f(x0, u0)
         x2, y1 <- f(x1, u1)
         ...
         x_N, y_(N-1) <- f(x_(N-1), u_(N-1))

Mapaccum has the following benefits over writing an equivalent for- loop:

much faster at construction time

potentially much faster compilation times (for codegen)

offers a trade-off between memory and evaluation time

The base (settable through the options dictionary, default 10), is used to create a tower of function calls, containing unrolled for- loops of length maximum base.

This technique is much more scalable in terms of memory-usage, but slightly slower at evaluation, than a plain for-loop. The effect is similar to that of a for-loop with a check-pointing instruction after each chunk of iterations with size base.

Set base to -1 to unroll all the way; no gains in memory efficiency here.

Extra doc: https://github.com/casadi/casadi/wiki/L_1wi

Doc source: https://github.com/casadi/casadi/blob/develop/casadi/core/function.hpp#L698

Implementation: https://github.com/casadi/casadi/blob/develop/casadi/core/function.cpp#L477-L483

Extra documentation

To edit, see writing tips.

Clone this wiki locally