Skip to content
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

matmul operator doesn't work on Python 3.4 and less. #18

Closed
marcrleonard opened this issue Dec 7, 2017 · 4 comments
Closed

matmul operator doesn't work on Python 3.4 and less. #18

marcrleonard opened this issue Dec 7, 2017 · 4 comments

Comments

@marcrleonard
Copy link

marcrleonard commented Dec 7, 2017

from p5 import *

def setup():
    size(640, 360)
    no_stroke()
    background(204)

def draw():
    if mouse_is_pressed:
        fill(random_uniform(255), random_uniform(127), random_uniform(51), 127)
    else:
        fill(255, 15)

    circle_size = random_uniform(low=10, high=80)

    circle((mouse_x, mouse_y), circle_size)

def key_pressed(event):
    background(204)

run()

I'm running p5 in a pipenv environment, python 3.4
Every sketch I run yields an error in OSX:

Traceback (most recent call last):
  File "/Users/marcleonard/Projects/p5/sketch.py", line 1, in <module>
    from p5 import *
  File "/Users/marcleonard/.local/share/virtualenvs/p5-vgNG_uZz/lib/python3.4/site-packages/p5/__init__.py", line 19, in <module>
    from .sketch import *
  File "/Users/marcleonard/.local/share/virtualenvs/p5-vgNG_uZz/lib/python3.4/site-packages/p5/sketch/__init__.py", line 19, in <module>
    from .base import *
  File "/Users/marcleonard/.local/share/virtualenvs/p5-vgNG_uZz/lib/python3.4/site-packages/p5/sketch/base.py", line 29, in <module>
    from ..opengl import renderer
  File "/Users/marcleonard/.local/share/virtualenvs/p5-vgNG_uZz/lib/python3.4/site-packages/p5/opengl/__init__.py", line 19, in <module>
    from .renderer import *
  File "/Users/marcleonard/.local/share/virtualenvs/p5-vgNG_uZz/lib/python3.4/site-packages/p5/opengl/renderer.py", line 33, in <module>
    from ..pmath import matrix
  File "/Users/marcleonard/.local/share/virtualenvs/p5-vgNG_uZz/lib/python3.4/site-packages/p5/pmath/__init__.py", line 20, in <module>
    from .vector import *
  File "/Users/marcleonard/.local/share/virtualenvs/p5-vgNG_uZz/lib/python3.4/site-packages/p5/pmath/vector.py", line 321
    return np.arccos( (self @ other) / (self.magnitude * other.magnitude))
                            ^
SyntaxError: invalid syntax
@marcrleonard marcrleonard changed the title Every script gives me a syntax error in Every script gives me a syntax error Dec 7, 2017
@marcrleonard marcrleonard changed the title Every script gives me a syntax error '@' syntax error - SOLVED Dec 7, 2017
@marcrleonard
Copy link
Author

using the @ symbol for matrix multiplication was added in python3.5
https://www.python.org/dev/peps/pep-0465/

python3.5 should be listed as a requirement.

@abhikpal
Copy link
Member

abhikpal commented Dec 7, 2017

Ahh.. yes! Thanks for pointing that out! I think we can just change the code to not use @ for matrix multiplication. Someone just needs to read through the code and replace all @ with np.dot or equivalent.

@abhikpal abhikpal changed the title '@' syntax error - SOLVED matmul operator doesn't work on Python 3.4 and less. Dec 7, 2017
@arihantparsoya
Copy link
Member

Even after replacing all @ with np.dot there are problems with python3.4 version:

    from p5 import *
  File "/Users/arihantparsoya/Documents/p5/p5/__init__.py", line 19, in <module>
    from .sketch import *
  File "/Users/arihantparsoya/Documents/p5/p5/sketch/__init__.py", line 19, in <module>
    from .base import *
  File "/Users/arihantparsoya/Documents/p5/p5/sketch/base.py", line 29, in <module>
    from ..opengl import renderer
  File "/Users/arihantparsoya/Documents/p5/p5/opengl/__init__.py", line 19, in <module>
    from .renderer import *
  File "/Users/arihantparsoya/Documents/p5/p5/opengl/renderer.py", line 33, in <module>
    from ..pmath import matrix
  File "/Users/arihantparsoya/Documents/p5/p5/pmath/__init__.py", line 22, in <module>
    from .curves import *
  File "/Users/arihantparsoya/Documents/p5/p5/pmath/curves.py", line 46
    ret_value = func(*new_args, parameter, **kwargs)
                                       ^
SyntaxError: only named arguments may follow *expression

arihantparsoya added a commit to arihantparsoya/p5 that referenced this issue Dec 24, 2017
Fixes p5py#18 .
Replaced all @ operator with np.dot since @ operator was introduced from python3.5
@abhikpal
Copy link
Member

Hmm.. interesting. I think the new culprit is the tuple unpacking:

    ret_value = func(*new_args, parameter, **kwargs)

We'll have to look through the code to see if this is really needed. If yes, then we add Python 3.5 as a dependency, else re-write it to be compatible for versions less than 3.5.

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

No branches or pull requests

3 participants