Reputation: 6149
I have a code which reads unstructured mesh. I wrote wrappers around geometric entities of sympy.geometry
such as:
class Point:
def __init__(self, x, y, parent_mesh):
self.shape = sympy.geometry.Point(x,y)
self.parent_mesh = parent_mesh
self.parent_cell = list()
Everything works fine but initialization of sympy.geometry.Point
takes a lot of time for each Point
. Actually, the code did not finish execution for thousands of points. Similar code written in C++ finished in a few seconds. Without it the code is fast enough (I removed it and timed). I read that a possible reason could be that sympy.geometry
converts floating point numbers to rationals for precision. Is there a way (flag) to speed up sympy.geometry
as I do not need exact precision?
Upvotes: 3
Views: 871
Reputation: 160447
Take a look at the Point
class documentation, specifically, in one of the first examples:
Floats are automatically converted to Rational unless the evaluate flag is
False
.
So, you could pass a flag named evaluate
during initialization of your Point
classes:
self.shape = sympy.geometry.Point(x,y, evaluate=False)
which apparently signals what you're after.
Upvotes: 5