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

Allow custom codegen class to be passed in to autowrap and codegen #12833

Merged
merged 17 commits into from Jul 1, 2017

Conversation

Projects
None yet
4 participants
@ixjlyons
Contributor

ixjlyons commented Jun 28, 2017

This feature would allow users to create their own code printer for use in autowrap and codegen. Here's a working example.

import sympy as sp
from sympy.printing.ccode import C99CodePrinter
from sympy.utilities.codegen import CCodeGen, codegen
from sympy.utilities.autowrap import autowrap

x = sp.symbols('x')

class CustomCCodePrinter(C99CodePrinter):
    _kf = dict(C99CodePrinter._kf, exp='fastexp')

class CustomCCodeGen(CCodeGen):
    printer = CustomCCodePrinter

    def _ccode(self, expr, assign_to=None, **settings):
        return self.printer(settings).doprint(expr, assign_to)

    def _indent_code(self, codelines):
        return self.printer().indent_code(codelines)

    def _preprocessor_statements(self, prefix):
        lines = super(CustomCCodeGen, self)._preprocessor_statements(prefix)
        lines.append("#include \"fastexp.h\"\n")
        return lines

#autowrap(sp.exp(x), language=CustomCCodeGen, backend='cython', tempdir='./tmp')

[(cname, ccode), (hname, hcode)] = codegen(('expr', sp.exp(x)), CustomCCodeGen)
print(ccode)

The autowrap line is commented out because compilation fails without passing compiler flags to tell it where the fastexp.h header is, but the generated code looks correct. Here's the codegen output:

/******************************************************************************
 *                    Code generated with sympy 1.0.1.dev                     *
 *                                                                            *
 *              See http://www.sympy.org/ for more information.               *
 *                                                                            *
 *                       This file is part of 'project'                       *
 ******************************************************************************/
#include "expr.h"
#include <math.h>
#include "fastexp.h"

double expr(double x) {

   double expr_result;
   expr_result = fastexp(x);
   return expr_result;

}

Updates to the docstring of autowrap and codegen would still be needed, as well as tests. Submitting now to get feedback on how the feature itself and potential side effects.

Show outdated Hide outdated sympy/utilities/codegen.py
"OCTAVE": OctaveCodeGen,
"RUST": RustCodeGen}.get(language.upper())
if isinstance(language, type):
CodeGenClass = language

This comment has been minimized.

@asmeurer

asmeurer Jun 28, 2017

Member

Should allow instances too. You sometimes need to instantiate the class to set settings.

@asmeurer

asmeurer Jun 28, 2017

Member

Should allow instances too. You sometimes need to instantiate the class to set settings.

This comment has been minimized.

@ixjlyons

ixjlyons Jun 28, 2017

Contributor

For the code gen class? Doesn't it just take the project name in __init__? I was originally hoping to be able to use an instance of a custom printer, but I didn't get that working because the code gen class instantiates the printer with different settings in a couple places (e.g. human, dereference, etc.).

@ixjlyons

ixjlyons Jun 28, 2017

Contributor

For the code gen class? Doesn't it just take the project name in __init__? I was originally hoping to be able to use an instance of a custom printer, but I didn't get that working because the code gen class instantiates the printer with different settings in a couple places (e.g. human, dereference, etc.).

This comment has been minimized.

@moorepants

moorepants Jun 28, 2017

Member

I think we'll have to live with this for now. Seems like the CCodeGen class would need to be reworked in the long run to accept a printer instance in its __init__ method for example.

@moorepants

moorepants Jun 28, 2017

Member

I think we'll have to live with this for now. Seems like the CCodeGen class would need to be reworked in the long run to accept a printer instance in its __init__ method for example.

@ixjlyons

This comment has been minimized.

Show comment
Hide comment
@ixjlyons

ixjlyons Jun 28, 2017

Contributor

I've cleaned up the interface to customizing the CCodeGen class a bit. It makes the original example I pasted above look more like this:

import sympy as sp
from sympy.printing.ccode import C99CodePrinter
from sympy.utilities.codegen import CCodeGen, codegen
from sympy.utilities.autowrap import autowrap

x = sp.symbols('x')

class CustomCCodePrinter(C99CodePrinter):
    _kf = dict(C99CodePrinter._kf, exp='fastexp')

class CustomCCodeGen(CCodeGen):
    printer_class = CustomCCodePrinter
    preprocessor_extras = ['#include "fastexp.h"\n']

result = codegen(('expr', sp.exp(x)), CustomCCodeGen)
print(result[0][1])

I'm still not seeing a way to use an instance of a custom code printer unless there is a way to update its settings like human after it's been created.

Also, having a preprocessor_extras class attribute might not be flexible enough, e.g. in case an extra header would have namespace clashes with math.h. In that case, I guess the _preprocessor_statements method could be left as is and the user would override it. Maybe make it a public method.

Contributor

ixjlyons commented Jun 28, 2017

I've cleaned up the interface to customizing the CCodeGen class a bit. It makes the original example I pasted above look more like this:

import sympy as sp
from sympy.printing.ccode import C99CodePrinter
from sympy.utilities.codegen import CCodeGen, codegen
from sympy.utilities.autowrap import autowrap

x = sp.symbols('x')

class CustomCCodePrinter(C99CodePrinter):
    _kf = dict(C99CodePrinter._kf, exp='fastexp')

class CustomCCodeGen(CCodeGen):
    printer_class = CustomCCodePrinter
    preprocessor_extras = ['#include "fastexp.h"\n']

result = codegen(('expr', sp.exp(x)), CustomCCodeGen)
print(result[0][1])

I'm still not seeing a way to use an instance of a custom code printer unless there is a way to update its settings like human after it's been created.

Also, having a preprocessor_extras class attribute might not be flexible enough, e.g. in case an extra header would have namespace clashes with math.h. In that case, I guess the _preprocessor_statements method could be left as is and the user would override it. Maybe make it a public method.

@moorepants

This comment has been minimized.

Show comment
Hide comment
@moorepants

moorepants Jun 28, 2017

Member

This seems like a bad design for the codeprinter:

class CustomCCodePrinter(C99CodePrinter):
    _kf = dict(C99CodePrinter._kf, exp='fastexp')
``
It should let you override `_print_exp()`. I'm not sure why this is like that.
Member

moorepants commented Jun 28, 2017

This seems like a bad design for the codeprinter:

class CustomCCodePrinter(C99CodePrinter):
    _kf = dict(C99CodePrinter._kf, exp='fastexp')
``
It should let you override `_print_exp()`. I'm not sure why this is like that.
@moorepants

This comment has been minimized.

Show comment
Hide comment
@moorepants

moorepants Jun 28, 2017

Member

I think this is a suitable solution to get this working. It just needs some tests to check if the preprocessor stuff was added in the source file and that the custom printer was properly set on the class.

Member

moorepants commented Jun 28, 2017

I think this is a suitable solution to get this working. It just needs some tests to check if the preprocessor stuff was added in the source file and that the custom printer was properly set on the class.

@moorepants

This comment has been minimized.

Show comment
Hide comment
@moorepants

moorepants Jun 28, 2017

Member

What's the plan to allow the user to set the custom class at the autowrap level?

Member

moorepants commented Jun 28, 2017

What's the plan to allow the user to set the custom class at the autowrap level?

@moorepants moorepants added this to the SymPy 1.1 milestone Jun 28, 2017

@ixjlyons

This comment has been minimized.

Show comment
Hide comment
@ixjlyons

ixjlyons Jun 28, 2017

Contributor

This seems like a bad design for the codeprinter

A minimally invasive solution might be writing a __new__ to take the known_functions dict and generate _print_Exp, _print_Cos, etc. methods for the class so they can be overriden. The user_functions solution is nice but it does reach its limit in this case.

What's the plan to allow the user to set the custom class at the autowrap level?

It should already "just work": pass in the class as the language arg. The compilation step fails because it can't find the header, but the generated code is correct.

edit: need to think more about checking backend in autowrap with a custom code gen class

Contributor

ixjlyons commented Jun 28, 2017

This seems like a bad design for the codeprinter

A minimally invasive solution might be writing a __new__ to take the known_functions dict and generate _print_Exp, _print_Cos, etc. methods for the class so they can be overriden. The user_functions solution is nice but it does reach its limit in this case.

What's the plan to allow the user to set the custom class at the autowrap level?

It should already "just work": pass in the class as the language arg. The compilation step fails because it can't find the header, but the generated code is correct.

edit: need to think more about checking backend in autowrap with a custom code gen class

@bjodah

This comment has been minimized.

Show comment
Hide comment
@bjodah

bjodah Jun 29, 2017

Member

I don't think we need to touch _kf:

In [2]: from sympy.printing.ccode import C99CodePrinter as CPrntr

In [3]: class MyCPrinter(CPrntr):
   ...:     def _print_exp(self, expr):
   ...:         return 'fastexp(%s)' % self._print(*expr.args)
   ...:     

In [4]: my_printer = MyCPrinter()

In [5]: my_printer.doprint(exp(x))
Out[5]: 'fastexp(x)'

or even:

In [7]: ccode(exp(x), user_functions={'exp': 'fastexp'})
Out[7]: 'fastexp(x)'

Regarding CodeGen/Routine/CodeWrapper/autowrap: it's a mess, I'm fine with invasive changes to it too (we should design something better eventually), right now it takes "heroic" efforts to extend it. I've been giving it a go the past hours (not successful yet -- I'll try some more).

Member

bjodah commented Jun 29, 2017

I don't think we need to touch _kf:

In [2]: from sympy.printing.ccode import C99CodePrinter as CPrntr

In [3]: class MyCPrinter(CPrntr):
   ...:     def _print_exp(self, expr):
   ...:         return 'fastexp(%s)' % self._print(*expr.args)
   ...:     

In [4]: my_printer = MyCPrinter()

In [5]: my_printer.doprint(exp(x))
Out[5]: 'fastexp(x)'

or even:

In [7]: ccode(exp(x), user_functions={'exp': 'fastexp'})
Out[7]: 'fastexp(x)'

Regarding CodeGen/Routine/CodeWrapper/autowrap: it's a mess, I'm fine with invasive changes to it too (we should design something better eventually), right now it takes "heroic" efforts to extend it. I've been giving it a go the past hours (not successful yet -- I'll try some more).

@bjodah

This comment has been minimized.

Show comment
Hide comment
@bjodah

bjodah Jun 29, 2017

Member

OK, I pushed to this branch after talking with @moorepants

This kind of "works":
https://gist.github.com/3238989b7a6df71f80a68dfb1793c901

But it feels like a horrible hack (but if you have a function called codegen and a class called CodeGen I suppose you get what you deserve... :/).

It's getting late here so I'll hand over to you guys and will catch up tomorrow morning. (I feel like quoting Churchill here...)

Member

bjodah commented Jun 29, 2017

OK, I pushed to this branch after talking with @moorepants

This kind of "works":
https://gist.github.com/3238989b7a6df71f80a68dfb1793c901

But it feels like a horrible hack (but if you have a function called codegen and a class called CodeGen I suppose you get what you deserve... :/).

It's getting late here so I'll hand over to you guys and will catch up tomorrow morning. (I feel like quoting Churchill here...)

@moorepants

This comment has been minimized.

Show comment
Hide comment
@moorepants

moorepants Jun 29, 2017

Member

It's looking good! Kenny's gonna add the code to deal with manipulating the include statements.

Member

moorepants commented Jun 29, 2017

