Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NDTensors] Add SmallVectors submodule #1202

Merged
merged 13 commits into from
Sep 29, 2023
Merged

[NDTensors] Add SmallVectors submodule #1202

merged 13 commits into from
Sep 29, 2023

Conversation

mtfishman
Copy link
Member

Description

This adds a submodule to NDTensors called SmallVectors which defines the types SmallVector and MSmallVector which are stack allocated with a maximum compile-time length but have a runtime length that can be less than the maximum compile-time length. The goal is for this type to be used by the QN type and the TagSet type, which both have a similar storage requirement. This should also make it easier to allow users to customize the types if they want to.

Here's an example of some functionality:

julia> using NDTensors.SmallVectors

julia> v = SmallVector{10}([1, 3, 5])
3-element SmallVector{10, Int64}:
 1
 3
 5

julia> v = SmallVectors.push(v, 7)
4-element SmallVector{10, Int64}:
 1
 3
 5
 7

julia> v = SmallVectors.insertsorted(v, 2)
5-element SmallVector{10, Int64}:
 1
 2
 3
 5
 7

The test suite has various tests of common operations to test that they have zero allocations.

@emstoudenmire

NDTensors/src/SmallVectors/src/SmallVectors.jl Outdated Show resolved Hide resolved
NDTensors/src/SmallVectors/src/SmallVectors.jl Outdated Show resolved Hide resolved
NDTensors/src/SmallVectors/src/SmallVectors.jl Outdated Show resolved Hide resolved
NDTensors/src/SmallVectors/src/SmallVectors.jl Outdated Show resolved Hide resolved
NDTensors/src/SmallVectors/test/runtests.jl Outdated Show resolved Hide resolved
NDTensors/src/SmallVectors/test/runtests.jl Outdated Show resolved Hide resolved
NDTensors/src/SmallVectors/test/runtests.jl Outdated Show resolved Hide resolved
NDTensors/src/SmallVectors/test/runtests.jl Show resolved Hide resolved
NDTensors/src/SmallVectors/test/runtests.jl Outdated Show resolved Hide resolved
@mtfishman
Copy link
Member Author

@emstoudenmire one goal was to define an abstract interface AbstactSmallVector, so that the QN type can both wrap a SmallVector as it's storage, and also be a subtype of AbstactSmallVector so efficient stack-allocateed operations automatically work (using a few function overloads). You can see the interface requirements for subtypes based on the code for SmallVector, MSmallVector, SubSmallVector, and SubMSmallVector (the last two are used to define efficient contiguous slices of SmallVectors), the interface is pretty minimal and mostly involves defining getting and setting elements, some constructors, access to the underlying buffer, etc.

@mtfishman
Copy link
Member Author

Unfortunately the design of the mutable types right now relies on a feature that was made available in Julia 1.8 for marking certain fields as const (https://github.com/JuliaLang/julia/blob/master/HISTORY.md#new-language-features-2), to have control over which fields or mutable or not. For now I'll just test against Julia 1.8 and later and work out how to make it backwards compatible to Julia 1.6 but still efficient.

@codecov-commenter
Copy link

codecov-commenter commented Sep 21, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (f6c575b) 85.41% compared to head (5084494) 67.37%.
Report is 6 commits behind head on main.

❗ Current head 5084494 differs from pull request most recent head 067b5aa. Consider uploading reports for the commit 067b5aa to get more accurate results

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1202       +/-   ##
===========================================
- Coverage   85.41%   67.37%   -18.05%     
===========================================
  Files          88       87        -1     
  Lines        8426     8388       -38     
===========================================
- Hits         7197     5651     -1546     
- Misses       1229     2737     +1508     
Files Coverage Δ
src/itensor.jl 80.96% <100.00%> (-1.30%) ⬇️

... and 35 files with indirect coverage changes

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

@emstoudenmire
Copy link
Collaborator

Looks good & the interface is clear. More convenient that a plain SArray (or MArray) for sure. When it's merged I will go ahead and use it for the new QN type.

@mtfishman mtfishman merged commit ea0f602 into main Sep 29, 2023
7 checks passed
@mtfishman mtfishman deleted the NDTensors_smallvectors branch September 29, 2023 00:34
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.

3 participants