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

Use vectorized operations to compute transformations #266

Merged
merged 2 commits into from
Oct 14, 2015

Conversation

oliverlee
Copy link
Contributor

Use vectorized Numpy operation to compute visualization frame
transformation matrices as this is much faster than using a for loop.
Each element of the transformation matrix is lambdified and stored in a
list of numerical transformations.

Individual element transforms that do not contain dynamic variables nor
constant variables are not returned as functions by lambdify and
subsequent evaluation for these elements is skipped. Element transforms
that contain constant variables but not dynamic variables are lambdified
with only the constant variables as arguments. These are only evaluated
once and then repeated for create of the visualization matrix
trajectory.

This commit resolves issue #32

@oliverlee oliverlee force-pushed the speedup-frame-transformations branch from c89e7bf to ccc6478 Compare October 7, 2015 14:31
@moorepants
Copy link
Member

Are there any tests for this code?

@moorepants
Copy link
Member

Please update with master.

@oliverlee oliverlee force-pushed the speedup-frame-transformations branch from ccc6478 to d8c273b Compare October 13, 2015 11:39
Use vectorized Numpy operation to compute visualization frame
transformation matrices as this is much faster than using a for loop.
Each element of the transformation matrix is lambdified and stored in a
list of numerical transformations.

Individual element transforms that do not contain dynamic variables nor
constant variables are not returned as functions by lambdify and
subsequent evaluation for these elements is skipped. Element transforms
that contain constant variables but not dynamic variables are lambdified
with only the constant variables as arguments. These are only evaluated
once and then repeated for create of the visualization matrix
trajectory.

This commit resolves issue pydy#32.
@oliverlee
Copy link
Contributor Author

It looks like there are no tests for the calculation of the transform matrices.

@moorepants
Copy link
Member

Would you be willing to create a regression test? You could run the code from master on an example and pull out some values and then make the test against them.

@oliverlee
Copy link
Contributor Author

No problem I'm already doing that now.

@oliverlee
Copy link
Contributor Author

Actually, there is already a regression test:

def test_numeric_transform(self):
self.list1 = [[0.5000000000000001, 0.5, \
-0.7071067811865475, 0.0, \
-0.14644660940672627, 0.8535533905932737, \
0.5, 0.0, \
0.8535533905932737, -0.14644660940672627, \
0.5000000000000001, 0.0, \
10.0, 10.0, 10.0, 1.0]]
self.list2 = [[-0.11518993731879767, 0.8178227645734215, \
-0.563823734943801, 0.0, \
0.1332055011661179, 0.5751927992738988, \
0.8070994598700584, 0.0, \
0.984371663956036, 0.017865313009926137, \
-0.17519491371464685, 0.0, \
20.0, 20.0, 20.0, 1.0]]
self.global_frame1.generate_transformation_matrix(self.I, self.O)
self.global_frame1.generate_numeric_transform_function(self.dynamic, \
self.parameters)
assert_allclose(self.global_frame1.\
evaluate_transformation_matrix(self.states, \
self.param_vals), self.list1)
self.global_frame2.generate_transformation_matrix(self.I, self.O)
self.global_frame2.generate_numeric_transform_function(self.dynamic, \
self.parameters)
assert_allclose(self.global_frame2.\
evaluate_transformation_matrix(self.states, \
self.param_vals), self.list2)

so I think we can merge this unless you have any other issues.

@moorepants
Copy link
Member

Sweet. Merging.

moorepants added a commit that referenced this pull request Oct 14, 2015
Use vectorized operations to compute transformations
@moorepants moorepants merged commit 42aae29 into pydy:master Oct 14, 2015
@oliverlee oliverlee deleted the speedup-frame-transformations branch October 17, 2015 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants