Shibli
Shibli

Reputation: 6149

sympy.geometry Point class is working slow

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

Answers (1)

Dimitris Fasarakis Hilliard
Dimitris Fasarakis Hilliard

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

Related Questions