Skip to content

Commit d04693f

Browse files
committed
Fix a bug in blocktype
1 parent 88aa06f commit d04693f

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
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.2.13"
4+
version = "0.2.14"
55

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

src/blocksparsearrayinterface/blocksparsearrayinterface.jl

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,26 @@ function eachstoredblock(a::AbstractArray)
4141
return storedvalues(blocks(a))
4242
end
4343

44-
# TODO: Generalize this, this catches simple cases
45-
# where the more general definition isn't specific enough.
46-
blocktype(a::Array) = typeof(a)
47-
# TODO: Maybe unwrap SubArrays?
4844
function blocktype(a::AbstractArray)
49-
# TODO: Unfortunately, this doesn't always give
50-
# a concrete type, even when it could be concrete, i.e.
51-
#=
52-
```julia
53-
julia> eltype(blocks(BlockArray(randn(2, 2), [1, 1], [1, 1])))
54-
Matrix{Float64} (alias for Array{Float64, 2})
55-
56-
julia> eltype(blocks(BlockedArray(randn(2, 2), [1, 1], [1, 1])))
57-
AbstractMatrix{Float64} (alias for AbstractArray{Float64, 2})
58-
59-
julia> eltype(blocks(randn(2, 2)))
60-
AbstractMatrix{Float64} (alias for AbstractArray{Float64, 2})
61-
```
62-
=#
6345
if isempty(blocks(a))
46+
# TODO: Unfortunately, this doesn't always give
47+
# a concrete type, even when it could be concrete, i.e.
48+
#=
49+
```julia
50+
julia> eltype(blocks(BlockArray(randn(2, 2), [1, 1], [1, 1])))
51+
Matrix{Float64} (alias for Array{Float64, 2})
52+
53+
julia> eltype(blocks(BlockedArray(randn(2, 2), [1, 1], [1, 1])))
54+
AbstractMatrix{Float64} (alias for AbstractArray{Float64, 2})
55+
56+
julia> eltype(blocks(randn(2, 2)))
57+
AbstractMatrix{Float64} (alias for AbstractArray{Float64, 2})
58+
```
59+
=#
60+
# That is an issue in BlockArrays.jl that we should address.
6461
return eltype(blocks(a))
6562
end
66-
return eltype(first(blocks(a)))
63+
return mapreduce(typeof, promote_type, blocks(a))
6764
end
6865

6966
abstract type AbstractBlockSparseArrayInterface <: AbstractSparseArrayInterface end

test/test_basics.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ arrayts = (Array, JLArray)
132132
end
133133
end
134134
end
135+
@testset "blocktype" begin
136+
@test blocktype(arrayt(randn(elt, 2, 2))) <: SubArray{elt,2,arrayt{elt,2}}
137+
end
135138
@testset "Basics" begin
136139
a = dev(BlockSparseArray{elt}([2, 3], [2, 3]))
137140
@allowscalar @test a == dev(

0 commit comments

Comments
 (0)