Skip to content

Commit 16897bb

Browse files
committed
fix similar with eltype change
1 parent 88aa06f commit 16897bb

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

ext/BlockSparseArraysGradedUnitRangesExt/BlockSparseArraysGradedUnitRangesExt.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module BlockSparseArraysGradedUnitRangesExt
22

33
using BlockSparseArrays: AnyAbstractBlockSparseArray, BlockSparseArray, blocktype
44
using GradedUnitRanges: AbstractGradedUnitRange
5-
using TypeParameterAccessors: set_ndims, unwrap_array_type
5+
using TypeParameterAccessors: set_eltype, set_ndims, unwrap_array_type
66

77
# A block spare array similar to the input (dense) array.
88
# TODO: Make `BlockSparseArrays.blocksparse_similar` more general and use that,
@@ -15,7 +15,9 @@ function similar_blocksparse(
1515
# TODO: Probably need to unwrap the type of `a` in certain cases
1616
# to make a proper block type.
1717
return BlockSparseArray{
18-
elt,length(axes),set_ndims(unwrap_array_type(blocktype(a)), length(axes))
18+
elt,
19+
length(axes),
20+
set_eltype(set_ndims(unwrap_array_type(blocktype(a)), length(axes)), elt),
1921
}(
2022
axes
2123
)

test/test_gradedunitrangesext.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
5353
@test 2 * Array(a) == b
5454
end
5555

56+
b = similar(a, ComplexF64)
57+
@test eltype(b) === ComplexF64
58+
5659
# Test mixing graded axes and dense axes
5760
# in addition/broadcasting.
5861
for b in (a + Array(a), Array(a) + a)

0 commit comments

Comments
 (0)