-
Notifications
You must be signed in to change notification settings - Fork 59
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add faster c implementations for some functions in triangulation.py #243
base: main
Are you sure you want to change the base?
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.
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 |
Missing import.
b26b274
to
1b6ef17
Compare
@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 import adaptive
import numpy as np
def sphere(xyz):
x, y, z = xyz
a = 0.4
return x + 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=lambda l: 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.
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.
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.