It's looking good! Kenny's gonna add the code to deal with manipulating the include statements.

Show outdated Hide outdated sympy/utilities/tests/test_codegen.py
printer = C99CodePrinter(settings={'user_functions': {'exp': 'fastexp'}})
gen = C99CodeGen(printer=printer)
gen.preprocessor_statements.append('#include "fastexp.h"\n')

This comment has been minimized.

@moorepants

moorepants Jun 29, 2017

Member

I think it'd be a bit nicer if the user didn't have to append a \n to these strings.

@moorepants

moorepants Jun 29, 2017

Member

I think it'd be a bit nicer if the user didn't have to append a \n to these strings.

This comment has been minimized.

@ixjlyons

ixjlyons Jun 30, 2017

Contributor

Ok they're appended automatically now. It doesn't really hurt anything if the user wants to have a more complicated preprocessor statement.

@ixjlyons

ixjlyons Jun 30, 2017

Contributor

Ok they're appended automatically now. It doesn't really hurt anything if the user wants to have a more complicated preprocessor statement.

@moorepants moorepants changed the title from [WIP] Allow custom codegen class to be passed in to autowrap and codegen to Allow custom codegen class to be passed in to autowrap and codegen Jun 29, 2017

@asmeurer

This comment has been minimized.

Show comment
Hide comment
@asmeurer

asmeurer Jun 30, 2017

Member

If this needs to go in the release, close this PR and reopen it against the 1.1 branch.

Member

asmeurer commented Jun 30, 2017

If this needs to go in the release, close this PR and reopen it against the 1.1 branch.

@asmeurer asmeurer changed the base branch from master to 1.1 Jun 30, 2017

@asmeurer

This comment has been minimized.

Show comment
Hide comment
@asmeurer

asmeurer Jun 30, 2017

Member

Never mind you can change the base branch without creating a new PR.

Member

asmeurer commented Jun 30, 2017

Never mind you can change the base branch without creating a new PR.

@ixjlyons

This comment has been minimized.

Show comment
Hide comment
@ixjlyons

ixjlyons Jun 30, 2017

Contributor

The test failures aren't caused by this PR. They are caused by the RustCodeGen header output being tested with the sympy_version string centered. Since changing the base branch to 1.1, the version string is shorter than usual and the hard-coded centering in the test is incorrect. Other tests with header=True either do not center that line in the header output (Octave, Julia) or comment out the line in the test and do not use it to test the generated code (Fortran, C).

Should I resolve the merge conflicts myself, by the way? What is the appropriate way to do it? Rebase onto 1.1 or merge in 1.1?

Contributor

ixjlyons commented Jun 30, 2017

The test failures aren't caused by this PR. They are caused by the RustCodeGen header output being tested with the sympy_version string centered. Since changing the base branch to 1.1, the version string is shorter than usual and the hard-coded centering in the test is incorrect. Other tests with header=True either do not center that line in the header output (Octave, Julia) or comment out the line in the test and do not use it to test the generated code (Fortran, C).

Should I resolve the merge conflicts myself, by the way? What is the appropriate way to do it? Rebase onto 1.1 or merge in 1.1?

@bjodah

This comment has been minimized.

Show comment
Hide comment
@bjodah

bjodah Jun 30, 2017

Member

I usually just merge master on top and resolve merge conflicts in the merge commit. It would be nice if the tests could be changed so that they ignore comments in the code. Let me know if I can help.

Member

bjodah commented Jun 30, 2017

I usually just merge master on top and resolve merge conflicts in the merge commit. It would be nice if the tests could be changed so that they ignore comments in the code. Let me know if I can help.

@ixjlyons

This comment has been minimized.

Show comment
Hide comment
@ixjlyons

ixjlyons Jun 30, 2017

Contributor

Ok, this should be ready to go as long as Travis is happy.

Contributor

ixjlyons commented Jun 30, 2017

Ok, this should be ready to go as long as Travis is happy.

@asmeurer

This comment has been minimized.

Show comment
Hide comment
@asmeurer

asmeurer Jun 30, 2017

Member

Thanks for fixing the rust failure!

Member

asmeurer commented Jun 30, 2017

Thanks for fixing the rust failure!

@asmeurer

This comment has been minimized.

Show comment
Hide comment
@asmeurer

asmeurer Jul 1, 2017

Member

A bunch of tests fail for me locally

_________________________________________________ sympy/external/tests/test_autowrap.py:test_ufuncify_numpy __________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/external/tests/test_autowrap.py", line 269, in test_ufuncify_numpy
    runtest_ufuncify('C99', 'numpy')
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/external/tests/test_autowrap.py", line 97, in runtest_ufuncify
    fabc = ufuncify([a, b, c], a*b + c, backend=backend)
  File "/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/utilities/autowrap.py", line 1082, in ufuncify
    return code_wrapper.wrap_code(routines, helpers=helps)
  File "/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/utilities/autowrap.py", line 810, in wrap_code
    self._process_files(routines)
  File "/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/utilities/autowrap.py", line 170, in _process_files
    " ".join(command), e.output.decode()))
sympy.utilities.autowrap.CodeWrapError: Error while executing command: /Users/aaronmeurer/anaconda3/bin/python setup.py build_ext --inplace. Command output is:
running build_ext
running build_src
build_src
building extension "wrapper_module_18" sources
build_src: building npy-pkg config files
customize UnixCCompiler
customize UnixCCompiler using build_ext
building 'wrapper_module_18' extension
compiling C sources
C compiler: gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/aaronmeurer/anaconda3/include -arch x86_64

