Skip to content

Clean up the data in test_type_promotion.py #26

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

Merged
merged 47 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
d4f8dea
Refactor things from `test_type_promotion.py` to `dtype_helpers.py`
honno Oct 5, 2021
d12808b
Meta test for promote_dtype
honno Oct 5, 2021
29cec27
Use full dtype names instead of shorthands
honno Oct 5, 2021
3f1060f
Use dtype object instead of name for dtype helpers
honno Oct 7, 2021
e4461b3
Improve parametrize names for scalar promotion tests
honno Oct 7, 2021
48fd544
Convert `dtype_signed` and `dtype_nbits` to dicts
honno Oct 7, 2021
8c5fad0
Use `dh.promotion_table` instead of `ah.promote_dtypes()`
honno Oct 8, 2021
c9d958e
Refactor `dtype_helpers`
honno Oct 8, 2021
c07ba0e
Rudimentary elementwise parameters refactor
honno Oct 11, 2021
19cfff7
Rudimentary operator parameters refactor
honno Oct 11, 2021
a113c7d
Merge branch 'master' into type-promotion-refactor
honno Oct 11, 2021
1c06936
Namespace some imports
honno Oct 11, 2021
85212da
Change promotion test names
honno Oct 11, 2021
ce6a7e8
Clarify operator-related variable names
honno Oct 11, 2021
eecae7d
Merge branch 'master' into type-promotion-refactor
honno Oct 12, 2021
dd3fb86
Refactor type promotion tests
honno Oct 12, 2021
043726d
Merge unary and binary tests
honno Oct 12, 2021
6efe39d
Remove unused `pytest` import in `test_array_helpers.py`
honno Oct 12, 2021
de5dd5a
Use a `defaultdict` for storing filters
honno Oct 12, 2021
331e95c
Type hint parameter generators
honno Oct 12, 2021
09d2281
Add filters to inplace operators test
honno Oct 12, 2021
5a06078
Make `op_to_func` public, use `promotion_table` in linalg tests
honno Oct 12, 2021
357aa94
Remove unnecessary TODO comment
honno Oct 12, 2021
612b358
Merge branch 'master' into type-promotion-refactor
honno Oct 13, 2021
26cf341
Move `ah*_objects` and `ah.dtype_ranges` into `dtype_helpers`
honno Oct 13, 2021
a0e410d
Move `ah.is_*_dtype` methods into `dtype_helpers`
honno Oct 13, 2021
6976d19
Rudimentary clean-up of scalar promotion test
honno Oct 13, 2021
b98997c
Ignore testing NaNs and infs in `test_type_promotion.py`
honno Oct 13, 2021
3fe4b07
Rudimentary array element factories for scalar promotion tests
honno Oct 13, 2021
198df7e
Remove elements factory
honno Oct 14, 2021
e40cac8
Reject on OverflowError
honno Oct 14, 2021
b37ecc9
Remove old scalar promotion tests
honno Oct 14, 2021
8e79ebf
Merge branch 'master' into type-promotion-refactor
honno Oct 14, 2021
06fc784
Construct `inplace_op_to_symbol` in `dtype_helpers`
honno Oct 14, 2021
eab08d9
Generate NaNs and infs for scalar promotion tests
honno Oct 14, 2021
4907178
Dont catch OverflowError for single array funcs
honno Oct 14, 2021
75f44d7
Fix regression of `dtype_objects` instead of updated `dtype_objs`
honno Oct 14, 2021
d4467f1
Sort `promotable_dtypes` without relying on dtype comparisons
honno Oct 14, 2021
7bc75f0
Merge branch 'master' into type-promotion-refactor
honno Oct 15, 2021
e558ff2
Merge branch 'master' into type-promotion-refactor
honno Oct 18, 2021
64ef13c
Don't rely on str(dtype) for parameter ids
honno Oct 18, 2021
8f33325
Pass func/op names in params
honno Oct 18, 2021
7acf87a
Shorten test method names
honno Oct 18, 2021
0ff687e
Replace input dtype categories with dtype objects
honno Oct 18, 2021
49279d5
Only use `_op_to_func` privately
honno Oct 18, 2021
086cc10
Replace `func_out_categories` with `func_returns_bool`
honno Oct 18, 2021
b7c0f51
Replace param generators with constructed lists
honno Oct 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 7 additions & 60 deletions array_api_tests/array_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
zeros, ones, full, bool, int8, int16, int32,
int64, uint8, uint16, uint32, uint64, float32,
float64, nan, inf, pi, remainder, divide, isinf,
negative, _integer_dtypes, _floating_dtypes,
_numeric_dtypes, _boolean_dtypes, _dtypes,
asarray)
from . import _array_module

