Skip to content

MAINT: core: Remove duplicated inner loop e->e from log, exp, sin, cos, sqrt. #14554

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 1 commit into from
Sep 20, 2019

Conversation

WarrenWeckesser
Copy link
Member

@WarrenWeckesser WarrenWeckesser commented Sep 20, 2019

The ufuncs log, exp, sin, cos and sqrt had two occurrences of the signature
e->e, with the corresponding generic loop function PyUFunc_e_e_As_f_f.
This change removes the generation of the duplicated function from the
array of inner loops for these ufuncs. The first entry of e->e is
kept; tests fail if the first one is removed instead of the second.

…os, sqrt.

The ufuncs log, exp, sin, cos and sqrt had two occurrences of the signature
ee->e, with the corresponding generic loop function PyUFunc_e_e_As_f_f.
This change removes the generation of the duplicated function from the
array of inner loops for these ufuncs.  The *first* entry of ee->e is
kept; tests fail if the first one is removed instead of the second.
@WarrenWeckesser
Copy link
Member Author

I'm not sure what is going on with the PyPy tests. Apparently PyPy thinks
there is a syntax error in line 628 of bit_generator.pyx in numpy/random.

From the test run...

numpy/random/tests/test_direct.py ..............F................F...... [ 88%]
..........F.................F....                                        [ 88%]

The first error...

=================================== FAILURES ===================================
_____________________________ TestPhilox.test_cffi _____________________________

self = <numpy.random.tests.test_direct.TestPhilox object at 0x000000001ddb7e88>

    @pytest.mark.skipif(MISSING_CFFI, reason='cffi not available')
    def test_cffi(self):
        bit_generator = self.bit_generator(*self.data1['seed'])
>       cffi_interface = bit_generator.cffi

bit_generator = <numpy.random.philox.Philox object at 0x000000000838aa00>
self       = <numpy.random.tests.test_direct.TestPhilox object at 0x000000001ddb7e88>

numpy/random/tests/test_direct.py:285: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   ???
E     File "/home/vsts/work/1/s/pypy3/lib_pypy/cffi/_pycparser/c_lexer.py", line 55
E       self.line_pattern = re.compile('([ \t]*line\W)|([ \t]*\d+)')
E                                     ^
E   SyntaxError: invalid escape sequence 'd'

BitGenerator = <class 'numpy.random.bit_generator.BitGenerator'>
DECIMAL_RE = re.compile('[0-9]+')
ISeedSequence = <class 'numpy.random.bit_generator.ISeedSequence'>
ISpawnableSeedSequence = <class 'numpy.random.bit_generator.ISpawnableSeedSequence'>
Lock       = <built-in function allocate_lock>
SeedSequence = <class 'numpy.random.bit_generator.SeedSequence'>
SeedlessSeedSequence = <class 'numpy.random.bit_generator.SeedlessSeedSequence'>
SeedlessSequence = <class 'numpy.random.bit_generator.SeedlessSequence'>
__all__    = ['SeedSequence', 'BitGenerator']
__builtins__ = <builtins>
__doc__    = "\nBitGenerator base class and SeedSequence used to seed the BitGenerators.\n\nSeedSequence is derived from Melissa E....R OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
__file__   = '/home/vsts/work/1/s/build/testenv/site-packages/numpy/random/bit_generator.pypy3-73-x86_64-linux-gnu.so'
__loader__ = <_frozen_importlib_external.ExtensionFileLoader object at 0x00007f7b8e8c18a0>
__name__   = 'numpy.random.bit_generator'
__package__ = 'numpy.random'
__pyx_unpickle_SeedSequence = <builtin_function_or_method object at 0x00007f7b8e8c1868>
__pyx_unpickle_SeedlessSeedSequence = <builtin_function_or_method object at 0x00007f7b8e8c1830>
__spec__   = ModuleSpec(name='numpy.random.bit_generator', loader=<_frozen_importlib_external.ExtensionFileLoader object at 0x00007...8a0>, origin='/home/vsts/work/1/s/build/testenv/site-packages/numpy/random/bit_generator.pypy3-73-x86_64-linux-gnu.so')
__test__   = {'_coerce_to_uint32_array (line 90)': ' Coerce an input to a uint32 array.\n\n    If a `uint32` array, pass it through...901234567890)\n    array([3460238034, 2898026390, 3235640248, 2697535605,          3],\n          dtype=uint32)\n    '}
_coerce_to_uint32_array = <builtin_function_or_method object at 0x00007f7b8e89b360>
_int_to_uint32_array = <builtin_function_or_method object at 0x00007f7b8e89b398>
abc        = <module 'abc' from '/home/vsts/work/1/s/pypy3/lib-python/3/abc.py'>
cycle      = <class 'itertools.cycle'>
np         = <module 'numpy' from '/home/vsts/work/1/s/build/testenv/site-packages/numpy/__init__.py'>
randbits   = <bound method SystemRandom.getrandbits of <random.SystemRandom object at 0x00007f7b8e8cada0>>
re         = <module 're' from '/home/vsts/work/1/s/pypy3/lib-python/3/re.py'>
sys        = <module 'sys' (built-in)>

bit_generator.pyx:628: SyntaxError

@mattip
Copy link
Member

mattip commented Sep 20, 2019

Not related to this PR. I am checking ...

@eric-wieser
Copy link
Member

eric-wieser commented Sep 20, 2019

That is a syntax error (at least, in regular python 3.7 code). It should be

-self.line_pattern = re.compile('([ \t]*line\W)|([ \t]*\d+)')
+self.line_pattern = re.compile(r'([ \t]*line\W)|([ \t]*\d+)')

@mattip
Copy link
Member

mattip commented Sep 20, 2019

It is an issue with pycparser, that cffi uses internally, and only shows up on PyPy because we do not test python with cffi

Edit: wrong analysis: the problem is an old vendored version of pycparser inside PyPy

@mattip
Copy link
Member

mattip commented Sep 20, 2019

The reason it turned up now is that PyPy added the deprecation warnings (that exist in CPython3.6 since it was released) last night. In the mean time, I backed that change out of PyPy to unbreak NumPy builds

@mattip
Copy link
Member

mattip commented Sep 20, 2019

I edited my comment above, but just to make it clear: PyPy had an old vendored version of pycparser. Sorry for implying there were unresolved issues in the latest pycparser release

@WarrenWeckesser
Copy link
Member Author

@mattip, thanks for tracking down the issue.

@seberg
Copy link
Member

seberg commented Sep 20, 2019

OK, should be harmless (although in some cases it might take a few cpu cylce extra if there is a loop too much) and no need to have duplicate entries. Thanks @WarrenWeckesser.

@seberg seberg merged commit 61289fb into numpy:master Sep 20, 2019
@WarrenWeckesser WarrenWeckesser deleted the remove-dup-loop branch October 24, 2019 14:30
@WarrenWeckesser WarrenWeckesser changed the title MAINT: core: Remove duplicated inner loop ee->e from log, exp, sin, cos, sqrt. MAINT: core: Remove duplicated inner loop e->e from log, exp, sin, cos, sqrt. Sep 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants