Skip to content

Smoke valid args for binary ufunc tests #18

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

Closed
wants to merge 22 commits into from
Closed

Conversation

honno
Copy link
Contributor

@honno honno commented Jan 9, 2023

This PR is WIP, and starts from #12 as it contains a critical fix.

The binary ufunc smoke tests were passing floats to functions that didn't accept them, which this PR fixes... kinda. Running autogen/gen_ufuncs.py as-is does not produce the same file structure as it exists for torch_np, and moving things over still breaks due to invalid import references.

So I can work on fixing these things generally, although IMO it looks like these smoke tests don't need to be generated by a script, but instead could be both generated and ran on runtime with pytest.mark.parametrize. Mind if I have a go exploring that?

ev-br and others added 22 commits January 5, 2023 16:38
Try to duck-type NumPy, only without array scalars, so that

* dtype('float32').type --> np.float32

and

* np.float32(3) --> array(3.0, dtype='float32)

IOW, the attempt is to only have zero-dim arrays (we have them anyway)
and have them everywhere where NumPy creates a scalar.
Try to duck-type NumPy, only without array scalars, so that

* dtype('float32').type --> np.float32

and

* np.float32(3) --> array(3.0, dtype='float32)

IOW, the attempt is to only have zero-dim arrays (we have them anyway)
and have them everywhere where NumPy creates a scalar.
So that current tests pass. This involves fixing a slew of small
issues all around but hey.
This is a stub, will need to decide and clearly articulate what exactly is a scalar.
Structured dtypes, longdoubles and all that.
Also make test_numerictypes from numpy pass. Remove weird things,
xfail the "scalar does not upcast array" test, fix up the rest.
The largest difference is that our type promotions are way simpler and
more straighforward. No "weak promotion", no values.
@ev-br
Copy link
Collaborator

ev-br commented Jan 9, 2023

These smoke tests certainly do not need to be generated by a script anymore, so please feel free to fix them! Also cf gh-17, which add a bunch of tests for this.

try:
other_instance = dtype(other)
except TypeError:
return False
Copy link
Collaborator

@ev-br ev-br Jan 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why it is better than raising? (Uhm, that was me. Meaning this code is not right, long tern)

return asarray(self._tensor >= asarray(other).get())

def __le__(self, other):
return asarray(self._tensor <= asarray(other).get())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NB: this will need to be redone similar to gh-17

from ..testing import assert_allclose


def test_add():
assert_allclose(np.add(0.5, 0.6),
add(0.5, 0.6), atol=1e-7, check_dtype=False)
np.add(0.5, 0.6), atol=1e-7, check_dtype=False)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert_allclose(np.add(0.5, 0.5), np.add(0.5, 0.6))?

@honno
Copy link
Contributor Author

honno commented Jan 16, 2023

Looks like the test inputs have now been fixed, so closing.

@honno honno closed this Jan 16, 2023
@honno honno deleted the smoke-valid-builtins branch January 16, 2023 11:31
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

Successfully merging this pull request may close these issues.

2 participants