diff options
author | Ankit Dwivedi <ankit_dwivedi@outlook.com> | 2021-08-12 00:37:47 +0530 |
---|---|---|
committer | Ankit Dwivedi <ankit_dwivedi@outlook.com> | 2021-08-12 00:37:47 +0530 |
commit | ed7f30db21f4510e3e6106a68991e8ee21d781ff (patch) | |
tree | 08747e40c529eb2120b1920f2399d568bcbdfbae /numpy/lib/function_base.py | |
parent | f42da0df031a98bb17d22025a837466450a2e041 (diff) | |
download | numpy-ed7f30db21f4510e3e6106a68991e8ee21d781ff.tar.gz |
replace whitespaces in the signature argument
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r-- | numpy/lib/function_base.py | 9 |
1 files changed, 5 insertions, 4 deletions
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('->')) |