Skip to content

perf!: float64 Abs, Neg, Square, Floor, Ceil, Round on go-simd/floats v0.23.0; Round is half to even, add RoundHalfAway - #123

Merged
tannevaled merged 4 commits into
mainfrom
perf/floats023-unary
Nov 15, 2026
Merged

tannevaled merged 4 commits into
mainfrom
perf/floats023-unary

Conversation

@tannevaled

@tannevaled tannevaled commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Float64 Abs, Neg, Square, Floor, Ceil and Round now run on the go-simd/floats v0.23.0 kernels (go.mod bumped from v0.17.0), split across cores above the parallel threshold as before. Workspace allocation, strided inputs (materialised first) and the integer dtypes are unchanged.

Behaviour change (MINOR): Round is half to even, as np.round. On exact halves Round of 0.5, 1.5, 2.5 and -0.5 gives 0, 2, 2 and -0 instead of 1, 2, 3 and -1. It holds on every dtype: float64 (the RoundEven kernel), float32 and each part of a complex number (math.RoundToEven); integers and bools are returned unchanged. The old behaviour is the new RoundHalfAway (math.Round, scalar path, same dtypes), whose doc comment says how it differs from Round and np.round. There is no decimals variant. README (API section and the note on the change) and docs are updated; the repository has no changelog file, so this body is the release note for the next MINOR.

Bit identity. TestUnaryKernelsBitIdentical compares each op with math.Abs, -x, x*x, math.Floor, math.Ceil, math.RoundToEven and math.Round on lengths 0 to 33 and one above ParThreshold, over an edge table (±0, ±Inf, NaNs including a signalling one, subnormals, halves, ±2^52 and ±2^63 neighbours) and random bit patterns. Abs and Neg are compared with exact NaN bits; for Square, Floor, Ceil and Round a signalling NaN may come back quieted. Strided views are covered too. The 100% coverage gate holds locally.

Measured (go test -bench Unary, new benchmarks/unary_bench_test.go), 10^5 float64 including the result allocation, cfarm420 (AMD EPYC 7773X), GOMAXPROCS=1, taskset -c 9, a v0.42.0 test binary against one of this branch, four interleaved rounds of 1 s each (two runs; 1-minute load 2.3 to 3.3):

operation before (µs) after (µs)
Abs 244–258 70–75
Neg 243–249 72–75
Square 243–247 72–80
Floor 432–457 73–81
Ceil 437–464 72–81
Round (old: half away) 325–340 71–80
RoundHalfAway (control) 324–345

No NumPy ratio is claimed: these are Go against Go, and the new table run has not been made.

Also in this PR: docs/linalg.md and docs/design-linalg.md name go-blas/blas for the GEMM, and SECURITY.md gives its two "unreleased" audit entries their releases (v0.42.0, #122; v0.40.2, #115).

Refs #118

🤖 Generated with Claude Code

tannevaled and others added 3 commits November 15, 2026 18:17
… kernels

Bump go-simd/floats to v0.23.0 and route the contiguous float64 case of
Abs, Neg, Square, Floor and Ceil through its SIMD kernels, still split
across cores above kernels.ParThreshold. Results are bit for bit those of
math.Abs, -x, x*x, math.Floor and math.Ceil (a signalling NaN may come
back quieted). Round is unchanged: it rounds half away from zero, which
floats.RoundEven does not.

On 10^5 float64, one core of cfarm420: Abs 244-258 -> 70-75 us, Neg
243-249 -> 72-75, Square 243-247 -> 72-80, Floor 432-457 -> 73-81, Ceil
437-464 -> 72-81 (result allocation included).

Refs #118

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…udit entries

docs/linalg.md and docs/design-linalg.md named the ndarray package's own
GEMM; since #122 it is go-blas/blas. SECURITY.md: the go-blas entry is
v0.42.0 (#122, commit 208bdac, tag v0.42.0 contains it); the Choice gather
entry is v0.40.2 (#115, 8ac94fb, first tag containing it, Refs #103).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…RoundHalfAway

Round now rounds exact halves to the even neighbour on every dtype
(float64 on the go-simd/floats RoundEven kernel; float32 and each part of
a complex number through math.RoundToEven), as np.round with no decimals.
The old half-away-from-zero behaviour (math.Round) is RoundHalfAway, on
the scalar path, on the same dtypes. Integers and bools are unchanged by
both. There is no decimals variant.

Tests: halves and the edge table for both against math.RoundToEven and
math.Round; Abs and Neg now compared with strict NaN bits, the others
with is-NaN only. On 10^5 float64, cfarm420 one core: Round 325-340 ->
71-80 us; RoundHalfAway (control) 324-345 us.

Refs #118

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@tannevaled tannevaled changed the title perf: float64 Abs, Neg, Square, Floor, Ceil on go-simd/floats v0.23.0 perf!: float64 Abs, Neg, Square, Floor, Ceil, Round on go-simd/floats v0.23.0; Round is half to even, add RoundHalfAway Nov 15, 2026
…rpart)

TestPerf requires every public function to have a row or an exemption.
RoundHalfAway rounds halves away from zero; np.round is half to even,
which is Array.Round, so there is nothing to time it against.

Refs #118

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 3a83c6f into main Nov 15, 2026
13 checks passed
@tannevaled
tannevaled deleted the perf/floats023-unary branch November 15, 2026 18:17
tannevaled added a commit that referenced this pull request Nov 15, 2026
docs/plan-ndarray.md still said Round is math.Round (half away from
zero) and that Floor/Ceil/Round/Square go through the Map seam. Since
v0.43.0 (#123) Round rounds halves to even, as
np.round, RoundHalfAway keeps the older rule, and the float64 forms of
Abs/Neg/Square/Floor/Ceil/Round run on go-simd/floats kernels. The docs
site mirrors this file, so the stale sentence was being republished.

Refs #123

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
tannevaled added a commit to go-ndarray/docs that referenced this pull request Nov 15, 2026
Labels, hugo.yaml version and README move to v0.43.1 (baseURL stays /docs/0.43/).
roadmap.md is re-synced from docs/plan-ndarray.md at v0.43.1, which fixes the
stale Round sentence (ndarray#124); the other mirrored sources are unchanged
since v0.43.0. security.md keeps its v0.40.2 audit label verbatim
("v0.40.2, #115, Refs #103").

Refs go-ndarray/ndarray#123

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
tannevaled added a commit to go-ndarray/go-ndarray.github.io that referenced this pull request Nov 15, 2026
The card says "library · v0.43.1" and the playground builds against ndarray
v0.43.1 (docs-only release); its tests pass.

Refs go-ndarray/ndarray#123

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
tannevaled added a commit to go-ndarray/docs that referenced this pull request Nov 15, 2026
* docs: ndarray v0.43.0

Every mirrored page, hugo.yaml (version and baseURL /docs/0.43/) and the
README now point at v0.43.0. Re-synced from the v0.43.0 sources, which changed
since v0.42.0: performance.md (docs/perf.md, "Since the table": float64
Abs/Neg/Square/Floor/Ceil/Round on go-simd/floats v0.23.0), linalg.md
(docs/linalg.md, GEMM from go-blas/blas), dtypes.md (docs/design-dtypes.md,
the round row is gone) and security.md (SECURITY.md, version labels fixed;
by hand, as its README says). roadmap.md, random.md and accuracy.md are
unchanged in their sources and only relabelled. The home page's ufunc row says
Round is half to even and RoundHalfAway keeps the old rule.
performance-history.md is history and is left alone.

Refs go-ndarray/ndarray#123

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

* docs: ndarray v0.43.1

Labels, hugo.yaml version and README move to v0.43.1 (baseURL stays /docs/0.43/).
roadmap.md is re-synced from docs/plan-ndarray.md at v0.43.1, which fixes the
stale Round sentence (ndarray#124); the other mirrored sources are unchanged
since v0.43.0. security.md keeps its v0.40.2 audit label verbatim
("v0.40.2, #115, Refs #103").

Refs go-ndarray/ndarray#123

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

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
tannevaled added a commit to go-ndarray/go-ndarray.github.io that referenced this pull request Nov 15, 2026
* landing: ndarray v0.43.0

The card says "library · v0.43.0". The "Broadcasting and ufuncs" family says
Round is half to even as np.round (RoundHalfAway keeps the old rule) and that
float64 Abs, Neg, Square, Floor, Ceil and Round run on go-simd/floats vector
kernels. The playground builds against ndarray v0.43.0 (go-simd/floats goes to
v0.23.0 with it); its tests pass.

Refs go-ndarray/ndarray#123

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

* landing: ndarray v0.43.1

The card says "library · v0.43.1" and the playground builds against ndarray
v0.43.1 (docs-only release); its tests pass.

Refs go-ndarray/ndarray#123

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

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
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