Skip to content

perf: a vertex makes its coordinate with np.array, not np.r_ - #66

Merged
petercorke merged 1 commit into
mainfrom
perf/vertex-coord-array
Oct 13, 2026
Merged

petercorke merged 1 commit into
mainfrom
perf/vertex-coord-array

Conversation

@petercorke

Copy link
Copy Markdown
Owner

np.r_[coord] costs 1.4 µs, 88% of the cost of creating a vertex (profiled: it is a class that parses its index). np.array(coord, ndmin=1) costs 0.16 µs and gives the same array.

before after 0.6.5
Vertex(coord) 1.59 µs 0.35 µs 1.47 µs
g.add_vertex(coord) 3.12 µs 1.72 µs 2.18 µs

Same harness, 100,000 vertices, best of 5.

Equivalence is tested, not assumed: for a list of ints, a list of floats, a tuple, an int and a float scalar, a numpy array of floats and of int32, a range and a 2-D list, the coordinate has the same shape, dtype and values as np.r_[coord]; a scalar is a vector of one; and an array given is copied, not shared.

758 tests pass, mypy clean.

🤖 Generated with Claude Code

np.r_[coord] is a class that parses its index and cost 1.4 us, 88% of
creating a vertex.  np.array(coord, ndmin=1) costs 0.16 us and gives the same
array for every coordinate checked (a list, a tuple, a scalar, a numpy array of
either type, a range, a 2-D list): same shape, type and values, and a copy.

Vertex(coord) 1.59 -> 0.35 us; add_vertex(coord) 3.12 -> 1.72 us, where 0.6.5
took 2.18 us.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 4 complexity · 0 duplication

Metric Results
Complexity 4
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@petercorke
petercorke merged commit 79a6dd7 into main Oct 13, 2026
12 checks passed
@petercorke
petercorke deleted the perf/vertex-coord-array branch October 13, 2026 00:54
@codecov

codecov Bot commented Oct 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.26%. Comparing base (d41fd62) to head (0a9b654).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #66   +/-   ##
=======================================
  Coverage   97.26%   97.26%           
=======================================
  Files           3        3           
  Lines        1570     1570           
=======================================
  Hits         1527     1527           
  Misses         43       43           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant