From 943729592b380dc58368b6774ad7baa53469466c Mon Sep 17 00:00:00 2001 From: Ankit Dwivedi Date: Sat, 7 Aug 2021 06:09:47 +0000 Subject: ignore whitespaces while parsing gufunc signatures --- numpy/lib/function_base.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'numpy/lib/function_base.py') diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index b43a1d666..93aea46c7 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -1844,9 +1844,9 @@ def disp(mesg, device=None, linefeed=True): # See https://docs.scipy.org/doc/numpy/reference/c-api.generalized-ufuncs.html -_DIMENSION_NAME = r'\w+' +_DIMENSION_NAME = r'\s*\w+\s*' _CORE_DIMENSION_LIST = '(?:{0:}(?:,{0:})*)?'.format(_DIMENSION_NAME) -_ARGUMENT = r'\({}\)'.format(_CORE_DIMENSION_LIST) +_ARGUMENT = r'\s*\({}\s*\)\s*'.format(_CORE_DIMENSION_LIST) _ARGUMENT_LIST = '{0:}(?:,{0:})*'.format(_ARGUMENT) _SIGNATURE = '^{0:}->{0:}$'.format(_ARGUMENT_LIST) @@ -1869,7 +1869,7 @@ def _parse_gufunc_signature(signature): if not re.match(_SIGNATURE, signature): raise ValueError( 'not a valid gufunc signature: {}'.format(signature)) - return tuple([tuple(re.findall(_DIMENSION_NAME, arg)) + return tuple([tuple([dim.strip() for dim in re.findall(_DIMENSION_NAME, arg)]) for arg in re.findall(_ARGUMENT, arg_list)] for arg_list in signature.split('->')) -- cgit v1.2.1 From 9d9cb200cb2d8c24d648f342ecc67b90efcf1f48 Mon Sep 17 00:00:00 2001 From: Ankit Dwivedi Date: Sat, 7 Aug 2021 16:05:07 +0000 Subject: fix lint errors --- numpy/lib/function_base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'numpy/lib/function_base.py') diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 93aea46c7..8d5264123 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -1869,7 +1869,8 @@ def _parse_gufunc_signature(signature): if not re.match(_SIGNATURE, signature): raise ValueError( 'not a valid gufunc signature: {}'.format(signature)) - return tuple([tuple([dim.strip() for dim in re.findall(_DIMENSION_NAME, arg)]) + return tuple([tuple([dim.strip() + for dim in re.findall(_DIMENSION_NAME, arg)]) for arg in re.findall(_ARGUMENT, arg_list)] for arg_list in signature.split('->')) -- cgit v1.2.1 From ed7f30db21f4510e3e6106a68991e8ee21d781ff Mon Sep 17 00:00:00 2001 From: Ankit Dwivedi Date: Thu, 12 Aug 2021 00:37:47 +0530 Subject: replace whitespaces in the signature argument --- numpy/lib/function_base.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'numpy/lib/function_base.py') diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 8d5264123..6f19619bb 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -1844,9 +1844,9 @@ def disp(mesg, device=None, linefeed=True): # See https://docs.scipy.org/doc/numpy/reference/c-api.generalized-ufuncs.html -_DIMENSION_NAME = r'\s*\w+\s*' +_DIMENSION_NAME = r'\w+' _CORE_DIMENSION_LIST = '(?:{0:}(?:,{0:})*)?'.format(_DIMENSION_NAME) -_ARGUMENT = r'\s*\({}\s*\)\s*'.format(_CORE_DIMENSION_LIST) +_ARGUMENT = r'\({}\)'.format(_CORE_DIMENSION_LIST) _ARGUMENT_LIST = '{0:}(?:,{0:})*'.format(_ARGUMENT) _SIGNATURE = '^{0:}->{0:}$'.format(_ARGUMENT_LIST) @@ -1866,11 +1866,12 @@ def _parse_gufunc_signature(signature): Tuple of input and output core dimensions parsed from the signature, each of the form List[Tuple[str, ...]]. """ + signature = re.sub(r'\s+', '', signature) + if not re.match(_SIGNATURE, signature): raise ValueError( 'not a valid gufunc signature: {}'.format(signature)) - return tuple([tuple([dim.strip() - for dim in re.findall(_DIMENSION_NAME, arg)]) + return tuple([tuple(re.findall(_DIMENSION_NAME, arg)) for arg in re.findall(_ARGUMENT, arg_list)] for arg_list in signature.split('->')) -- cgit v1.2.1 From a562cb2d44760d01a5481280d98248026fabeb40 Mon Sep 17 00:00:00 2001 From: Ghiles Meddour Date: Tue, 17 Aug 2021 23:40:56 +0200 Subject: DOC: Fix typo in `unwrap` docstring. --- numpy/lib/function_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'numpy/lib/function_base.py') diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 6f19619bb..d875a00ae 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -1512,7 +1512,7 @@ def unwrap(p, discont=None, axis=-1, *, period=2*pi): difference from their predecessor of more than ``max(discont, period/2)`` to their `period`-complementary values. - For the default case where `period` is :math:`2\pi` and is `discont` is + For the default case where `period` is :math:`2\pi` and `discont` is :math:`\pi`, this unwraps a radian phase `p` such that adjacent differences are never greater than :math:`\pi` by adding :math:`2k\pi` for some integer :math:`k`. -- cgit v1.2.1