def check_response(self, answer, student_input, **kwargs): try: with MathArray.enable_negative_powers(self.config['negative_powers']): result = super(MatrixGrader, self).check_response(answer, student_input, **kwargs) except ShapeError as err: if self.config['suppress_matrix_messages']: return {'ok': False, 'msg': '', 'grade_decimal': 0} elif self.config['shape_errors']: raise else: return {'ok': False, 'msg': err.message, 'grade_decimal': 0} except InputTypeError as err: if self.config['suppress_matrix_messages']: return {'ok': False, 'msg': '', 'grade_decimal': 0} elif self.config['answer_shape_mismatch']['is_raised']: raise else: return {'ok': False, 'grade_decimal': 0, 'msg': err.message} except (ArgumentShapeError, MathArrayError) as err: # If we're using matrix quantities for noncommutative scalars, we # might get an ArgumentShapeError from using functions of matrices, # or a MathArrayError from taking a funny power of a matrix. # Suppress these too. if self.config['suppress_matrix_messages']: return {'ok': False, 'msg': '', 'grade_decimal': 0} raise return result
def check_response(self, answer, student_input, **kwargs): try: with MathArray.enable_negative_powers( self.config['negative_powers']): result = super(MatrixGrader, self).check_response(answer, student_input, **kwargs) except ShapeError as err: if self.config['shape_errors']: raise else: return {'ok': False, 'msg': err.message, 'grade_decimal': 0} except InputTypeError as err: if self.config['answer_shape_mismatch']['is_raised']: raise else: return {'ok': False, 'grade_decimal': 0, 'msg': err.message} return result