creating build
creating build/temp.macosx-10.9-x86_64-3.5
compile options: '-I/Users/aaronmeurer/anaconda3/lib/python3.5/site-packages/numpy/core/include -I/Users/aaronmeurer/anaconda3/include/python3.5m -c'
gcc: wrapper_module_18.c
In file included from wrapper_module_18.c:3:
In file included from /Users/aaronmeurer/anaconda3/lib/python3.5/site-packages/numpy/core/include/numpy/ndarraytypes.h:1777:
/Users/aaronmeurer/anaconda3/lib/python3.5/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: "Using deprecated NumPy API, disable it by "          "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-W#warnings]
#warning "Using deprecated NumPy API, disable it by " \
 ^
1 warning generated.
gcc: wrapped_code_18.c
wrapped_code_18.c:3:10: fatal error: 'shortpi.h' file not found
#include "shortpi.h"
         ^
1 error generated.
wrapped_code_18.c:3:10: fatal error: 'shortpi.h' file not found
#include "shortpi.h"
         ^
1 error generated.
error: Command "gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/aaronmeurer/anaconda3/include -arch x86_64 -I/Users/aaronmeurer/anaconda3/lib/python3.5/site-packages/numpy/core/include -I/Users/aaronmeurer/anaconda3/include/python3.5m -c wrapped_code_18.c -o build/temp.macosx-10.9-x86_64-3.5/wrapped_code_18.o" failed with exit status 1


______________________________________________________________________________________________________________________________________________________________
__________________________________________________ sympy/utilities/tests/test_codegen.py:test_empty_c_code ___________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 66, in test_empty_c_code
    assert source == "#include \"file.h\"\n#include <math.h>\n"
AssertionError
______________________________________________________________________________________________________________________________________________________________
____________________________________________ sympy/utilities/tests/test_codegen.py:test_empty_c_code_with_comment ____________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 76, in test_empty_c_code_with_comment
    assert source[158:] == (                                                              "*\n"
AssertionError
______________________________________________________________________________________________________________________________________________________________
__________________________________________________ sympy/utilities/tests/test_codegen.py:test_simple_c_code __________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 108, in test_simple_c_code
    assert source == expected
AssertionError
______________________________________________________________________________________________________________________________________________________________
______________________________________________ sympy/utilities/tests/test_codegen.py:test_c_code_reserved_words ______________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 126, in test_c_code_reserved_words
    assert source == expected
AssertionError
______________________________________________________________________________________________________________________________________________________________
_______________________________________________ sympy/utilities/tests/test_codegen.py:test_numbersymbol_c_code _______________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 143, in test_numbersymbol_c_code
    assert source == expected
AssertionError
______________________________________________________________________________________________________________________________________________________________
______________________________________________ sympy/utilities/tests/test_codegen.py:test_c_code_argument_order ______________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 161, in test_c_code_argument_order
    assert source == expected
AssertionError
______________________________________________________________________________________________________________________________________________________________
________________________________________________ sympy/utilities/tests/test_codegen.py:test_simple_c_codegen _________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 200, in test_simple_c_codegen
    assert result == expected
AssertionError
______________________________________________________________________________________________________________________________________________________________
_______________________________________________ sympy/utilities/tests/test_codegen.py:test_ansi_math1_codegen ________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 244, in test_ansi_math1_codegen
    '#include "file.h"\n#include <math.h>\n'
AssertionError
______________________________________________________________________________________________________________________________________________________________
_______________________________________________ sympy/utilities/tests/test_codegen.py:test_ansi_math2_codegen ________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 286, in test_ansi_math2_codegen
    '#include "file.h"\n#include <math.h>\n'
AssertionError
______________________________________________________________________________________________________________________________________________________________
_______________________________________________ sympy/utilities/tests/test_codegen.py:test_complicated_codegen _______________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 309, in test_complicated_codegen
    '#include "file.h"\n#include <math.h>\n'
AssertionError
______________________________________________________________________________________________________________________________________________________________
_____________________________________________________ sympy/utilities/tests/test_codegen.py:test_loops_c _____________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 399, in test_loops_c
    code == expected % {'rhs': 'x[j]*A[%s]' % (j + i*n)})
AssertionError
______________________________________________________________________________________________________________________________________________________________
__________________________________________________ sympy/utilities/tests/test_codegen.py:test_dummy_loops_c __________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 428, in test_dummy_loops_c
    assert code == expected
AssertionError
______________________________________________________________________________________________________________________________________________________________
_________________________________________________ sympy/utilities/tests/test_codegen.py:test_partial_loops_c _________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 466, in test_partial_loops_c
    code == expected % {'rhs': 'x[j]*A[%s]' % (j + i*p)})
AssertionError
______________________________________________________________________________________________________________________________________________________________
__________________________________________________ sympy/utilities/tests/test_codegen.py:test_output_arg_c ___________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 493, in test_output_arg_c
    assert result[0][1] == expected
AssertionError
______________________________________________________________________________________________________________________________________________________________
___________________________________________ sympy/utilities/tests/test_codegen.py:test_output_arg_c_reserved_words ___________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 513, in test_output_arg_c_reserved_words
    assert result[0][1] == expected
AssertionError
______________________________________________________________________________________________________________________________________________________________
___________________________________________ sympy/utilities/tests/test_codegen.py:test_ccode_results_named_ordered ___________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 541, in test_ccode_results_named_ordered
    assert source == expected
AssertionError
______________________________________________________________________________________________________________________________________________________________
____________________________________________ sympy/utilities/tests/test_codegen.py:test_ccode_matrixsymbol_slice _____________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 571, in test_ccode_matrixsymbol_slice
    assert source == expected
AssertionError
______________________________________________________________________________________________________________________________________________________________
___________________________________________________ sympy/utilities/tests/test_codegen.py:test_global_vars ___________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 1443, in test_global_vars
    assert source == expected
AssertionError
______________________________________________________________________________________________________________________________________________________________
_________________________________________________ sympy/utilities/tests/test_codegen.py:test_custom_codegen __________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 1469, in test_custom_codegen
    assert source == expected
AssertionError

