in evaluation/latex2sympy/latex2sympy2.py [0:0]
def convert_elementary_transform(matrix, transform):
if transform.transform_scale():
transform_scale = transform.transform_scale()
transform_atom = transform_scale.transform_atom()
k = None
num = int(transform_atom.NUMBER().getText()) - 1
if transform_scale.expr():
k = convert_expr(transform_scale.expr())
elif transform_scale.group():
k = convert_expr(transform_scale.group().expr())
elif transform_scale.SUB():
k = -1
else:
k = 1
if transform_atom.LETTER_NO_E().getText() == 'r':
matrix = matrix.elementary_row_op(op='n->kn', row=num, k=k)
elif transform_atom.LETTER_NO_E().getText() == 'c':
matrix = matrix.elementary_col_op(op='n->kn', col=num, k=k)
else:
raise Exception('Row and col don\'s match')
elif transform.transform_swap():
first_atom = transform.transform_swap().transform_atom()[0]
second_atom = transform.transform_swap().transform_atom()[1]
first_num = int(first_atom.NUMBER().getText()) - 1
second_num = int(second_atom.NUMBER().getText()) - 1
if first_atom.LETTER_NO_E().getText() != second_atom.LETTER_NO_E().getText():
raise Exception('Row and col don\'s match')
elif first_atom.LETTER_NO_E().getText() == 'r':
matrix = matrix.elementary_row_op(op='n<->m', row1=first_num, row2=second_num)
elif first_atom.LETTER_NO_E().getText() == 'c':
matrix = matrix.elementary_col_op(op='n<->m', col1=first_num, col2=second_num)
else:
raise Exception('Row and col don\'s match')
elif transform.transform_assignment():
first_atom = transform.transform_assignment().transform_atom()
second_atom = transform.transform_assignment().transform_scale().transform_atom()
transform_scale = transform.transform_assignment().transform_scale()
k = None
if transform_scale.expr():
k = convert_expr(transform_scale.expr())
elif transform_scale.group():
k = convert_expr(transform_scale.group().expr())
elif transform_scale.SUB():
k = -1
else:
k = 1
first_num = int(first_atom.NUMBER().getText()) - 1
second_num = int(second_atom.NUMBER().getText()) - 1
if first_atom.LETTER_NO_E().getText() != second_atom.LETTER_NO_E().getText():
raise Exception('Row and col don\'s match')
elif first_atom.LETTER_NO_E().getText() == 'r':
matrix = matrix.elementary_row_op(op='n->n+km', k=k, row1=first_num, row2=second_num)
elif first_atom.LETTER_NO_E().getText() == 'c':
matrix = matrix.elementary_col_op(op='n->n+km', k=k, col1=first_num, col2=second_num)
else:
raise Exception('Row and col don\'s match')
return matrix