I am having the following error on the test function for the verify() function on the Face Recognition assessment
TypeError: ufunc ‘isfinite’ not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ‘‘safe’’
Printing the result of the distance calculation I got 0.5436483025550842 which matches with the first case in the cell test,
PD: And the curious thing is that for the next cells the code works
PD2: Definitely there is a problem with all the tests for this function, I have tried all, and in all asserst I find the same error output from above
Does your verify() function return two values - distance as float and door open indicator as boolean?
I think this error is returned by numpy as it is trying to cast some value but is unable to do so. This could occur if the your verify() function doesn’t return 2 values or if the data types of returned values aren’t compatible to expected values.
That would explain why you get an error in asset cell but not the next one. To check, compare your output of that cell to expected:
Right. If the if-else block was not completed, the variable is of type NoneType which cannot be cast to type Boolean, causing the exception you saw before.
I had the same problem and the explanation was that the grader was expecting a scalar (float) but it was receiving an array - so it did not know what to do with it.
Error
TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
The solution was just to “flatten” the variable dist in the statement:
the grader was expecting a scalar (float) but it was receiving an array
I don’t think you have analyzed the cause and effect here correctly.
The issue is that you need to guarantee that “door_open” is set to either True or False.
The “door_open” return parameter does not have a default value.
You can’t just set it to True if the dist case is met, because if you don’t have an ‘else’ clause, then the “door_open” variable is undefined when the function returns.
Or maybe I don’t understand exactly what you mean by “flatten the variable dist”?
I had the same issue, the autograder issued the following error message:
Code Cell UNQ_C2: Unexpected error (TypeError(“ufunc ‘isfinite’ not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ‘‘safe’’”)) occurred during function check. We expected function verify to return verify test 1 failed. Please check that this function is defined properly.
I had the following line which had no issue with the couple of test-cased with Younes and Kian, however it broke the autograder.
dist = np.linalg.norm(variable)
Then, after reading the comments here, I casted the np.float32 into a basic python float, both test-cases went thru. The autograder didn’t raise that error anymore.
dist = float(np.linalg.norm(variable))
I think you must have just confused yourself because of the fact that typing new code and then calling the function again does nothing: it just runs the old code again. You have to actually click “Shift-Enter” on the changed cell before you call it again in order to run the new code.
You’re correct, I’ve just tried again!!
With axis=-1, the autograder fails like before, even though it goes thru in jupyter.
Without axis=-1, and without the float cast, it passes the autograder.
Just added the following assert. PY is really a pain in the neck for type checking.
assert type(dist) == type(0.7), f"check dist type: {type(dist)} although {type(0.7)} expected"