negative, asarray)
# These are exported here so that they can be included in the special cases
# tests from this file.
from ._array_module import logical_not, subtract, floor, ceil, where
from . import dtype_helpers as dh


__all__ = ['all', 'any', 'logical_and', 'logical_or', 'logical_not', 'less',
'less_equal', 'greater', 'subtract', 'negative', 'floor', 'ceil',
Expand All @@ -25,9 +23,8 @@
'assert_isinf', 'positive_mathematical_sign',
'assert_positive_mathematical_sign', 'negative_mathematical_sign',
'assert_negative_mathematical_sign', 'same_sign',
'assert_same_sign', 'ndindex', 'promote_dtypes', 'float64',
'asarray', 'is_integer_dtype', 'is_float_dtype', 'dtype_ranges',
'full', 'true', 'false', 'isnan']
'assert_same_sign', 'ndindex', 'float64',
'asarray', 'full', 'true', 'false', 'isnan']

def zero(shape, dtype):
"""
Expand Down Expand Up @@ -111,7 +108,7 @@ def isnegzero(x):
# TODO: If copysign or signbit are added to the spec, use those instead.
shape = x.shape
dtype = x.dtype
if is_integer_dtype(dtype):
if dh.is_int_dtype(dtype):
return false(shape)
return equal(divide(one(shape, dtype), x), -infinity(shape, dtype))

Expand All @@ -122,7 +119,7 @@ def isposzero(x):
# TODO: If copysign or signbit are added to the spec, use those instead.
shape = x.shape
dtype = x.dtype
if is_integer_dtype(dtype):
if dh.is_int_dtype(dtype):
return true(shape)
return equal(divide(one(shape, dtype), x), infinity(shape, dtype))

Expand Down Expand Up @@ -311,37 +308,6 @@ def same_sign(x, y):
def assert_same_sign(x, y):
assert all(same_sign(x, y)), "The input arrays do not have the same sign"

integer_dtype_objects = [getattr(_array_module, t) for t in _integer_dtypes]
floating_dtype_objects = [getattr(_array_module, t) for t in _floating_dtypes]
numeric_dtype_objects = [getattr(_array_module, t) for t in _numeric_dtypes]
boolean_dtype_objects = [getattr(_array_module, t) for t in _boolean_dtypes]
integer_or_boolean_dtype_objects = integer_dtype_objects + boolean_dtype_objects
dtype_objects = [getattr(_array_module, t) for t in _dtypes]

def is_integer_dtype(dtype):
if dtype is None:
return False
return dtype in [int8, int16, int32, int64, uint8, uint16, uint32, uint64]

def is_float_dtype(dtype):
if dtype is None:
# numpy.dtype('float64') == None gives True
return False
# TODO: Return True even for floating point dtypes that aren't part of the
# spec, like np.float16
return dtype in [float32, float64]

dtype_ranges = {
int8: [-128, +127],
int16: [-32_768, +32_767],
int32: [-2_147_483_648, +2_147_483_647],
int64: [-9_223_372_036_854_775_808, +9_223_372_036_854_775_807],
uint8: [0, +255],
uint16: [0, +65_535],
uint32: [0, +4_294_967_295],
uint64: [0, +18_446_744_073_709_551_615],
}

def int_to_dtype(x, n, signed):
"""
Convert the Python integer x into an n bit signed or unsigned number.
Expand All @@ -363,22 +329,3 @@ def ndindex(shape):

"""
return itertools.product(*[range(i) for i in shape])

def promote_dtypes(dtype1, dtype2):
"""
Special case of result_type() which uses the exact type promotion table
from the spec.
"""
from .test_type_promotion import dtype_mapping, promotion_table

# Equivalent to this, but some libraries may not work properly with using
# dtype objects as dict keys
#
# d1, d2 = reverse_dtype_mapping[dtype1], reverse_dtype_mapping[dtype2]

d1 = [i for i in dtype_mapping if dtype_mapping[i] == dtype1][0]
d2 = [i for i in dtype_mapping if dtype_mapping[i] == dtype2][0]

if (d1, d2) not in promotion_table:
raise ValueError(f"{d1} and {d2} are not type promotable according to the spec (this may indicate a bug in the test suite).")
return dtype_mapping[promotion_table[d1, d2]]
Loading