cutcutcodec.core.compilation.sympy_to_torch.printer_atom.c_pow_pos_integer
- cutcutcodec.core.compilation.sympy_to_torch.printer_atom.c_pow_pos_integer(out: Symbol, indexing: defaultdict[Symbol, str], c_type: str, base: Atom, exp: Atom) tuple[set[str], set[Symbol], list[str]][source]
Manage the special case of power where the exponant is a positive integer.
Examples
>>> from collections import defaultdict >>> from sympy.abc import x, y >>> from cutcutcodec.core.compilation.sympy_to_torch.printer import c_pow_pos_integer >>> >>> # case allocation in new var >>> c_pow_pos_integer(y, defaultdict(lambda: ""), "float", x, 0) (set(), set(), ['y = 1.0f;']) >>> c_pow_pos_integer(y, defaultdict(lambda: ""), "float", x, 1) (set(), set(), ['y = x;']) >>> c_pow_pos_integer(y, defaultdict(lambda: ""), "float", x, 2) (set(), set(), ['y = x * x;']) >>> c_pow_pos_integer(y, defaultdict(lambda: ""), "float", x, 3) (set(), set(), ['y = x * x;', 'y *= x;']) >>> c_pow_pos_integer(y, defaultdict(lambda: ""), "float", x, 4) (set(), set(), ['y = x * x;', 'y *= y;']) >>> c_pow_pos_integer(y, defaultdict(lambda: ""), "float", x, 5) (set(), set(), ['y = x * x;', 'y *= y;', 'y *= x;']) >>> c_pow_pos_integer(y, defaultdict(lambda: ""), "float", x, 6) (set(), {_buf}, ['y = x * x;', '_buf = y;', 'y *= y;', 'y *= _buf;']) >>> c_pow_pos_integer(y, defaultdict(lambda: ""), "float", x, 7) (set(), {_buf}, ['y = x * x;', '_buf = x * y;', 'y *= y;', 'y *= _buf;']) >>> c_pow_pos_integer(y, defaultdict(lambda: ""), "float", x, 8) (set(), set(), ['y = x * x;', 'y *= y;', 'y *= y;']) >>> c_pow_pos_integer(y, defaultdict(lambda: ""), "float", x, 9) (set(), set(), ['y = x * x;', 'y *= y;', 'y *= y;', 'y *= x;']) >>> c_pow_pos_integer(y, defaultdict(lambda: ""), "float", x, 10) (set(), {_buf}, ['y = x * x;', '_buf = y;', 'y *= y;', 'y *= y;', 'y *= _buf;']) >>> >>> # case allocation inplace >>> c_pow_pos_integer(x, defaultdict(lambda: ""), "float", x, 0) (set(), set(), ['x = 1.0f;']) >>> c_pow_pos_integer(x, defaultdict(lambda: ""), "float", x, 1) (set(), set(), ['x = x;']) >>> c_pow_pos_integer(x, defaultdict(lambda: ""), "float", x, 2) (set(), set(), ['x *= x;']) >>> c_pow_pos_integer(x, defaultdict(lambda: ""), "float", x, 3) (set(), {_buf}, ['_buf = x;', 'x *= x;', 'x *= _buf;']) >>> c_pow_pos_integer(x, defaultdict(lambda: ""), "float", x, 4) (set(), set(), ['x *= x;', 'x *= x;']) >>> c_pow_pos_integer(x, defaultdict(lambda: ""), "float", x, 5) (set(), {_buf}, ['_buf = x;', 'x *= x;', 'x *= x;', 'x *= _buf;']) >>> c_pow_pos_integer(x, defaultdict(lambda: ""), "float", x, 6) (set(), {_buf}, ['x *= x;', '_buf = x;', 'x *= x;', 'x *= _buf;']) >>> c_pow_pos_integer(x, defaultdict(lambda: ""), "float", x, 7) (set(), {_buf}, ['_buf = x;', 'x *= x;', '_buf *= x;', 'x *= x;', 'x *= _buf;']) >>> c_pow_pos_integer(x, defaultdict(lambda: ""), "float", x, 8) (set(), set(), ['x *= x;', 'x *= x;', 'x *= x;']) >>> c_pow_pos_integer(x, defaultdict(lambda: ""), "float", x, 9) (set(), {_buf}, ['_buf = x;', 'x *= x;', 'x *= x;', 'x *= x;', 'x *= _buf;']) >>> c_pow_pos_integer(x, defaultdict(lambda: ""), "float", x, 10) (set(), {_buf}, ['x *= x;', '_buf = x;', 'x *= x;', 'x *= x;', 'x *= _buf;']) >>>