sympy.geometry Point class is working slow

无人久伴 提交于 2020-01-04 07:33:39

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/38830236/sympy-geometry-point-class-is-working-slow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!