Add reshape support for DiffCache resizing#180
Draft
ChrisRackauckas-Claude wants to merge 2 commits into
Draft
Conversation
e5bcc1f to
f412824
Compare
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
f412824 to
ead730d
Compare
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Contributor
Author
|
Follow-up for the PreallocationTools test coverage request. Added core resizing tests for:
The Local validation run on commit
|
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.
Draft PR. Please ignore until reviewed by @ChrisRackauckas.
Summary
reshape(::DiffCache, dims...)so vector-backedDiffCachestorage can be presented as a multidimensional cache without callers reaching into.du/.dual_du.resize!d and reshaped again.DiffCaches.ArrayInterface.restructure.1.3.0for the new public API.Root Cause
The issue workflow needed multidimensional
DiffCacheaccess while keeping resizeable vector storage. A plainreshape(vector, dims...)marks the vector as shared and prevents laterresize!, while the existing public API did not expose the field/unsafe_wrappattern safely.The initial implementation used a view-backed reshape for safety, but the ForwardDiff path for that wrapper fell back to
ArrayInterface.restructure, which copied into a fresh matrix. The current implementation adds a vector-backed reshaped-cache fast path soget_tmpremains zero-copy and writes alias the raw dual storage, without relying on non-publicBase.ReshapedArrayin source.Fixes #140.
Performance Notes
Benchmarked locally with BenchmarkTools after rebasing onto current
master, on a 1000-element vector-backed cache reshaped to(20, 50):get_tmpfor reshaped dual cache:23.63 ns,0 bytesget_tmp:23.63 ns,0 bytesreshape(DiffCache vector):5.63 ns,0 bytesunsafe_wrap(Array, pointer, dims):45.35 ns,48 bytesunsafe_wrapand ordinary matrix timings and allocated0 bytesStridedArrays and the dual temporary aliasesdual_duNon-standard probes:
SubArrayandLVectorvector-backed reshapes return strided, zero-copy reshaped dual temporaries.LArraymatrix reshapes stay on the existingArrayInterface.restructurefallback, preserving wrapper behavior instead of applying the vector-backed fast path.VectorOfArrayreshaped normal access remains zero-allocation.Validation
timeout 3600 /home/crackauc/.juliaup/bin/julia +1.10 --project=. test/core_resizing.jltimeout 3600 /home/crackauc/.juliaup/bin/julia +1.10 --project=. -e 'using Runic; Runic.main(ARGS)' -- --check --diff .timeout 3600 /home/crackauc/.juliaup/bin/julia +1.10 --project=. -e 'using Pkg; Pkg.test()'GROUP=QA timeout 3600 /home/crackauc/.juliaup/bin/julia +1 --project=. -e 'using Pkg; Pkg.test()'429during Documenterlinkcheck; retrying the same command unchanged passed:timeout 3600 /home/crackauc/.juliaup/bin/julia +1.10 --project=docs -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate(); include("docs/make.jl")'perf_env, removed after use.