Repository navigation
feat: Ravel and Real return views, as NumPy does (#118) - #125
Merged
Merged
Conversation
Ravel of a contiguous array now shares its storage (numpy.ravel), and Real of a non-complex array is the array itself (numpy.real). Both used to copy, which made their #118 rows 566x slower than NumPy. A Set through the result now changes the original; Ravel of a non-contiguous array still copies, Real of a complex array is still a new float array, and Flatten keeps copying (numpy.flatten) - it no longer delegates to Ravel for other dtypes, which the existing TestTypedStructural caught. Internal callers checked: the reductions, Outer and linalg's power only read the view; fft's Real().AsType() clones (AsType copies even when the dtype is unchanged). cfarm420, one core, 3 interleaved rounds, load 2.1-2.3, 10^5 float64: Ravel 83-90 us -> 93-101 ns (803 kB -> 128 B per call) Real 84-91 us -> 101-104 ns Decided by the user, 2026-11-15: views as NumPy, with Flatten/Copy documented as the way to get an independent array. Refs #118 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review of #125: isContiguous refuses any offset, so Ravel of a contiguous slice of a larger array (p.Slice(Rng(1,4,1))) still copied, where numpy.ravel returns a view of a C-contiguous slice. The new isRowMajor asks only that the elements be one row-major run from a.offset; Ravel views that run, and isContiguous is isRowMajor plus offset 0 and full storage. A strided slice still copies. Tests cover both. Refs #118 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ravel and Real return views (4 -> 3 allocations), and the fft real-input transforms, which call x.Real(), save one allocation each. The table is measured again on cfarm420 (one pinned core, NumPy 2.5.4, load 3.01 to 3.86, 256 valid rows): 186 slower, 51 faster, 19 tie (v0.41.0: 188, 54, 14). docs/perf.md: the Status section describes this run, and the section on changes since v0.41.0 now states the ratios against that table, with the run-to-run spread of rows whose code did not change. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The cause list in docs/perf.md still quoted the v0.41.0 ratios (Add 3.1, AddInto 1.03, Ceil 20, Abs 12, SqrtInto 0.51, ...). Re-read each from the table measured at c198892, and name the unary rows that now run on kernels. README: the allocating forms are 3.4-3.8x slower, the *Into forms within 7%. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
isRowMajor had taken isContiguous's doc comment, leaving isContiguous with none. docs/perf.md called Power binary, but it takes a scalar exponent. 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.44.0". The stats and the measured paragraph quote the new table (51 faster, 19 tied, 186 slower of 256; Sum 0.76, fft.FFT 0.64, Ravel 0.35, Real 0.57, SqrtInto 0.52; Exp is now a tie at 0.92), read from docs/perf-table.md at v0.44.0. The views family says Ravel is a view when the elements are one row-major run. The playground builds against ndarray v0.44.0; its tests pass. Refs go-ndarray/ndarray#125 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This was referenced Nov 15, 2026
tannevaled
added a commit
to go-ndarray/docs
that referenced
this pull request
Nov 15, 2026
Every mirrored page, hugo.yaml (version and baseURL /docs/0.44/) and the README now point at v0.44.0. Re-synced from the v0.44.0 sources, which changed since v0.43.1: performance.md (docs/perf.md: the table measured at c198892, "Since the v0.41.0 table"). The other mirrored sources (roadmap, dtypes, linalg, random, security, and the accuracy section of the README) are unchanged and only relabelled. The home page quotes the new counts (186 slower, 51 faster, 19 tied) and says Ravel is a view when the elements are one row-major run. performance-history.md is left alone. Refs go-ndarray/ndarray#125 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.44.0". The stats and the measured paragraph quote the new table (51 faster, 19 tied, 186 slower of 256; Sum 0.76, fft.FFT 0.64, Ravel 0.35, Real 0.57, SqrtInto 0.52; Exp is now a tie at 0.92), read from docs/perf-table.md at v0.44.0. The views family says Ravel is a view when the elements are one row-major run. The playground builds against ndarray v0.44.0; its tests pass. Refs go-ndarray/ndarray#125 Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
RavelandRealreturn views, as NumPy does. Both used to copy, which made their #118 rows 566× slower than NumPy.Behaviour change, decided by the maintainer on 2026-11-15: views as in NumPy, with
Flatten/Copydocumented as the way to get an independent array.Ravelof a contiguous array shares its storage (numpy.ravel). A non-contiguous array is still copied.Realof a non-complex array is the array itself (numpy.real): same layout, and the weak-scalar flag is kept.Realof a complex array is still a new float array.Setthrough the result now changes the original. The README states this for the next MINOR release.Flattenkeeps copying (numpy.flatten). It used to delegate toRavelfor dtypes other than float64; the existingTestTypedStructuralcaught that, and it now copies explicitly.Internal callers, checked:
argTyped,scanTyped,reduceTyped),Outerand linalg'sMultiDotonly read the view;x.Real().AsType(...)stays a private copy, becauseAsTypeclones even when the dtype is unchanged.Measured on cfarm420 (EPYC 7773X): one pinned core,
GOMAXPROCS=1, three interleaved rounds, load 2.1–2.3, 10⁵ float64.Ravel(contiguous)Real(float64)The table's NumPy times were 176 ns and 164 ns. That is not a new measurement against NumPy, and docs/perf.md says so.
Tests
TestRavelIsAViewWhenContiguouscovers float64 and int8 aliasing, the transposed copy, and Flatten's independence.TestRealIsAViewOfARealArraycovers a transposed view, complex independence and the weak flag.Refs #118
🤖 Generated with Claude Code