Shibli Shibli - 1 year ago 97
Python Question

sympy.geometry Point class is working slow

I have a code which reads unstructured mesh. I wrote wrappers around geometric entities of

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
takes a lot of time for each
. 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
converts floating point numbers to rationals for precision. Is there a way (flag) to speed up
as I do not need exact precision?

Jim Jim
Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download