============ tests finished: 853 passed, 19 failed, 4 skipped, 14 expected to fail, 1 expected to fail but passed, 1 exceptions, in 70.60 seconds ============
DO *NOT* COMMIT!

Also, can you go ahead and add yourself to the AUTHORS file (run python36 bin/authors_update.py and commit the result).

Member

asmeurer commented Jul 1, 2017

A bunch of tests fail for me locally

_________________________________________________ sympy/external/tests/test_autowrap.py:test_ufuncify_numpy __________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/external/tests/test_autowrap.py", line 269, in test_ufuncify_numpy
    runtest_ufuncify('C99', 'numpy')
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/external/tests/test_autowrap.py", line 97, in runtest_ufuncify
    fabc = ufuncify([a, b, c], a*b + c, backend=backend)
  File "/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/utilities/autowrap.py", line 1082, in ufuncify
    return code_wrapper.wrap_code(routines, helpers=helps)
  File "/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/utilities/autowrap.py", line 810, in wrap_code
    self._process_files(routines)
  File "/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/utilities/autowrap.py", line 170, in _process_files
    " ".join(command), e.output.decode()))
sympy.utilities.autowrap.CodeWrapError: Error while executing command: /Users/aaronmeurer/anaconda3/bin/python setup.py build_ext --inplace. Command output is:
running build_ext
running build_src
build_src
building extension "wrapper_module_18" sources
build_src: building npy-pkg config files
customize UnixCCompiler
customize UnixCCompiler using build_ext
building 'wrapper_module_18' extension
compiling C sources
C compiler: gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/aaronmeurer/anaconda3/include -arch x86_64

creating build
creating build/temp.macosx-10.9-x86_64-3.5
compile options: '-I/Users/aaronmeurer/anaconda3/lib/python3.5/site-packages/numpy/core/include -I/Users/aaronmeurer/anaconda3/include/python3.5m -c'
gcc: wrapper_module_18.c
In file included from wrapper_module_18.c:3:
In file included from /Users/aaronmeurer/anaconda3/lib/python3.5/site-packages/numpy/core/include/numpy/ndarraytypes.h:1777:
/Users/aaronmeurer/anaconda3/lib/python3.5/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: "Using deprecated NumPy API, disable it by "          "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-W#warnings]
#warning "Using deprecated NumPy API, disable it by " \
 ^
1 warning generated.
gcc: wrapped_code_18.c
wrapped_code_18.c:3:10: fatal error: 'shortpi.h' file not found
#include "shortpi.h"
         ^
1 error generated.
wrapped_code_18.c:3:10: fatal error: 'shortpi.h' file not found
#include "shortpi.h"
         ^
1 error generated.
error: Command "gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/aaronmeurer/anaconda3/include -arch x86_64 -I/Users/aaronmeurer/anaconda3/lib/python3.5/site-packages/numpy/core/include -I/Users/aaronmeurer/anaconda3/include/python3.5m -c wrapped_code_18.c -o build/temp.macosx-10.9-x86_64-3.5/wrapped_code_18.o" failed with exit status 1


______________________________________________________________________________________________________________________________________________________________
__________________________________________________ sympy/utilities/tests/test_codegen.py:test_empty_c_code ___________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 66, in test_empty_c_code
    assert source == "#include \"file.h\"\n#include <math.h>\n"
AssertionError
______________________________________________________________________________________________________________________________________________________________
____________________________________________ sympy/utilities/tests/test_codegen.py:test_empty_c_code_with_comment ____________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 76, in test_empty_c_code_with_comment
    assert source[158:] == (                                                              "*\n"
AssertionError
______________________________________________________________________________________________________________________________________________________________
__________________________________________________ sympy/utilities/tests/test_codegen.py:test_simple_c_code __________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 108, in test_simple_c_code
    assert source == expected
AssertionError
______________________________________________________________________________________________________________________________________________________________
______________________________________________ sympy/utilities/tests/test_codegen.py:test_c_code_reserved_words ______________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 126, in test_c_code_reserved_words
    assert source == expected
AssertionError
______________________________________________________________________________________________________________________________________________________________
_______________________________________________ sympy/utilities/tests/test_codegen.py:test_numbersymbol_c_code _______________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 143, in test_numbersymbol_c_code
    assert source == expected
AssertionError
______________________________________________________________________________________________________________________________________________________________
______________________________________________ sympy/utilities/tests/test_codegen.py:test_c_code_argument_order ______________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 161, in test_c_code_argument_order
    assert source == expected
AssertionError
______________________________________________________________________________________________________________________________________________________________
________________________________________________ sympy/utilities/tests/test_codegen.py:test_simple_c_codegen _________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 200, in test_simple_c_codegen
    assert result == expected
AssertionError
______________________________________________________________________________________________________________________________________________________________
_______________________________________________ sympy/utilities/tests/test_codegen.py:test_ansi_math1_codegen ________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 244, in test_ansi_math1_codegen
    '#include "file.h"\n#include <math.h>\n'
AssertionError
______________________________________________________________________________________________________________________________________________________________
_______________________________________________ sympy/utilities/tests/test_codegen.py:test_ansi_math2_codegen ________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 286, in test_ansi_math2_codegen
    '#include "file.h"\n#include <math.h>\n'
AssertionError
______________________________________________________________________________________________________________________________________________________________
_______________________________________________ sympy/utilities/tests/test_codegen.py:test_complicated_codegen _______________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 309, in test_complicated_codegen
    '#include "file.h"\n#include <math.h>\n'
AssertionError
______________________________________________________________________________________________________________________________________________________________
_____________________________________________________ sympy/utilities/tests/test_codegen.py:test_loops_c _____________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 399, in test_loops_c
    code == expected % {'rhs': 'x[j]*A[%s]' % (j + i*n)})
AssertionError
______________________________________________________________________________________________________________________________________________________________
__________________________________________________ sympy/utilities/tests/test_codegen.py:test_dummy_loops_c __________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 428, in test_dummy_loops_c
    assert code == expected
AssertionError
______________________________________________________________________________________________________________________________________________________________
_________________________________________________ sympy/utilities/tests/test_codegen.py:test_partial_loops_c _________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 466, in test_partial_loops_c
    code == expected % {'rhs': 'x[j]*A[%s]' % (j + i*p)})
AssertionError
______________________________________________________________________________________________________________________________________________________________
__________________________________________________ sympy/utilities/tests/test_codegen.py:test_output_arg_c ___________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 493, in test_output_arg_c
    assert result[0][1] == expected
AssertionError
______________________________________________________________________________________________________________________________________________________________
___________________________________________ sympy/utilities/tests/test_codegen.py:test_output_arg_c_reserved_words ___________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 513, in test_output_arg_c_reserved_words
    assert result[0][1] == expected
AssertionError
______________________________________________________________________________________________________________________________________________________________
___________________________________________ sympy/utilities/tests/test_codegen.py:test_ccode_results_named_ordered ___________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 541, in test_ccode_results_named_ordered
    assert source == expected
AssertionError
______________________________________________________________________________________________________________________________________________________________
____________________________________________ sympy/utilities/tests/test_codegen.py:test_ccode_matrixsymbol_slice _____________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 571, in test_ccode_matrixsymbol_slice
    assert source == expected
AssertionError
______________________________________________________________________________________________________________________________________________________________
___________________________________________________ sympy/utilities/tests/test_codegen.py:test_global_vars ___________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 1443, in test_global_vars
    assert source == expected
AssertionError
______________________________________________________________________________________________________________________________________________________________
_________________________________________________ sympy/utilities/tests/test_codegen.py:test_custom_codegen __________________________________________________
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/utilities/tests/test_codegen.py", line 1469, in test_custom_codegen
    assert source == expected
AssertionError

============ tests finished: 853 passed, 19 failed, 4 skipped, 14 expected to fail, 1 expected to fail but passed, 1 exceptions, in 70.60 seconds ============
DO *NOT* COMMIT!

Also, can you go ahead and add yourself to the AUTHORS file (run python36 bin/authors_update.py and commit the result).

@ixjlyons

This comment has been minimized.

Show comment
Hide comment
@ixjlyons

ixjlyons Jul 1, 2017

Contributor

Should be fixed now, though I'm now getting an error in an unrelated test locally in test_cython_wrapper_compile_flags -- I think that's because the generated file names are hard-coded (e.g. wrapped_code_0.c) but the suffix is different for me.

Contributor

ixjlyons commented Jul 1, 2017

Should be fixed now, though I'm now getting an error in an unrelated test locally in test_cython_wrapper_compile_flags -- I think that's because the generated file names are hard-coded (e.g. wrapped_code_0.c) but the suffix is different for me.

@moorepants

This comment has been minimized.

Show comment
Hide comment
@moorepants

moorepants Jul 1, 2017

Member

My tests pass in external and utilities:

moorepants@garuda:sympy(pr-12833)$ bin/test sympy/utilities/
=============================================================================================== test process starts ===============================================================================================
executable:         /home/moorepants/miniconda3/bin/python  (3.5.3-final-0) [CPython]
architecture:       64-bit
cache:              yes
ground types:       python 
random seed:        84143524
hash randomization: on (PYTHONHASHSEED=2814741793)

sympy/utilities/tests/test_autowrap.py[10] ..........                                                                                                                                                          [OK]
sympy/utilities/tests/test_code_quality.py[6] ......                                                                                                                                                           [OK]
sympy/utilities/tests/test_codegen.py[52] ....................................................                                                                                                                 [OK]
sympy/utilities/tests/test_codegen_julia.py[32] .....f.......f..................                                                                                                                               [OK]
sympy/utilities/tests/test_codegen_octave.py[32] .....f.......f..................                                                                                                                              [OK]
sympy/utilities/tests/test_codegen_rust.py[21] .....f.......f.......                                                                                                                                           [OK]
sympy/utilities/tests/test_decorator.py[3] ...                                                                                                                                                                 [OK]
sympy/utilities/tests/test_enumerative.py[4] ...w                                                                                                                                                              [OK]
sympy/utilities/tests/test_iterables.py[37] .....................................                                                                                                                              [OK]
sympy/utilities/tests/test_lambdify.py[72] ................s...........................ssssssss....................                                                                                            [OK]
sympy/utilities/tests/test_misc.py[2] ..                                                                                                                                                                       [OK]
sympy/utilities/tests/test_module_imports.py[1] f                                                                                                                                                              [OK]
sympy/utilities/tests/test_pickling.py[39] .........f..........ff..f..........ff..                                                                                                                             [OK]
sympy/utilities/tests/test_pytest.py[7] .......                                                                                                                                                                [OK]
sympy/utilities/tests/test_source.py[2] ..                                                                                                                                                                     [OK]
sympy/utilities/tests/test_timeutils.py[1] .                                                                                                                                                                   [OK]

================================================================== tests finished: 298 passed, 10 skipped, 13 expected to fail, in 12.89 seconds ==================================================================
moorepants@garuda:sympy(pr-12833)$ bin/test sympy/external/
=============================================================================================== test process starts ===============================================================================================
executable:         /home/moorepants/miniconda3/bin/python  (3.5.3-final-0) [CPython]
architecture:       64-bit
cache:              yes
ground types:       python 
random seed:        3559338
hash randomization: on (PYTHONHASHSEED=1650015804)

