- Notifications
You must be signed in to change notification settings - Fork62
Add faster c implementations for some functions in triangulation.py#243
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This provides faster implementations for fast_norm, fast_2d_circumcircle, fast_3d_circumcircle, and fast_2d_point_in_simplex.
triangulation.c provides fast implementations for some of the functions in learner/triangulation.py
Wrong directory.
On running pip install adaptive, adaptive.triangulation will also be set up.
Missed a bracket.
basnijholt commentedDec 15, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
This is awesome! I'll check it out in more detail when I'm near my computer. Do you know if this speeds up the |
b26b274 to1b6ef17Comparebasnijholt commentedDec 15, 2019
@philippeitis, I hope you don't mind, but I solved the style issues in Also, when trying it out, I seem to get the following error When running importadaptiveimportnumpyasnpdefsphere(xyz):x,y,z=xyza=0.4returnx+z**2+np.exp(-(x**2+y**2+z**2-0.75**2)**2/a**4)learner=adaptive.LearnerND(sphere,bounds=[(-1,1), (-1,1), (-1,1)])runner=adaptive.runner.simple(learner,goal=lambdal:l.npoints>2000) To use your module in the |
Added more error strings and updated docstrings to include details about what the functions accept and when to use them.Expanded fast_2d_circumcircle, fast_3d_circumcircle to accept tuples and appropriately sized numpy arrays.
philippeitis commentedDec 15, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I've updated the functions and their docstrings, so calling help(adaptive.triangulation.{}) will yield useful information, and I added helpful error messages where necessary. fast_norm can handle one dimensional lists, tuples and numpy arrays. I've decided not to support arrays with more dimensions, as numpy's linear algebra library (eg. np.linalg.norm) is likely to be faster and more robust for these cases. fast_2d_circumcircle can handle lists of tuples, tuples of tuples, and numpy arrays that have at least 3 rows and exactly 2 columns - numpy.array([(1, 0), (0, 1), (-1, 0)]) is automatically converted to such an array, but this may not be the case if you're appending tuples. fast_2d_point_in_simplex takes a tuple as its first argument, a list of at least three tuples as its second argument, and a double as its third. I can add support for numpy arrays and lists here if necessary. |
Add newlines to docstring. Remove null checks that are unneeded after adding size checks, and add checks for successful PyFloat conversion.
Uh oh!
There was an error while loading.Please reload this page.
I implemented some of the functions in triangulation.py in C for a considerable speed boost in several situations. They may not support all list types that are used, but I tried to implement functionality for the ones I saw.
The timing differences are as follows, for 100000 iterations of arbitrarily chosen function arguments:
The difference is considerably large for fast_2d_circumcircle and fast_3d_circumcircle, as these use numpy array operations that massively slow the program down - getting rid of
in both of these functions would provide a considerable speedup - converting points to an array creates a lot of unnecessary overhead.