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

Introduce OneElementArray #26

Merged
merged 4 commits into from
Feb 3, 2025
Merged

Introduce OneElementArray #26

merged 4 commits into from
Feb 3, 2025

Conversation

mtfishman
Copy link
Member

@mtfishman mtfishman commented Feb 3, 2025

This is a sparse type that only stores a single structurally nonzero element. This is very similar to FillArrays.OneElement, but I'm reimplementing a version here for better compatibility with the sparse types we are developing, and to have more control over the operations we define. See also OneHotArrays.OneHotArray for a similar type.

A lot of algebra operations "just work" for this type, but don't yet necessarily preserve the OneElementArray type (when that is possible) and instead fall back to generic code that constructs SparseArrayDOK, for example:

julia> a = oneelement((1, 2), (2, 2))
2×2 SparseArraysBase.OneElementMatrix{Bool, Tuple{Int64, Int64}, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}, typeof(SparseArraysBase.default_getunstoredindex)}:
   true
       

julia> 2a
2×2 SparseArraysBase.SparseMatrixDOK{Int64, typeof(SparseArraysBase.default_getunstoredindex)}:
   2
    

Note that most of the code is defining various constructors, and probably that can be simplified.

The idea is that this will serve as the basis for the next-generation oneelement function for constructing ITensors with a single element, see ITensor/ITensorBase.jl#26.

Copy link

codecov bot commented Feb 3, 2025

Codecov Report

Attention: Patch coverage is 67.88321% with 44 lines in your changes missing coverage. Please review.

Project coverage is 75.05%. Comparing base (b41609b) to head (6da5a80).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/oneelementarray.jl 67.88% 44 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main      #26       +/-   ##
===========================================
+ Coverage   62.54%   75.05%   +12.51%     
===========================================
  Files           6        7        +1     
  Lines         283      421      +138     
===========================================
+ Hits          177      316      +139     
+ Misses        106      105        -1     
Flag Coverage Δ
docs 42.10% <0.00%> (-20.31%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@mtfishman mtfishman merged commit f44f3f2 into main Feb 3, 2025
12 checks passed
@mtfishman mtfishman deleted the oneelement branch February 3, 2025 02:46
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