sympy/external/tests/test_autowrap.py[13] .............                                                                                                                                                        [OK]
sympy/external/tests/test_codegen.py[9] ..s.s....                                                                                                                                                              [OK]
sympy/external/tests/test_importtools.py[4] ....                                                                                                                                                               [OK]
sympy/external/tests/test_numpy.py[23] .......................                                                                                                                                                 [OK]
sympy/external/tests/test_scipy.py[1] .                                                                                                                                                                        [OK]

============================================================================= tests finished: 48 passed, 2 skipped, in 26.92 seconds ==============================================================================
moorepants@garuda:sympy(pr-12833)$ 
Member

moorepants commented Jul 1, 2017

My tests pass in external and utilities:

moorepants@garuda:sympy(pr-12833)$ bin/test sympy/utilities/
=============================================================================================== test process starts ===============================================================================================
executable:         /home/moorepants/miniconda3/bin/python  (3.5.3-final-0) [CPython]
architecture:       64-bit
cache:              yes
ground types:       python 
random seed:        84143524
hash randomization: on (PYTHONHASHSEED=2814741793)

sympy/utilities/tests/test_autowrap.py[10] ..........                                                                                                                                                          [OK]
sympy/utilities/tests/test_code_quality.py[6] ......                                                                                                                                                           [OK]
sympy/utilities/tests/test_codegen.py[52] ....................................................                                                                                                                 [OK]
sympy/utilities/tests/test_codegen_julia.py[32] .....f.......f..................                                                                                                                               [OK]
sympy/utilities/tests/test_codegen_octave.py[32] .....f.......f..................                                                                                                                              [OK]
sympy/utilities/tests/test_codegen_rust.py[21] .....f.......f.......                                                                                                                                           [OK]
sympy/utilities/tests/test_decorator.py[3] ...                                                                                                                                                                 [OK]
sympy/utilities/tests/test_enumerative.py[4] ...w                                                                                                                                                              [OK]
sympy/utilities/tests/test_iterables.py[37] .....................................                                                                                                                              [OK]
sympy/utilities/tests/test_lambdify.py[72] ................s...........................ssssssss....................                                                                                            [OK]
sympy/utilities/tests/test_misc.py[2] ..                                                                                                                                                                       [OK]
sympy/utilities/tests/test_module_imports.py[1] f                                                                                                                                                              [OK]
sympy/utilities/tests/test_pickling.py[39] .........f..........ff..f..........ff..                                                                                                                             [OK]
sympy/utilities/tests/test_pytest.py[7] .......                                                                                                                                                                [OK]
sympy/utilities/tests/test_source.py[2] ..                                                                                                                                                                     [OK]
sympy/utilities/tests/test_timeutils.py[1] .                                                                                                                                                                   [OK]

================================================================== tests finished: 298 passed, 10 skipped, 13 expected to fail, in 12.89 seconds ==================================================================
moorepants@garuda:sympy(pr-12833)$ bin/test sympy/external/
=============================================================================================== test process starts ===============================================================================================
executable:         /home/moorepants/miniconda3/bin/python  (3.5.3-final-0) [CPython]
architecture:       64-bit
cache:              yes
ground types:       python 
random seed:        3559338
hash randomization: on (PYTHONHASHSEED=1650015804)

sympy/external/tests/test_autowrap.py[13] .............                                                                                                                                                        [OK]
sympy/external/tests/test_codegen.py[9] ..s.s....                                                                                                                                                              [OK]
sympy/external/tests/test_importtools.py[4] ....                                                                                                                                                               [OK]
sympy/external/tests/test_numpy.py[23] .......................                                                                                                                                                 [OK]
sympy/external/tests/test_scipy.py[1] .                                                                                                                                                                        [OK]

============================================================================= tests finished: 48 passed, 2 skipped, in 26.92 seconds ==============================================================================
moorepants@garuda:sympy(pr-12833)$ 
@moorepants

This comment has been minimized.

Show comment
Hide comment
@moorepants

moorepants Jul 1, 2017

Member

@ixjlyons What test is failing for your locally? Can you print the output?

Member

moorepants commented Jul 1, 2017

@ixjlyons What test is failing for your locally? Can you print the output?

@asmeurer asmeurer merged commit 7362545 into sympy:1.1 Jul 1, 2017

1 check was pending

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
@ixjlyons

This comment has been minimized.

Show comment
Hide comment
@ixjlyons

ixjlyons Jul 1, 2017

Contributor

@ixjlyons What test is failing for your locally? Can you print the output?

Hmm, can't seem to replicate now, but it was definitely sympy/utilities/tests/test_autowrap.py:test_cython_wrapper_compile_flags. It must have been something going on with how I was haphazardly running tests to fix the issue from before. Essentially the assertion(s) in that test failed because the file names were not wrapper_module_0.pyx, wrapped_code_0.c, etc. but instead something like wrapper_module_16.pyx. I don't quite understand how that would happen, but in my autowrap test, for example, I followed the example of another test by finding the file and substituting it in the expected string.

Contributor

ixjlyons commented Jul 1, 2017

@ixjlyons What test is failing for your locally? Can you print the output?

Hmm, can't seem to replicate now, but it was definitely sympy/utilities/tests/test_autowrap.py:test_cython_wrapper_compile_flags. It must have been something going on with how I was haphazardly running tests to fix the issue from before. Essentially the assertion(s) in that test failed because the file names were not wrapper_module_0.pyx, wrapped_code_0.c, etc. but instead something like wrapper_module_16.pyx. I don't quite understand how that would happen, but in my autowrap test, for example, I followed the example of another test by finding the file and substituting it in the expected string.

@moorepants

This comment has been minimized.

Show comment
Hide comment
@moorepants

moorepants Jul 1, 2017

Member

it has a counter and will increment that number based on how many times you run autowrap. You probably just incremented the counter while testing, whereas the testing is expecting the code to be generated from the first run of autowrap.

Member

moorepants commented Jul 1, 2017

it has a counter and will increment that number based on how many times you run autowrap. You probably just incremented the counter while testing, whereas the testing is expecting the code to be generated from the first run of autowrap.

