Skip to content

Commit 311f391

Browse files
authored
blocksparsezeros with Float64 default (#146)
1 parent 37b5183 commit 311f391

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "BlockSparseArrays"
22
uuid = "2c9a651f-6452-4ace-a6ac-809f4280fbb4"
33
authors = ["ITensor developers <[email protected]> and contributors"]
4-
version = "0.7.11"
4+
version = "0.7.12"
55

66
[deps]
77
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

src/abstractblocksparsearray/wrappedabstractblocksparsearray.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const WrappedAbstractBlockSparseArray{T,N} = WrappedArray{
1818
T,N,AbstractBlockSparseArray,AbstractBlockSparseArray{T,N}
1919
}
2020

21-
# TODO: Rename `AnyBlockSparseArray`.
2221
const AnyAbstractBlockSparseArray{T,N} = Union{
2322
<:AbstractBlockSparseArray{T,N},<:WrappedAbstractBlockSparseArray{T,N}
2423
}
@@ -414,3 +413,7 @@ function Adapt.adapt_structure(to, a::SubArray{<:Any,<:Any,<:AbstractBlockSparse
414413
# BlockArrays.jl.
415414
return SubArray(adapt(to, parent(a)), parentindices(a))
416415
end
416+
417+
function Base.show(io::IO, a::AnyAbstractBlockSparseArray)
418+
return show(io, convert(Array, a))
419+
end

src/blocksparsearray/blocksparsearray.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ end
250250
function blocksparsezeros(elt::Type, axes...)
251251
return BlockSparseArray{elt}(undef, axes...)
252252
end
253+
function blocksparsezeros(axes...)
254+
return blocksparsezeros(Float64, axes...)
255+
end
253256
function blocksparsezeros(::BlockType{A}, axes...) where {A<:AbstractArray}
254257
# TODO: Use:
255258
# ```julia

test/test_basics.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,15 @@ arrayts = (Array, JLArray)
159159
end
160160

161161
# Convenient constructors.
162+
a = blocksparsezeros([2, 3], [2, 3])
163+
@test iszero(a)
164+
@test iszero(blockstoredlength(a))
165+
@test a isa BlockSparseMatrix{Float64,Matrix{Float64}}
166+
@test blocktype(a) == Matrix{Float64}
167+
@test blockstype(a) <: SparseMatrixDOK{Matrix{Float64}}
168+
@test blocksize(a) == (2, 2)
169+
@test blocksizes(a) == [(2, 2) (2, 3); (3, 2) (3, 3)]
170+
162171
a = blocksparsezeros(elt, [2, 3], [2, 3])
163172
@test iszero(a)
164173
@test iszero(blockstoredlength(a))

0 commit comments

Comments
 (0)