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

[ENHANCEMENT] Remove BlockSparseArray{Float64}([2, 3], [2, 3]) constructor #69

Open
mtfishman opened this issue Feb 27, 2025 · 1 comment · May be fixed by #68
Open

[ENHANCEMENT] Remove BlockSparseArray{Float64}([2, 3], [2, 3]) constructor #69

mtfishman opened this issue Feb 27, 2025 · 1 comment · May be fixed by #68
Assignees
Labels
enhancement New feature or request

Comments

@mtfishman
Copy link
Member

mtfishman commented Feb 27, 2025

Remove the BlockSparseArray{Float64}([2, 3], [2, 3]) constructor. Instead, either undef should be specified explicitly, i.e. BlockSparseArray{Float64}(undef, [2, 3], [2, 3]), or we should define a zeros constructor, i.e. blocksparsezeros(Float64, [2, 3], [2, 3]).

Also note that BlockArrays.jl has both BlockArray{Float64}(undef, [2, 2], [2, 2]) and BlockArray{Float64}(undef_blocks, [2, 2], [2, 2]) which distinguishes between the blocks being allocated with undefined elements vs. the blocks not being allocated yet. Maybe that distinction is relevant for certain block sparse types, or in constructors where you list the block locations (where undef vs. undef_blocks could distinguish between the blocks being allocated or not).

See @lkdvos's PR here: ITensor/SparseArraysBase.jl#33 doing the same thing for SparseArraysBase.jl.

@mtfishman mtfishman added the enhancement New feature or request label Feb 27, 2025
@mtfishman
Copy link
Member Author

mtfishman commented Feb 27, 2025

This is a bit orthogonal, but something this reminds me of is that I wish Julia had a more systematic way of generically constructing special arrays, like zero or random arrays. It seems like the concept undef/UndefInitializer() could be generalized for that, for example:

blocksparsezeros(Float64, [2, 3], [2, 3]) == BlockSparseArray{Float64}(ZeroInitializer(), [2, 3], [2, 3])
blocksparserand(Float64, [2, 3], [2, 3], 0.4) == BlockSparseArray{Float64}(RandInitializer(; density=0.4), [2, 3], [2, 3])

(I think I saw this suggested somewhere but can't find it now, I'm sure this idea has come up before.)

@mtfishman mtfishman self-assigned this Mar 3, 2025
@mtfishman mtfishman transferred this issue from ITensor/NamedDimsArrays.jl Mar 3, 2025
@mtfishman mtfishman linked a pull request Mar 3, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant