output
stringlengths
1
928k
instruction
stringlengths
7
928k
system
stringlengths
0
104k
def ignored_double_corner( intersection, tangent_s, tangent_t, edge_nodes1, edge_nodes2 ): """Check if an intersection is an "ignored" double corner. .. note:: This is a helper used only by :func:`ignored_corner`, which in turn is only used by :func:`classify_intersection`. Helper for :...
How would you code a function in Python 3 to check if an intersection is an ignored double corner.
You are a Python code analyst, evaluating scripts for potential improvements.
Check if an intersection is an ignored corner.
Make a summary of the following Python 3 code def ignored_corner( intersection, tangent_s, tangent_t, edge_nodes1, edge_nodes2 ): """Check if an intersection is an "ignored" corner. .. note:: This is a helper used only by :func:`classify_intersection`. An "ignored" corner is one where the surf...
As a Python code analyst, you investigate and solve complex coding mysteries
This function handles the end of an intersection between two nodes.
Given the following Python 3 function, write the documentation def handle_ends(index1, s, index2, t): edge_end = False if s == 1.0: s = 0.0 index1 = (index1 + 1) % 3 edge_end = True # NOTE: This is not a typo, the values can be updated twice if both ``s`` # and ``t`` are ``...
You are a Python code analyst, evaluating scripts for potential improvements.
Rotates a node to the front.
Can you generate the documentation for the following Python 3 function def to_front(intersection, intersections, unused): if intersection.s == 1.0: next_index = (intersection.index_first + 1) % 3 # Make sure we haven't accidentally ignored an existing intersection. for other_int in intersect...
As a Python code translator, you convert algorithms and pseudocode into Python.
Gets the next node along the current edge.
Explain what the following Python 3 code does def get_next_first(intersection, intersections, to_end=True): along_edge = None index_first = intersection.index_first s = intersection.s for other_int in intersections: other_s = other_int.s if other_int.index_first == index_first and other_...
As a Python code translator, you convert algorithms and pseudocode into Python.
def get_next_second(intersection, intersections, to_end=True): """Gets the next node along the current (second) edge. .. note:: This is a helper used only by :func:`get_next`, which in turn is only used by :func:`basic_interior_combine`, which itself is only used by :func:`combine_interse...
Implement a function in Python 3 to get the next node along the current edge.
You are a Python code architect, reviewing and designing scalable and efficient code
def get_next_coincident(intersection, intersections): """Gets the next node along the current (coincident) edge. .. note:: This is a helper used only by :func:`get_next`, which in turn is only used by :func:`basic_interior_combine`, which itself is only used by :func:`combine_intersection...
Can you implement a function in Python 3 that gets the next node along the current edge.
You are a Python code generator, capable of creating scripts from specifications.
Gets the next node along a given edge.
Given the following Python 3 function, write the documentation def get_next(intersection, intersections, unused): result = None if is_first(intersection.interior_curve): result = get_next_first(intersection, intersections) elif is_second(intersection.interior_curve): result = get_next_second...
As a Python code composer, you craft elegant and concise scripts.
def ends_to_curve(start_node, end_node): """Convert a "pair" of intersection nodes to a curve segment. .. note:: This is a helper used only by :func:`basic_interior_combine`, which in turn is only used by :func:`combine_intersections`. .. note:: This function could specialize to the...
Can you write a function in Python 3 where it converts a pair of intersection nodes to a base curve segment.
As a Python code composer, you craft elegant and concise scripts.
r Determine if one surface is in the other.
Can you generate a brief explanation for the following Python 3 code def no_intersections(nodes1, degree1, nodes2, degree2): # NOTE: This is a circular import. from bezier import _surface_intersection located = _surface_intersection.locate_point( nodes2, degree2, nodes1[0, 0], nodes1[1, 0] ) ...
You are a Python code generator, capable of creating scripts from specifications.
Determine intersection in the case of only - tangent intersections.
Make a summary of the following Python 3 code def tangent_only_intersections(all_types): if len(all_types) != 1: raise ValueError("Unexpected value, types should all match", all_types) point_type = all_types.pop() if point_type == CLASSIFICATION_T.OPPOSED: return [], None elif point_ty...
You are a Python code analyst, evaluating scripts for potential improvements.
Combine intersections that don t involve tangencies.
Can you tell what is the following Python 3 function doing def basic_interior_combine(intersections, max_edges=10): unused = intersections[:] result = [] while unused: start = unused.pop() curr_node = start next_node = get_next(curr_node, intersections, unused) edge_ends = [(...
You are a Python code architect, reviewing and designing scalable and efficient code
r Combine two curved polygons into one.
Here you have a function in Python 3, explain what it does def combine_intersections( intersections, nodes1, degree1, nodes2, degree2, all_types ): r"""Combine curve-curve intersections into curved polygon(s). .. note:: This is a helper used only by :meth:`.Surface.intersect`. Does so assuming...
You are a Python code analyst, evaluating scripts for potential improvements.
r Evaluates a point on a single barycentric surface.
Can you tell what is the following Python 3 function doing def _evaluate_barycentric(nodes, degree, lambda1, lambda2, lambda3): dimension, num_nodes = nodes.shape binom_val = 1.0 result = np.zeros((dimension, 1), order="F") index = num_nodes - 1 result[:, 0] += nodes[:, index] # curve evaluate_m...
As a python code expert, you are capable of creating scripts from specifications.
def _compute_edge_nodes(nodes, degree): """Compute the nodes of each edges of a surface. .. note:: There is also a Fortran implementation of this function, which will be used if it can be built. Args: nodes (numpy.ndarray): Control point nodes that define the surface. degree...
Write a Python 3 script to compute the nodes of each edge of a base class.
As a Python code translator, you convert algorithms and pseudocode into Python.
r Compute an auxiliary shoelace sum used to compute area.
Here you have a function in Python 3, explain what it does def shoelace_for_area(nodes): _, num_nodes = nodes.shape if num_nodes == 2: shoelace = SHOELACE_LINEAR scale_factor = 2.0 elif num_nodes == 3: shoelace = SHOELACE_QUADRATIC scale_factor = 6.0 elif num_nodes == 4: ...
You are a Python code analyst, evaluating scripts for potential improvements.
def save_image(figure, filename): """Save an image to the docs images directory. Args: filename (str): The name of the file (not containing directory info). """ path = os.path.join(IMAGES_DIR, filename) figure.savefig(path, bbox_inches="tight") plt.close(figure)
Implement a function in Python 3 to save an image to the docs images directory.
You are a Python code analyst, evaluating scripts for potential improvements.
def stack1d(*points): """Fill out the columns of matrix with a series of points. This is because ``np.hstack()`` will just make another 1D vector out of them and ``np.vstack()`` will put them in the rows. Args: points (Tuple[numpy.ndarray, ...]): Tuple of 1D points (i.e. arrays wit...
Write a Python 3 function that can fill out the columns of matrix with a series of points.
As a Python code composer, you craft elegant and concise scripts.
Image for : func :. linearization_error docstring.
Can you tell what is the following Python 3 function doing def linearization_error(nodes): if NO_IMAGES: return curve = bezier.Curve.from_nodes(nodes) line = bezier.Curve.from_nodes(nodes[:, (0, -1)]) midpoints = np.hstack([curve.evaluate(0.5), line.evaluate(0.5)]) ax = curve.plot(256) ...
You are a Python code generator, capable of creating scripts from specifications.
def newton_refine1(s, new_s, curve1, t, new_t, curve2): """Image for :func:`.newton_refine` docstring.""" if NO_IMAGES: return points = np.hstack([curve1.evaluate(s), curve2.evaluate(t)]) points_new = np.hstack([curve1.evaluate(new_s), curve2.evaluate(new_t)]) ax = curve1.plot(256) curv...
Write a Python 3 script to image for : func :. newton_refine
You are a Python code generator, capable of creating scripts from specifications.
Image for : func :. newton_refine
How would you explain what the following Python 3 function does def newton_refine2(s_vals, curve1, curve2): if NO_IMAGES: return ax = curve1.plot(256) ax.lines[-1].zorder = 1 curve2.plot(256, ax=ax) ax.lines[-1].zorder = 1 points = curve1.evaluate_multi(np.asfortranarray(s_vals)) co...
You are a Python code generator, capable of creating scripts from specifications.
Image for : func :. segment_intersection
Can you generate the documentation for the following Python 3 function def segment_intersection1(start0, end0, start1, end1, s): if NO_IMAGES: return line0 = bezier.Curve.from_nodes(stack1d(start0, end0)) line1 = bezier.Curve.from_nodes(stack1d(start1, end1)) ax = line0.plot(2) line1.plot(2...
You are a Python code analyst, evaluating scripts for potential improvements.
Image for : func :. segment_intersection docstring.
Given the following Python 3 function, write the documentation def segment_intersection2(start0, end0, start1, end1): if NO_IMAGES: return line0 = bezier.Curve.from_nodes(stack1d(start0, end0)) line1 = bezier.Curve.from_nodes(stack1d(start1, end1)) ax = line0.plot(2) line1.plot(2, ax=ax) ...
As a Python code composer, you craft elegant and concise scripts.
Image for parallel lines parameters docstring.
Can you generate the documentation for the following Python 3 function def helper_parallel_lines(start0, end0, start1, end1, filename): if NO_IMAGES: return figure = plt.figure() ax = figure.gca() points = stack1d(start0, end0, start1, end1) ax.plot(points[0, :2], points[1, :2], marker="o")...
As a python code expert, you are capable of creating scripts from specifications.
def curve_constructor(curve): """Image for :class`.Curve` docstring.""" if NO_IMAGES: return ax = curve.plot(256) line = ax.lines[0] nodes = curve._nodes ax.plot( nodes[0, :], nodes[1, :], color="black", linestyle="None", marker="o" ) add_patch(ax, nodes, line.get_color(...
Can you implement a function in Python 3 that images for : class. Curve docstring.
As a python code expert, you are capable of creating scripts from specifications.
Image for : meth. Curve. evaluate docstring.
Given the following Python 3 function, write the documentation def curve_evaluate(curve): if NO_IMAGES: return ax = curve.plot(256) points = curve.evaluate_multi(np.asfortranarray([0.75])) ax.plot( points[0, :], points[1, :], color="black", linestyle="None", marker="o" ) ax.axis...
You are a Python code architect, reviewing and designing scalable and efficient code
Image for : meth. Curve. subdivide docstring.
Explain what the following Python 3 code does def curve_subdivide(curve, left, right): if NO_IMAGES: return figure = plt.figure() ax = figure.gca() add_patch(ax, curve._nodes, "gray") ax = left.plot(256, ax=ax) line = ax.lines[-1] add_patch(ax, left._nodes, line.get_color()) rig...
As a Python code analyst, you investigate and solve complex coding mysteries
def curve_intersect(curve1, curve2, s_vals): """Image for :meth`.Curve.intersect` docstring.""" if NO_IMAGES: return ax = curve1.plot(256) curve2.plot(256, ax=ax) intersections = curve1.evaluate_multi(s_vals) ax.plot( intersections[0, :], intersections[1, :], col...
Can you write a function in Python 3 where it images for : meth. Curve. intersect docstring.
You are a Python code architect, reviewing and designing scalable and efficient code
Image for : class. Surface docstring.
Make a summary of the following Python 3 code def surface_constructor(surface): if NO_IMAGES: return ax = surface.plot(256, with_nodes=True) line = ax.lines[0] nodes = surface._nodes add_patch(ax, nodes[:, (0, 1, 2, 5)], line.get_color()) delta = 1.0 / 32.0 ax.text( nodes[0,...
You are a Python code generator, capable of creating scripts from specifications.
def surface_evaluate_barycentric(surface, point): """Image for :meth`.Surface.evaluate_barycentric` docstring.""" if NO_IMAGES: return ax = surface.plot(256) ax.plot( point[0, :], point[1, :], color="black", linestyle="None", marker="o" ) ax.axis("scaled") ax.set_xlim(-0.125...
Can you implement a function in Python 3 that images for : meth. Surface. evaluate_barycentric docstring.
As a python code expert, you are capable of creating scripts from specifications.
def surface_evaluate_cartesian_multi(surface, points): """Image for :meth`.Surface.evaluate_cartesian_multi` docstring.""" if NO_IMAGES: return ax = surface.plot(256) ax.plot( points[0, :], points[1, :], color="black", linestyle="None", marker="o" ) delta = 1.0 / 32.0 font_s...
Can you implement a function in Python 3 that images for : meth. Surface. evaluate_cartesian_multi docstring.
As a python code expert, you are capable of creating scripts from specifications.
def surface_is_valid1(surface): """Image for :meth`.Surface.is_valid` docstring.""" if NO_IMAGES: return ax = surface.plot(256) ax.axis("scaled") ax.set_xlim(-0.125, 2.125) ax.set_ylim(-0.125, 2.125) save_image(ax.figure, "surface_is_valid1.png")
Write a Python 3 script to image for : meth. Surface. is_valid docstring.
As a Python code analyst, you investigate and solve complex coding mysteries
def surface_is_valid3(surface): """Image for :meth`.Surface.is_valid` docstring.""" if NO_IMAGES: return edge1, edge2, edge3 = surface.edges N = 128 # Compute points on each edge. std_s = np.linspace(0.0, 1.0, N + 1) points1 = edge1.evaluate_multi(std_s) points2 = edge2.evaluate...
How would you code a function in Python 3 to image for : meth. Surface. is_valid
As a Python code composer, you craft elegant and concise scripts.
def surface_subdivide1(): """Image for :meth`.Surface.subdivide` docstring.""" if NO_IMAGES: return surface = bezier.Surface.from_nodes( np.asfortranarray([[0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]) ) surf_a, surf_b, surf_c, surf_d = surface.subdivide() figure, ((ax1, ax2), (ax3, ax4)) ...
Write a Python 3 script for imaging for : meth. Surface. subdivide docstring.
You are a Python code generator, capable of creating scripts from specifications.
Image for : meth. Surface. subdivide docstring.
Given the following Python 3 function, write the documentation def surface_subdivide2(surface, sub_surface_b): if NO_IMAGES: return # Plot set-up. figure = plt.figure() ax = figure.gca() colors = seaborn.husl_palette(6) N = 128 s_vals = np.linspace(0.0, 1.0, N + 1) # Add edges f...
You are a Python code generator, capable of creating scripts from specifications.
Image for : class. CurvedPolygon docstring.
Make a summary of the following Python 3 code def curved_polygon_constructor1(curved_poly): if NO_IMAGES: return ax = curved_poly.plot(256) ax.axis("scaled") ax.set_xlim(-0.125, 2.125) ax.set_ylim(-0.625, 1.625) save_image(ax.figure, "curved_polygon_constructor1.png")
As a Python code analyst, you investigate and solve complex coding mysteries
Image for : meth. Curve. specialize docstring.
Make a summary of the following Python 3 code def curve_specialize(curve, new_curve): if NO_IMAGES: return ax = curve.plot(256) interval = r"$\left[0, 1\right]$" line = ax.lines[-1] line.set_label(interval) color1 = line.get_color() new_curve.plot(256, ax=ax) interval = r"$\left...
You are a Python code generator, capable of creating scripts from specifications.
def newton_refine_surface(surface, x_val, y_val, s, t, new_s, new_t): """Image for :func:`._surface_helpers.newton_refine` docstring.""" if NO_IMAGES: return figure, (ax1, ax2) = plt.subplots(1, 2) # Plot features of the parameter space in ax1. tri_surf = bezier.Surface.from_nodes( ...
Can you create a Python 3 function that images for the Newton - Refine surface.
As a Python code analyst, you investigate and solve complex coding mysteries
def classify_intersection1(s, curve1, tangent1, curve2, tangent2): """Image for :func:`._surface_helpers.classify_intersection` docstring.""" if NO_IMAGES: return surface1 = bezier.Surface.from_nodes( np.asfortranarray( [[1.0, 1.75, 2.0, 1.0, 1.5, 1.0], [0.0, 0.25, 1.0, 1.0, 1.5...
Create a Python 3 function for imaging for :func:`._surface_helpers.classify_intersection` docstring.
As a Python code translator, you convert algorithms and pseudocode into Python.
Image for _surface_helpers. classify_intersection docstring.
How would you explain what the following Python 3 function does def classify_intersection2(s, curve1, curve2): if NO_IMAGES: return surface1 = bezier.Surface.from_nodes( np.asfortranarray( [[1.0, 1.5, 2.0, 1.25, 1.75, 1.5], [0.0, 1.0, 0.0, 1.0, 1.0, 2.0]] ) ) surface...
You are a Python code architect, reviewing and designing scalable and efficient code
def classify_intersection5(s, curve1, curve2): """Image for :func:`._surface_helpers.classify_intersection` docstring.""" if NO_IMAGES: return surface1 = bezier.Surface.from_nodes( np.asfortranarray( [ [1.0, 1.5, 2.0, 1.25, 1.75, 1.5], [0.0, 1.0, ...
Write a Python 3 script for imaging for _surface_helpers. classify_intersection docstring.
You are a Python code architect, reviewing and designing scalable and efficient code
Image for _surface_helpers. classify_intersection7 docstring.
Can you generate the documentation for the following Python 3 function def classify_intersection7(s, curve1a, curve1b, curve2): if NO_IMAGES: return surface1 = bezier.Surface.from_nodes( np.asfortranarray( [ [0.0, 4.5, 9.0, 0.0, 4.5, 0.0], [0.0, 0.0, ...
As a Python code analyst, you investigate and solve complex coding mysteries
Image for getting the curvature of a node.
Can you generate the documentation for the following Python 3 function def get_curvature(nodes, s, tangent_vec, curvature): if NO_IMAGES: return curve = bezier.Curve.from_nodes(nodes) # Find the center of the circle along the direction # perpendicular to the tangent vector (90 degree left turn)...
As a python code expert, you are capable of creating scripts from specifications.
def curve_locate(curve, point1, point2, point3): """Image for :meth`.Curve.locate` docstring.""" if NO_IMAGES: return ax = curve.plot(256) points = np.hstack([point1, point2, point3]) ax.plot( points[0, :], points[1, :], color="black", linestyle="None", marker="o" ) ax.axis(...
Implement a Python 3 function for imaging for : meth. Curve. locate docstring.
As a Python code translator, you convert algorithms and pseudocode into Python.
Image for the Newton - Refine curve.
Given the following Python 3 function, write the documentation def newton_refine_curve(curve, point, s, new_s): if NO_IMAGES: return ax = curve.plot(256) ax.plot(point[0, :], point[1, :], marker="H") wrong_points = curve.evaluate_multi(np.asfortranarray([s, new_s])) ax.plot( wrong_p...
As a Python code analyst, you investigate and solve complex coding mysteries
Image for the Newton Reine curve.
Can you tell what is the following Python 3 function doing def newton_refine_curve_cusp(curve, s_vals): if NO_IMAGES: return ax = curve.plot(256) ax.lines[-1].zorder = 1 points = curve.evaluate_multi(np.asfortranarray(s_vals)) colors = seaborn.dark_palette("blue", 6) ax.scatter( ...
As a Python code analyst, you investigate and solve complex coding mysteries
Image for classify_intersection8 docstring.
Can you generate a brief explanation for the following Python 3 code def classify_intersection8(s, curve1, surface1, curve2, surface2): if NO_IMAGES: return ax = classify_help(s, curve1, surface1, curve2, surface2, None) ax.set_xlim(-1.125, 1.125) ax.set_ylim(-0.125, 1.125) save_image(ax.fi...
You are a Python code architect, reviewing and designing scalable and efficient code
The edges for the curved polygon intersection used below.
Can you tell what is the following Python 3 function doing def _edges_classify_intersection9(): edges1 = ( bezier.Curve.from_nodes( np.asfortranarray([[32.0, 30.0], [20.0, 25.0]]) ), bezier.Curve.from_nodes( np.asfortranarray([[30.0, 25.0, 20.0], [25.0, 20.0, 20.0]]) ...
You are a Python code architect, reviewing and designing scalable and efficient code
def classify_intersection9(s, curve1, curve2): """Image for :func:`._surface_helpers.classify_intersection` docstring.""" if NO_IMAGES: return surface1 = bezier.Surface.from_nodes( np.asfortranarray( [ [0.0, 20.0, 40.0, 10.0, 30.0, 20.0], [0.0, 40...
How would you implement a function in Python 3 that images for _surface_helpers. classify_intersection docstring.
You are a Python code analyst, evaluating scripts for potential improvements.
Image for : meth :. curve. Curve. elevate docstring.
Here you have a function in Python 3, explain what it does def curve_elevate(curve, elevated): if NO_IMAGES: return figure, (ax1, ax2) = plt.subplots(1, 2) curve.plot(256, ax=ax1) color = ax1.lines[-1].get_color() add_patch(ax1, curve._nodes, color) elevated.plot(256, ax=ax2) color ...
You are a Python code architect, reviewing and designing scalable and efficient code
Image for : class :. surface. Surface docstring.
Here you have a function in Python 3, explain what it does def unit_triangle(): if NO_IMAGES: return nodes = np.asfortranarray([[0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]) surface = bezier.Surface(nodes, degree=1) ax = surface.plot(256) ax.axis("scaled") _plot_helpers.add_plot_boundary(ax) s...
As a Python code composer, you craft elegant and concise scripts.
Image for : meth :. curve. Curve. reduce docstring.
Explain what the following Python 3 code does def curve_reduce(curve, reduced): if NO_IMAGES: return figure, (ax1, ax2) = plt.subplots(1, 2, sharex=True, sharey=True) curve.plot(256, ax=ax1) color = ax1.lines[-1].get_color() add_patch(ax1, curve._nodes, color) reduced.plot(256, ax=ax2) ...
You are a Python code analyst, evaluating scripts for potential improvements.
def curve_reduce_approx(curve, reduced): """Image for :meth:`.curve.Curve.reduce` docstring.""" if NO_IMAGES: return ax = curve.plot(256) color = ax.lines[-1].get_color() add_patch(ax, curve._nodes, color, alpha=0.25, node_color=color) reduced.plot(256, ax=ax) color = ax.lines[-1].g...
Create a Python 3 function for imaging for : meth :. curve. Curve. reduce docstring.
As a python code expert, you are capable of creating scripts from specifications.
This function updates the list of candidates during geometric search for a point.
How would you explain what the following Python 3 function does def update_locate_candidates(candidate, next_candidates, x_val, y_val, degree): centroid_x, centroid_y, width, candidate_nodes = candidate point = np.asfortranarray([x_val, y_val]) if not _helpers.contains_nd(candidate_nodes, point): re...
You are a Python code architect, reviewing and designing scalable and efficient code
Take the mean of all centroids in set of reference triangles.
Can you generate a brief explanation for the following Python 3 code def mean_centroid(candidates): sum_x = 0.0 sum_y = 0.0 for centroid_x, centroid_y, _, _ in candidates: sum_x += centroid_x sum_y += centroid_y denom = 3.0 * len(candidates) return sum_x / denom, sum_y / denom
You are a Python code analyst, evaluating scripts for potential improvements.
r Finds a point on a base - image of a given degree on a given set of nodes.
Make a summary of the following Python 3 code def _locate_point(nodes, degree, x_val, y_val): # We track the centroid rather than base_x/base_y/width (by storing triple # the centroid -- to avoid division by three until needed). We also need # to track the width (or rather, just the sign of the width). ...
You are a Python code generator, capable of creating scripts from specifications.
Check if two intersections are close to machine precision.
Given the following Python 3 function, write the documentation def same_intersection(intersection1, intersection2, wiggle=0.5 ** 40): if intersection1.index_first != intersection2.index_first: return False if intersection1.index_second != intersection2.index_second: return False return np....
As a python code expert, you are capable of creating scripts from specifications.
def verify_duplicates(duplicates, uniques): """Verify that a set of intersections had expected duplicates. .. note:: This is a helper used only by :func:`generic_intersect`. Args: duplicates (List[.Intersection]): List of intersections corresponding to duplicates that were filt...
Can you implement a function in Python 3 that verifies that a set of intersections had expected duplicates.
You are a Python code architect, reviewing and designing scalable and efficient code
Verify that the edge segments in an intersection are valid.
How would you explain what the following Python 3 function does def verify_edge_segments(edge_infos): if edge_infos is None: return for edge_info in edge_infos: num_segments = len(edge_info) for index in six.moves.xrange(-1, num_segments - 1): index1, start1, end1 = edge_inf...
You are a Python code analyst, evaluating scripts for potential improvements.
def add_edge_end_unused(intersection, duplicates, intersections): """Add intersection that is ``COINCIDENT_UNUSED`` but on an edge end. This is a helper for :func:`~._surface_intersection.add_intersection`. It assumes that * ``intersection`` will have at least one of ``s == 0.0`` or ``t == 0.0`` *...
Write a Python 3 script for adding an intersection that is COINCIDENT_UNUSED but on an edge end.
You are a Python code architect, reviewing and designing scalable and efficient code
Checks if a valid intersection is already in intersections.
Explain what the following Python 3 code does def check_unused(intersection, duplicates, intersections): for other in intersections: if ( other.interior_curve == UNUSED_T and intersection.index_first == other.index_first and intersection.index_second == other.index_second...
As a Python code analyst, you investigate and solve complex coding mysteries
def add_intersection( # pylint: disable=too-many-arguments index1, s, index2, t, interior_curve, edge_nodes1, edge_nodes2, duplicates, intersections, ): """Create an :class:`Intersection` and append. The intersection will be classified as either a duplicate or a valid i...
How would you implement a function in Python 3 that adds an intersection to the current node list.
As a Python code composer, you craft elegant and concise scripts.
r Determine if the intersection parameters of two curves are used.
Here you have a function in Python 3, explain what it does def classify_coincident(st_vals, coincident): if not coincident: return None if st_vals[0, 0] >= st_vals[0, 1] or st_vals[1, 0] >= st_vals[1, 1]: return UNUSED_T else: return CLASSIFICATION_T.COINCIDENT
As a Python code composer, you craft elegant and concise scripts.
def should_use(intersection): """Check if an intersection can be used as part of a curved polygon. Will return :data:`True` if the intersection is classified as :attr:`~.IntersectionClassification.FIRST`, :attr:`~.IntersectionClassification.SECOND` or :attr:`~.IntersectionClassification.COINCIDENT`...
How would you implement a function in Python 3 that checks if an intersection can be used as part of a curved polygon.
You are a Python code architect, reviewing and designing scalable and efficient code
Find all intersections among edges of two surfaces.
Can you generate a brief explanation for the following Python 3 code def surface_intersections(edge_nodes1, edge_nodes2, all_intersections): # NOTE: There is no corresponding "enable", but the disable only applies # in this lexical scope. # pylint: disable=too-many-locals intersections = [] du...
As a Python code translator, you convert algorithms and pseudocode into Python.
r Returns a list of lists of edges that intersect the two surfaces.
Explain what the following Python 3 code does def generic_intersect( nodes1, degree1, nodes2, degree2, verify, all_intersections ): r"""Find all intersections among edges of two surfaces. This treats intersections which have ``s == 1.0`` or ``t == 1.0`` as duplicates. The duplicates will be checked by ...
As a python code expert, you are capable of creating scripts from specifications.
r Returns a tuple of lists containing intersections between two surfaces.
How would you explain what the following Python 3 function does def _geometric_intersect(nodes1, degree1, nodes2, degree2, verify): all_intersections = _geometric_intersection.all_intersections return generic_intersect( nodes1, degree1, nodes2, degree2, verify, all_intersections )
As a Python code translator, you convert algorithms and pseudocode into Python.
r Returns a tuple of lists containing all intersections among the two surfaces.
Explain what the following Python 3 code does def algebraic_intersect(nodes1, degree1, nodes2, degree2, verify): all_intersections = _algebraic_intersection.all_intersections return generic_intersect( nodes1, degree1, nodes2, degree2, verify, all_intersections )
As a Python code composer, you craft elegant and concise scripts.
def modify_path(): """Modify the module search path.""" # Only modify path on Windows. if os.name != "nt": return path = os.environ.get("PATH") if path is None: return try: extra_dll_dir = pkg_resources.resource_filename("bezier", "extra-dll") if os.path.isdir(e...
Implement a function in Python 3 to modify the module search path.
You are a Python code analyst, evaluating scripts for potential improvements.
Allow or re - raise an import error.
Can you generate a brief explanation for the following Python 3 code def handle_import_error(caught_exc, name): for template in TEMPLATES: expected_msg = template.format(name) if caught_exc.args == (expected_msg,): return raise caught_exc
You are a Python code architect, reviewing and designing scalable and efficient code
def is_macos_gfortran(f90_compiler): """Checks if the current build is ``gfortran`` on macOS. Args: f90_compiler (numpy.distutils.fcompiler.FCompiler): A Fortran compiler instance. Returns: bool: Only :data:`True` if * Current OS is macOS (checked via ``sys.platform``)...
Create a Python 3 function for checking if the current build is gfortran on macOS.
As a Python code translator, you convert algorithms and pseudocode into Python.
def patch_f90_compiler(f90_compiler): """Patch up ``f90_compiler.library_dirs``. On macOS, a Homebrew installed ``gfortran`` needs some help. The ``numpy.distutils`` "default" constructor for ``Gnu95FCompiler`` only has a single library search path, but there are many library paths included in the ...
Implement a function in Python 3 to patch up the Fortran Gnu95FCompiler s library_dirs.
You are a Python code analyst, evaluating scripts for potential improvements.
def _make_intersection(edge_info, all_edge_nodes): """Convert a description of edges into a curved polygon. .. note:: This is a helper used only by :meth:`.Surface.intersect`. Args: edge_info (Tuple[Tuple[int, float, float], ...]): Information describing each edge in the curved...
Create a Python 3 function for converting a description of edges into a curved polygon.
You are a Python code architect, reviewing and designing scalable and efficient code
Create a : class :. Surface from a numpy array of nodes.
Given the following Python 3 function, write the documentation def from_nodes(cls, nodes, _copy=True): _, num_nodes = nodes.shape degree = cls._get_degree(num_nodes) return cls(nodes, degree, _copy=_copy)
As a Python code translator, you convert algorithms and pseudocode into Python.
Get the degree of the current surface.
Given the following Python 3 function, write the documentation def _get_degree(num_nodes): # 8 * num_nodes = 4(d + 1)(d + 2) # = 4d^2 + 12d + 8 # = (2d + 3)^2 - 1 d_float = 0.5 * (np.sqrt(8.0 * num_nodes + 1.0) - 3.0) d_int = int(np.round(d_float)) ...
As a Python code analyst, you investigate and solve complex coding mysteries
Calculates the area of the current surface.
Here you have a function in Python 3, explain what it does def area(self): if self._dimension != 2: raise NotImplementedError( "2D is the only supported dimension", "Current dimension", self._dimension, ) edge1, edge2, edge3 = self...
As a Python code translator, you convert algorithms and pseudocode into Python.
Compute the edges of the current node and edge of the current node.
Can you tell what is the following Python 3 function doing def _compute_edges(self): nodes1, nodes2, nodes3 = _surface_helpers.compute_edge_nodes( self._nodes, self._degree ) edge1 = _curve_mod.Curve(nodes1, self._degree, _copy=False) edge2 = _curve_mod.Curve(nodes2, self._de...
As a Python code analyst, you investigate and solve complex coding mysteries
def _get_edges(self): """Get the edges for the current surface. If they haven't been computed yet, first compute and store them. This is provided as a means for internal calls to get the edges without copying (since :attr:`.edges` copies before giving to a user to keep the stor...
Implement a function in Python 3 to get the edges for the current surface.
As a python code expert, you are capable of creating scripts from specifications.
Verifies that the weights are barycentric and on the reference triangle.
Make a summary of the following Python 3 code def _verify_barycentric(lambda1, lambda2, lambda3): weights_total = lambda1 + lambda2 + lambda3 if not np.allclose(weights_total, 1.0, atol=0.0): raise ValueError( "Weights do not sum to 1", lambda1, lambda2, lambda3 )...
You are a Python code architect, reviewing and designing scalable and efficient code
r This method evaluates multiple points on the surface.
Explain what the following Python 3 code does def evaluate_barycentric_multi(self, param_vals, _verify=True): if _verify: if param_vals.ndim != 2: raise ValueError("Parameter values must be 2D array") for lambda1, lambda2, lambda3 in param_vals: self._ver...
As a Python code translator, you convert algorithms and pseudocode into Python.
Verifies that a point is in the reference triangle.
Given the following Python 3 function, write the documentation def _verify_cartesian(s, t): if s < 0.0 or t < 0.0 or s + t > 1.0: raise ValueError("Point lies outside reference triangle", s, t)
As a python code expert, you are capable of creating scripts from specifications.
r Returns a point on the surface.
Can you generate a brief explanation for the following Python 3 code def evaluate_cartesian(self, s, t, _verify=True): if _verify: self._verify_cartesian(s, t) return _surface_helpers.evaluate_barycentric( self._nodes, self._degree, 1.0 - s - t, s, t )
As a Python code composer, you craft elegant and concise scripts.
Plots the current control points of the current object.
Can you tell what is the following Python 3 function doing def plot(self, pts_per_edge, color=None, ax=None, with_nodes=False): if self._dimension != 2: raise NotImplementedError( "2D is the only supported dimension", "Current dimension", self._dimensi...
As a Python code composer, you craft elegant and concise scripts.
Split the surface into four sub - surfaces.
Can you tell what is the following Python 3 function doing def subdivide(self): nodes_a, nodes_b, nodes_c, nodes_d = _surface_helpers.subdivide_nodes( self._nodes, self._degree ) return ( Surface(nodes_a, self._degree, _copy=False), Surface(nodes_b, self._degr...
You are a Python code generator, capable of creating scripts from specifications.
r Returns the s t and t values corresponding to the point on the current surface.
Explain what the following Python 3 code does def locate(self, point, _verify=True): if _verify: if self._dimension != 2: raise NotImplementedError("Only 2D surfaces supported.") if point.shape != (self._dimension, 1): point_dimensions = " x ".join( ...
You are a Python code analyst, evaluating scripts for potential improvements.
Find the common intersection with another surface.
How would you explain what the following Python 3 function does def intersect(self, other, strategy=_STRATEGY.GEOMETRIC, _verify=True): if _verify: if not isinstance(other, Surface): raise TypeError( "Can only intersect with another surface", "...
You are a Python code analyst, evaluating scripts for potential improvements.
r Return a degree - elevated version of the current surface.
Can you generate a brief explanation for the following Python 3 code def elevate(self): _, num_nodes = self._nodes.shape # (d + 1)(d + 2)/2 --> (d + 2)(d + 3)/2 num_new = num_nodes + self._degree + 2 new_nodes = np.zeros((self._dimension, num_new), order="F") # NOTE: We start fro...
As a Python code composer, you craft elegant and concise scripts.
r Apply one step of 2D Newton s method.
Can you generate a brief explanation for the following Python 3 code def _newton_refine(s, nodes1, t, nodes2): # NOTE: We form -F(s, t) since we want to solve -DF^{-1} F(s, t). func_val = _curve_helpers.evaluate_multi( nodes2, np.asfortranarray([t]) ) - _curve_helpers.evaluate_multi(nodes1, np.asfor...
You are a Python code analyst, evaluating scripts for potential improvements.
def gfortran_search_path(library_dirs): """Get the library directory paths for ``gfortran``. Looks for ``libraries: =`` in the output of ``gfortran -print-search-dirs`` and then parses the paths. If this fails for any reason, this method will print an error and return ``library_dirs``. Args: ...
Implement a Python 3 function for getting the library directory paths for ``gfortran``. Looks for ``libraries: =`` in the output of ``gfortran -print-search-dirs`` and then parses the paths. If this fails for any reason, this method will print an error and return ``library_dirs``. Args: library_dirs (List[str]): Existi...
You are a Python code generator, capable of creating scripts from specifications.
def _update_flags(compiler_flags, remove_flags=()): """Update a given set of compiler flags. Args: compiler_flags (List[str]): Existing flags associated with a compiler. remove_flags (Optional[Container[str]]): A container of flags to remove that will override any of the defaults. ...
Write a Python 3 function that can update a given set of compiler flags.
You are a Python code analyst, evaluating scripts for potential improvements.
def patch_f90_compiler(f90_compiler): """Patch up ``f90_compiler``. For now, only updates the flags for ``gfortran``. In this case, it add any of ``GFORTRAN_SHARED_FLAGS`` that are missing. In debug mode, it also adds any flags in ``GFORTRAN_DEBUG_FLAGS`` and makes sure none of the flags in ``GFORT...
Can you write a function in Python 3 where it patches up f90_compiler. gfortran. f90. gfortran. f90. f90.
As a python code expert, you are capable of creating scripts from specifications.
def start_journaling(self): """Capture calls to the system by compilers. See: https://github.com/numpy/numpy/blob/v1.15.2/\ numpy/distutils/ccompiler.py#L154 Intercepts all calls to ``CCompiler.spawn`` and keeps the arguments around to be stored in the local ``commands`` ...
Can you create a Python 3 function that starts the journaling of the current entry point.
You are a Python code analyst, evaluating scripts for potential improvements.
Save the commands to a file.
How would you explain what the following Python 3 function does def save_journal(self): if self.journal_file is None: return try: as_text = self._commands_to_text() with open(self.journal_file, "w") as file_obj: file_obj.write(as_text) except ...
As a Python code composer, you craft elegant and concise scripts.
def _default_static_lib(self, obj_files): """Create a static library (i.e. a ``.a`` / ``.lib`` file). Args: obj_files (List[str]): List of paths of compiled object files. """ c_compiler = self.F90_COMPILER.c_compiler static_lib_dir = os.path.join(self.build_lib, "bez...
How would you implement a function in Python 3 that creates a static library for the current locale.
You are a Python code generator, capable of creating scripts from specifications.
Default cleanup after run.
Given the following Python 3 function, write the documentation def _default_cleanup(self): if not self.inplace: return shutil.move( os.path.join(self.build_lib, "bezier", "lib"), os.path.join("src", "bezier"), )
As a Python code analyst, you investigate and solve complex coding mysteries
def _verify_pair(prev, curr): """Verify a pair of sides share an endpoint. .. note:: This currently checks that edge endpoints match **exactly** but allowing some roundoff may be desired. Args: prev (.Curve): "Previous" curve at piecewise junction. ...
Write a Python 3 script to verify that two consecutive edge endpoints share an endpoint.
As a python code expert, you are capable of creating scripts from specifications.
def _verify(self): """Verify that the edges define a curved polygon. This may not be entirely comprehensive, e.g. won't check self-intersection of the defined polygon. .. note:: This currently checks that edge endpoints match **exactly** but allowing some roundof...
How would you implement a function in Python 3 that verifies that the edges define a curved polygon.
As a python code expert, you are capable of creating scripts from specifications.
r A method to compute the area of the current curved polygon.
Can you generate a brief explanation for the following Python 3 code def area(self): edges = tuple(edge._nodes for edge in self._edges) return _surface_helpers.compute_area(edges)
You are a Python code generator, capable of creating scripts from specifications.
Plot the current curved polygon.
Given the following Python 3 function, write the documentation def plot(self, pts_per_edge, color=None, ax=None): if ax is None: ax = _plot_helpers.new_axis() _plot_helpers.add_patch(ax, color, pts_per_edge, *self._edges) return ax
As a python code expert, you are capable of creating scripts from specifications.
Compute the implicit form of the line connecting curve endpoints.
Make a summary of the following Python 3 code def compute_implicit_line(nodes): delta = nodes[:, -1] - nodes[:, 0] length = np.linalg.norm(delta, ord=2) # Normalize and rotate 90 degrees to the "left". coeff_a = -delta[1] / length coeff_b = delta[0] / length # c = - ax - by = (delta[1] x - delta...
As a Python code composer, you craft elegant and concise scripts.