@ixjlyons

This comment has been minimized.

Show comment
Hide comment
@ixjlyons

ixjlyons Jul 1, 2017

Contributor

Ah, yep. It fails if I run the external autowrap tests first:

kenny::kalman[~/s/sympy](.venv) » pytest sympy/external/tests/test_autowrap.py sympy/utilities/tests/test_autowrap.py 
======================================== test session starts =========================================
platform linux -- Python 3.6.1, pytest-3.1.2, py-1.4.34, pluggy-0.4.0
architecture: 64-bit
cache:        yes
ground types: python 

rootdir: /home/kenny/src/sympy, inifile:
collected 23 items 

sympy/external/tests/test_autowrap.py .............
sympy/utilities/tests/test_autowrap.py ...F......

                                           DO *NOT* COMMIT!                                           
============================================== FAILURES ==============================================
_________________________________ test_cython_wrapper_compile_flags __________________________________

    def test_cython_wrapper_compile_flags():
        from sympy import Equality
        x, y, z = symbols('x,y,z')
        routine = make_routine("test", Equality(z, x + y))
    
        code_gen = CythonCodeWrapper(CCodeGen())
    
        expected = """\
    try:
        from setuptools import setup
        from setuptools import Extension
    except ImportError:
        from distutils.core import setup
        from distutils.extension import Extension
    from Cython.Build import cythonize
    cy_opts = {}
    
    ext_mods = [Extension(
        'wrapper_module_0', ['wrapper_module_0.pyx', 'wrapped_code_0.c'],
        include_dirs=[],
        library_dirs=[],
        libraries=[],
        extra_compile_args=['-std=c99'],
        extra_link_args=[]
    )]
    setup(ext_modules=cythonize(ext_mods, **cy_opts))
    """
        temp_dir = tempfile.mkdtemp()
        setup_file_path = os.path.join(temp_dir, 'setup.py')
    
        code_gen._prepare_files(routine, build_dir=temp_dir)
        with open(setup_file_path) as f:
            setup_text = f.read()
>       assert setup_text == expected
E       AssertionError: assert 'try:\n    fr...**cy_opts))\n' == 'try:\n    fro...**cy_opts))\n'
E         Skipping 260 identical leading characters in diff, use -v to show
E         - er_module_20', ['wrapper_module_20.pyx', 'wrapped_code_20.c'],
E         ?           -                     -                      -
E         + er_module_0', ['wrapper_module_0.pyx', 'wrapped_code_0.c'],
E               include_dirs=[],
E               library_dirs=[],
E               libraries=[],...
E         
E         ...Full output truncated (5 lines hidden), use '-vv' to show

sympy/utilities/tests/test_autowrap.py:124: AssertionError
================================ 1 failed, 22 passed in 28.61 seconds ================================
Contributor

ixjlyons commented Jul 1, 2017

Ah, yep. It fails if I run the external autowrap tests first:

kenny::kalman[~/s/sympy](.venv) » pytest sympy/external/tests/test_autowrap.py sympy/utilities/tests/test_autowrap.py 
======================================== test session starts =========================================
platform linux -- Python 3.6.1, pytest-3.1.2, py-1.4.34, pluggy-0.4.0
architecture: 64-bit
cache:        yes
ground types: python 

rootdir: /home/kenny/src/sympy, inifile:
collected 23 items 

sympy/external/tests/test_autowrap.py .............
sympy/utilities/tests/test_autowrap.py ...F......

                                           DO *NOT* COMMIT!                                           
============================================== FAILURES ==============================================
_________________________________ test_cython_wrapper_compile_flags __________________________________

    def test_cython_wrapper_compile_flags():
        from sympy import Equality
        x, y, z = symbols('x,y,z')
        routine = make_routine("test", Equality(z, x + y))
    
        code_gen = CythonCodeWrapper(CCodeGen())
    
        expected = """\
    try:
        from setuptools import setup
        from setuptools import Extension
    except ImportError:
        from distutils.core import setup
        from distutils.extension import Extension
    from Cython.Build import cythonize
    cy_opts = {}
    
    ext_mods = [Extension(
        'wrapper_module_0', ['wrapper_module_0.pyx', 'wrapped_code_0.c'],
        include_dirs=[],
        library_dirs=[],
        libraries=[],
        extra_compile_args=['-std=c99'],
        extra_link_args=[]
    )]
    setup(ext_modules=cythonize(ext_mods, **cy_opts))
    """
        temp_dir = tempfile.mkdtemp()
        setup_file_path = os.path.join(temp_dir, 'setup.py')
    
        code_gen._prepare_files(routine, build_dir=temp_dir)
        with open(setup_file_path) as f:
            setup_text = f.read()
>       assert setup_text == expected
E       AssertionError: assert 'try:\n    fr...**cy_opts))\n' == 'try:\n    fro...**cy_opts))\n'
E         Skipping 260 identical leading characters in diff, use -v to show
E         - er_module_20', ['wrapper_module_20.pyx', 'wrapped_code_20.c'],
E         ?           -                     -                      -
E         + er_module_0', ['wrapper_module_0.pyx', 'wrapped_code_0.c'],
E               include_dirs=[],
E               library_dirs=[],
E               libraries=[],...
E         
E         ...Full output truncated (5 lines hidden), use '-vv' to show

sympy/utilities/tests/test_autowrap.py:124: AssertionError
================================ 1 failed, 22 passed in 28.61 seconds ================================
@asmeurer

This comment has been minimized.

Show comment
Hide comment
@asmeurer

asmeurer Jul 1, 2017

Member

Yes, reset the counter to 0 while testing. Can you make a PR to fix?

Member

asmeurer commented Jul 1, 2017

Yes, reset the counter to 0 while testing. Can you make a PR to fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment