C2_W1 errors in function w1_unittest.test_f_of_omega(f_of_omega)

I was correct. Two errors in the w1_unittest.py code.

First error: When defining the variables for the default_check test cases, those test cases are not specifically defined as float32. This will cause a mismatch error.

The correct code should have a dtype= definition for float32 at the end, as illustrated below – since you’re asking us users to define data as float32:

# Variables for the default_check test cases.
prices_A = np.array([
    104., 108., 101., 104., 102., 105., 114., 102., 105., 101., 109., 103., 93., 98., 92., 97., 96.,
    94., 97., 93., 99., 93., 98., 94., 93., 92., 96., 98., 98., 93., 97., 102., 103., 100., 100., 104.,
    100., 103., 104., 101., 102., 100., 102., 108., 107., 107., 103., 109., 108., 108.,
], dtype=np.float32)
prices_B = np.array([
    76., 76., 84., 79., 81., 84., 90., 93., 93., 99., 98., 96., 94., 104., 101., 102., 104., 106., 105.,
    103., 106., 104., 113., 115., 114., 124., 119., 115., 112., 111., 106., 107., 108., 108., 102., 104.,
    101., 101., 100., 103., 106., 100., 97., 98., 90., 92., 92., 99., 94., 91.
], dtype=np.float32)

Second, to ensure that small floating point differences do not cause an error, a tolerance should be added such that the test looks like this:

assert np.allclose(result, test_case["expected"], atol=1e-5)

Doing so will resolve the errors and create the intended passing result when a student (ie, me) provides the correct input. See below screen cap for the updated result when executing this file in Google Colabs with the changes made to the w1_unittest.py file.

Can you please update the codebase to reflect this so we can proceed with this assignment? Thank you.

1 Like