I was not able to reproduce the same error on my end. However the issue could be because the output theta is not being assigned during the function call.
This is because none of the if-statements under which theta is assigned are being executed.
Please note that for a vector x, the condition x>0 will return true only if all the elements of x are greater than 0.