Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternate solution for Task 1.2 does not pass tests #11

Open
tnwei opened this issue Feb 6, 2022 · 2 comments
Open

Alternate solution for Task 1.2 does not pass tests #11

tnwei opened this issue Feb 6, 2022 · 2 comments

Comments

@tnwei
Copy link

tnwei commented Feb 6, 2022

For Task 1.2, I believe the intended code for scalar.Scalar.__sub__is return Add.apply(self, -b), which passes the tests. Interestingly, if return Add.apply(self, Neg.apply(b)) is used, the tests that involve subtracting constants fail. Excerpt of the failed test cases below:

===============================short test summary info==============================
FAILED tests/test_scalar.py::test_one_args[fn4] - AssertionError: Expected return typ <class 'float'> got <class 'int'>: -200
FAILED tests/test_scalar.py::test_one_args[fn5] - AssertionError: Expected return typ <class 'float'> got <class 'int'>: -200
FAILED tests/test_scalar.py::test_one_args[fn13] - AssertionError: Expected return typ <class 'float'> got <class 'int'>: -5     

I've slightly modified the error message in autodiff.FunctionBase to print the offending value in question, and they are all ints. The root cause is due to scalar.ScalarFunction.data_type being hard-coded as float. I assume data_type is fixed for a reason, and there probably isn't an easy fix to allow the alternate solution to pass the tests. Just thought y'all should know.

@srush
Copy link
Contributor

srush commented Feb 7, 2022

Thanks! Someone else mentioned this as well. Needs to be fixed.

@ingambe
Copy link

ingambe commented Mar 21, 2022

Indeed, this issue occurs when all the operations do not return a float.
I manage to pass the test with Add.apply(self, Neg.apply(b)) by defining the negation operation as:
return -1.0 * x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants