Skip to content

Commit 9b61731

Browse files
committed
Fix ambiguities in similar and blockreshape
1 parent 57c083d commit 9b61731

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
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.4.1"
4+
version = "0.4.2"
55

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

src/BlockArraysExtensions/BlockArraysExtensions.jl

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,17 +263,20 @@ function blocks_to_cartesianindices(d::Dictionary{<:Block})
263263
return Dictionary(blocks_to_cartesianindices(eachindex(d)), d)
264264
end
265265

266-
function blockreshape(a::AbstractArray, dims::Tuple{Vararg{Vector{Int}}})
266+
function blockreshape(a::AbstractArray, dims::Tuple{Vector{Int},Vararg{Vector{Int}}})
267267
return blockreshape(a, blockedrange.(dims))
268268
end
269-
270-
function blockreshape(a::AbstractArray, dims::Vararg{Vector{Int}})
271-
return blockreshape(a, dims)
269+
function blockreshape(a::AbstractArray, dim1::Vector{Int}, dim_rest::Vararg{Vector{Int}})
270+
return blockreshape(a, (dim1, dim_rest...))
271+
end
272+
# Fix ambiguity error.
273+
function blockreshape(a::AbstractArray)
274+
return blockreshape(a, ())
272275
end
273276

274277
tuple_oneto(n) = ntuple(identity, n)
275278

276-
function blockreshape(a::AbstractArray, axes::Tuple{Vararg{AbstractUnitRange}})
279+
function _blockreshape(a::AbstractArray, axes::Tuple{Vararg{AbstractUnitRange}})
277280
reshaped_blocks_a = reshape(blocks(a), blocklength.(axes))
278281
reshaped_a = similar(a, axes)
279282
for I in eachstoredindex(reshaped_blocks_a)
@@ -284,8 +287,20 @@ function blockreshape(a::AbstractArray, axes::Tuple{Vararg{AbstractUnitRange}})
284287
return reshaped_a
285288
end
286289

287-
function blockreshape(a::AbstractArray, axes::Vararg{AbstractUnitRange})
288-
return blockreshape(a, axes)
290+
function blockreshape(
291+
a::AbstractArray, axes::Tuple{AbstractUnitRange,Vararg{AbstractUnitRange}}
292+
)
293+
return _blockreshape(a, axes)
294+
end
295+
# Fix ambiguity error.
296+
function blockreshape(a::AbstractArray, axes::Tuple{})
297+
return _blockreshape(a, axes)
298+
end
299+
300+
function blockreshape(
301+
a::AbstractArray, axis1::AbstractUnitRange, axes_rest::Vararg{AbstractUnitRange}
302+
)
303+
return blockreshape(a, (axis1, axes_rest...))
289304
end
290305

291306
function cartesianindices(axes::Tuple, b::Block)

src/abstractblocksparsearray/wrappedabstractblocksparsearray.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,18 @@ end
232232
)
233233
return blocksparse_similar(a, elt, axes)
234234
end
235+
# Fix ambiguity error when non-blocked ranges are passed.
236+
@interface ::AbstractBlockSparseArrayInterface function Base.similar(
237+
a::AbstractArray, elt::Type, axes::Tuple{Base.OneTo,Vararg{Base.OneTo}}
238+
)
239+
return blocksparse_similar(a, elt, axes)
240+
end
241+
# Fix ambiguity error when empty axes are passed.
242+
@interface ::AbstractBlockSparseArrayInterface function Base.similar(
243+
a::AbstractArray, elt::Type, axes::Tuple{}
244+
)
245+
return blocksparse_similar(a, elt, axes)
246+
end
235247
@interface ::AbstractBlockSparseArrayInterface function Base.similar(
236248
a::Type{<:AbstractArray}, elt::Type, axes::Tuple{Vararg{Int}}
237249
)

0 commit comments

Comments
 (0)