Skip to content

blocksparsezeros with Float64 default #146

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

Merged
merged 2 commits into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "BlockSparseArrays"
uuid = "2c9a651f-6452-4ace-a6ac-809f4280fbb4"
authors = ["ITensor developers <[email protected]> and contributors"]
version = "0.7.11"
version = "0.7.12"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const WrappedAbstractBlockSparseArray{T,N} = WrappedArray{
T,N,AbstractBlockSparseArray,AbstractBlockSparseArray{T,N}
}

# TODO: Rename `AnyBlockSparseArray`.
const AnyAbstractBlockSparseArray{T,N} = Union{
<:AbstractBlockSparseArray{T,N},<:WrappedAbstractBlockSparseArray{T,N}
}
Expand Down Expand Up @@ -414,3 +413,7 @@ function Adapt.adapt_structure(to, a::SubArray{<:Any,<:Any,<:AbstractBlockSparse
# BlockArrays.jl.
return SubArray(adapt(to, parent(a)), parentindices(a))
end

function Base.show(io::IO, a::AnyAbstractBlockSparseArray)
return show(io, convert(Array, a))
end
3 changes: 3 additions & 0 deletions src/blocksparsearray/blocksparsearray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ end
function blocksparsezeros(elt::Type, axes...)
return BlockSparseArray{elt}(undef, axes...)
end
function blocksparsezeros(axes...)
return blocksparsezeros(Float64, axes...)
end
function blocksparsezeros(::BlockType{A}, axes...) where {A<:AbstractArray}
# TODO: Use:
# ```julia
Expand Down
9 changes: 9 additions & 0 deletions test/test_basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ arrayts = (Array, JLArray)
end

# Convenient constructors.
a = blocksparsezeros([2, 3], [2, 3])
@test iszero(a)
@test iszero(blockstoredlength(a))
@test a isa BlockSparseMatrix{Float64,Matrix{Float64}}
@test blocktype(a) == Matrix{Float64}
@test blockstype(a) <: SparseMatrixDOK{Matrix{Float64}}
@test blocksize(a) == (2, 2)
@test blocksizes(a) == [(2, 2) (2, 3); (3, 2) (3, 3)]

a = blocksparsezeros(elt, [2, 3], [2, 3])
@test iszero(a)
@test iszero(blockstoredlength(a))
Expand Down
Loading