parameters: (cls, name, ref, data, accuracy_critical=False,
                       rtol=1e-5, atol=1e-8, report_success=True,
                       report_failure=True)
return_statement: return True
docstring: Feedback.check_scalar(name, ref, data)
  
          Check that a student scalar has correct value with respect to a reference scalar. This will mark a value as correct if it passes any of the following checks:
  
          - ``abs(ref - data) < ref(ref) * rtol``
          - ``abs(ref - data) < atol``
  
          One of rtol or atol can be omitted (set to None) if that check is unwanted.
          Or both, but then nothing would be graded :)
  
          - ``name``: Name of the scalar that is being checked.  This will be used to give feedback.
          - ``ref``: Reference scalar.
          - ``data``: Student scalar to be checked.  Do not mix this up with the previous value! This argument is subject to more strict type checking.
          - ``accuracy_critical``: If true, grading will halt on failure.
          - ``rtol``: Maximum relative tolerance.
          - ``atol``: Maximum absolute tolerance.
          - ``report_failure``: If true, feedback will be given on failure.
          - ``report_success``: If true, feedback will be given on success.
docstring_summary: Feedback.check_scalar(name, ref, data)
docstring_tokens: Feedback . check_scalar ( name ref data )
function: def check_scalar(cls, name, ref, data, accuracy_critical=False,
                       rtol=1e-5, atol=1e-8, report_success=True,
                       report_failure=True):
          """
          Feedback.check_scalar(name, ref, data)
  
          Check that a student scalar has correct value with respect to a reference scalar. This will mark a value as correct if it passes any of the following checks:
  
          - ``abs(ref - data) < ref(ref) * rtol``
          - ``abs(ref - data) < atol``
  
          One of rtol or atol can be omitted (set to None) if that check is unwanted.
          Or both, but then nothing would be graded :)
  
          - ``name``: Name of the scalar that is being checked.  This will be used to give feedback.
          - ``ref``: Reference scalar.
          - ``data``: Student scalar to be checked.  Do not mix this up with the previous value! This argument is subject to more strict type checking.
          - ``accuracy_critical``: If true, grading will halt on failure.
          - ``rtol``: Maximum relative tolerance.
          - ``atol``: Maximum absolute tolerance.
          - ``report_failure``: If true, feedback will be given on failure.
          - ``report_success``: If true, feedback will be given on success.
          """
  
          import numpy as np
  
          def bad(msg):
              if report_failure:
                  cls.add_feedback(msg)
  
              if accuracy_critical:
                  cls.finish('')
              else:
                  return False
  
          if data is None:
              return bad("'%s' is None or not defined" % name)
  
          if not isinstance(data, (complex, float, int, np.number)):
              try:
                  # Check whether data is a sympy number because sympy
                  # numbers do not follow the typical interface
                  # See https://github.com/inducer/relate/pull/284
                  if not data.is_number:
                      return bad("'%s' is not a number" % name)
              except AttributeError:
                  return bad("'%s' is not a number" % name)
  
          good = False
  
          if rtol is not None and abs(ref-data) < abs(ref)*rtol:
              good = True
          if atol is not None and abs(ref-data) < atol:
              good = True
  
          if not good:
              return bad("'%s' is inaccurate" % name)
          else:
              if report_success:
                  cls.add_feedback("'%s' looks good" % name)
  
          return True
function_tokens: def check_scalar ( cls , name , ref , data , accuracy_critical = False , rtol = 1e-5 , atol = 1e-8 , report_success = True , report_failure = True ) : import numpy as np def bad ( msg ) : if report_failure : cls . add_feedback ( msg ) if accuracy_critical : cls . finish ( '' ) else : return False if data is None : return bad ( "'%s' is None or not defined" % name ) if not isinstance ( data , ( complex , float , int , np . number ) ) : try : # Check whether data is a sympy number because sympy # numbers do not follow the typical interface # See https://github.com/inducer/relate/pull/284 if not data . is_number : return bad ( "'%s' is not a number" % name ) except AttributeError : return bad ( "'%s' is not a number" % name ) good = False if rtol is not None and abs ( ref - data ) < abs ( ref ) * rtol : good = True if atol is not None and abs ( ref - data ) < atol : good = True if not good : return bad ( "'%s' is inaccurate" % name ) else : if report_success : cls . add_feedback ( "'%s' looks good" % name ) return True