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

Return TWave on multiplication with scalar. #8895

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Return TWave on multiplication with scalar. #8895

wants to merge 1 commit into from

Conversation

darshanime
Copy link
Contributor

Same as #8888
Sorry for the inconvenience.

On trying to multiply TWave object from sympy.physics.optics module with a scalar, sympy.core.mul.Mul was returned.
PR to return TWave with amplitude scaled.

@debugger22
Copy link
Member

Why a new PR?

@darshanime
Copy link
Contributor Author

Had a bad rebase.

@debugger22
Copy link
Member

Had a bad rebase.

It's ok. You should have asked on the same PR.

Let's wait for the tests to pass.

@darshanime
Copy link
Contributor Author

Next time I will keep that in mind.
Thanks !

@darshanime
Copy link
Contributor Author

Did it fail because the docstring example comes before the __mul__ implementation ?

Error log :

File "/home/travis/virtualenv/python2.6.9/lib/python2.6/site-packages/sympy-0.7.6_git-py2.6.egg/sympy/physics/optics/waves.py", line 75, in sympy.physics.optics.waves.TWave
Failed example:
w4.amplitude
Exception raised:
Traceback (most recent call last):
File "/opt/python/2.6.9/lib/python2.6/doctest.py", line 1253, in __run
compileflags, 1) in test.globs
File "<doctest sympy.physics.optics.waves.TWave[12]>", line 1, in <module>
w4.amplitude
AttributeError: 'Mul' object has no attribute 'amplitude'

@kevinventullo
Copy link
Contributor

I think it failed because TWave.__mul__ only gets called when you have an expression of the form TWave*Scalar, rather than Scalar*TWave. Thus the latter will still return a Mul.

Can I make changes to this PR?

@darshanime
Copy link
Contributor Author

@kevinventullo Maybe you are right. Implemented __rmul__
This should hopefully pass the tests. Thanks for the hint !

@darshanime
Copy link
Contributor Author

@debugger22 Checks passed. Please review.

@debugger22
Copy link
Member

Looks good to me.
I'll merge it tomorrow if nobody has any objection.

Please squash all your commits into one.

@@ -246,6 +251,12 @@ def __str__(self):

__repr__ = __str__

def __mul__(self, float):
return TWave(self._amplitude*float, self._frequency, self._phase)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the fix here (#8908) is better. You are not checking for the type of your variable float.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am only accepting float unlike other taken by #8908.
Should we close this PR in the interest of #8908 ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of the variable doesn't matter. You should always name the second argument to these functions other. Definitely don't name it float, which overwrites a builtin.

@@ -24,7 +24,7 @@ class TWave(Expr):
they can be changed later with respective methods provided.

It has been represented as :math:`A \times cos(k*x - \omega \times t + \phi )`
where :math:`A` is amplitude, :math:`\omega` is angular velocity, :math:`k`is
where :math:`A` is amplitude, :math:`\omega` is angular frequency, :math:`k`is
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not in the other PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Asked the author of that PR to make the change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I added that change to my PR.

@czgdp1807
Copy link
Member

@darshanime Would you still like to work on this PR? It looks like a good addition.

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.

6 participants