Ejemplo n.º 1
0
def _append_args_accessors_matrix(method, files, objlabel):
    """
    add all accessors for arguments from method.args_names to the cpp files for
    object with name objlabel. return Matrix<double, n, m>
    """
    title = "\n\n// Acessors to Arguments, return Matrix<double, n, m>\n"
    files['h']['public'] += title
    files['cpp']['public'] += title
    for name in method.args_names:
        arg = getattr(method, name + '_expr')
        dim0 = len(arg)
        if dim0 == 0:
            dim1 = 0
        else:
            dim1 = 1
        files['h']['public'] += \
            '\n{0} {1}() const;'.format(matrix_type(dim0, dim1), name)
        files['cpp']['public'] += \
            "\n{0} {1}::{2}() const".format(matrix_type(dim0, dim1),
                                            objlabel, name) + ' {'
        files['cpp']['public'] += \
            indent('\n{0} m;'.format(matrix_type(dim0, dim1)))
        for i, symb in enumerate(arg):
            files['cpp']['public'] += \
                indent("\nm({0}, 0) = *{1};".format(i, str(symb)))
        files['cpp']['public'] += indent("\nreturn m;")
        files['cpp']['public'] += "\n}"
Ejemplo n.º 2
0
def _str_mat_func_get(method, name, objlabel):
    mat = sympy.Matrix(getattr(method, name + '_expr'))
    mtype = matrix_type(mat.shape[0], mat.shape[1])
    get_h = '\n{0} {1}() const;'.format(mtype, name)
    get_cpp = '\n{0} {1}::{2}() const'.format(mtype, objlabel, name)
    get_cpp += ' {\n'
    get_cpp += indent("return _{0};".format(name))
    get_cpp += '\n}'
    return get_h, get_cpp
Ejemplo n.º 3
0
def append_constructor_init_matrix(method, objlabel, files):
    title = "\n\n// Constructor with matrix state initalization\n\n"
    mtype = matrix_type(method.core.dims.x(), 1)
    files['h']['public'] += "{0}{1}({2} &);".format(title, objlabel, mtype)
    files['cpp']['public'] += title
    string = '{0}::{0}({1} & x0)'.format(objlabel, mtype) + '{\n'
    string += "set_x(x0);"
    string += '\n' + indent('init();') + '\n};'
    files['cpp']['public'] += string
Ejemplo n.º 4
0
def _str_mat_op_def(nums, name):
    mat = getattr(nums, name)()
    if len(mat.shape) == 1:
        mat = numpy.matrix(mat).T
    if not bool(numpy.prod(mat.shape)):
        shape = (0, 0)
    else:
        shape = mat.shape
    mtype = matrix_type(shape[0], shape[1])
    return '\n{0} _{1};'.format(mtype, name)
Ejemplo n.º 5
0
def _str_mat_op_init_cpp(nums, name):
    mat = getattr(nums, name)()
    if len(mat.shape) == 1:
        mat = numpy.matrix(mat).T
    if not bool(numpy.prod(mat.shape)):
        shape = (0, 0)
    else:
        shape = mat.shape
    mtype = matrix_type(shape[0], shape[1])
    return '_{0} = Map<{1}> ({0}_data);'.format(name, mtype)
Ejemplo n.º 6
0
def _append_args_pointers(method, files):
    """
    add all pointers for arguments from method.args_names to the cpp files for
    object with name objlabel. pointers to 'args(i, 0)' for i in range(nargs)
    """
    title = "\n\n// Arguments\n"
    files['h']['private'] += title
    files['h']['private'] += \
        '\n{0} args;\n'.format(matrix_type(len(method.args), 1))
    for i, arg in enumerate(method.args):
        files['h']['private'] += \
            '\ndouble * {0} = & args({1}, 0);'.format(str(arg), i)
Ejemplo n.º 7
0
def _append_funcs_defs(nums, files):
    title = "\n\n// Functions Results Definitions\n"
    files['h']['private'] += title
    for name in nums.names:
        if name in nums.method.funcs_names:
            expr = getattr(nums.method, name + '_expr')
            try:
                _assert_expr(expr)
                files['h']['private'] += '\ndouble _{0};'.format(name)
            except AssertionError:
                mat = sympy.Matrix(getattr(nums.method, name + '_expr'))
                mtype = matrix_type(mat.shape[0], mat.shape[1])
                files['h']['private'] += '\n{0} _{1};'.format(mtype, name)
Ejemplo n.º 8
0
def _str_mat_op_get(nums, name, objlabel):
    mat = getattr(nums, name)()
    if len(mat.shape) == 1:
        mat = numpy.matrix(mat).T
    if not bool(numpy.prod(mat.shape)):
        shape = (0, 0)
    else:
        shape = mat.shape
    mtype = matrix_type(shape[0], shape[1])
    get_h = '\n{0} {1}() const;'.format(mtype, name)
    get_cpp = \
        '\n{0} {1}::{2}() const'.format(mtype, objlabel, name)
    get_cpp += ' {\n' + indent('return _{0};'.format(name)) + '\n}'
    return get_h, get_cpp
Ejemplo n.º 9
0
def _str_mat_func_init_cpp(method, name):
    mat = sympy.Matrix(getattr(method, name + '_expr'))
    mtype = matrix_type(mat.shape[0], mat.shape[1])
    return '\n_{0} = Map<{1}> ({0}_data);'.format(name, mtype)