Skip to content

Commit 5e46525

Browse files
committed
[WIP] Fix vector show
1 parent 4fe65b6 commit 5e46525

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/abstractblocksparsearray/wrappedabstractblocksparsearray.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ const AnyAbstractBlockSparseArray{T,N} = Union{
2323
<:AbstractBlockSparseArray{T,N},<:WrappedAbstractBlockSparseArray{T,N}
2424
}
2525

26+
const AnyAbstractBlockSparseVector{T} = AnyAbstractBlockSparseArray{T,1}
27+
const AnyAbstractBlockSparseMatrix{T} = AnyAbstractBlockSparseArray{T,2}
28+
const AnyAbstractBlockSparseVecOrMat{T,N} = Union{
29+
AnyAbstractBlockSparseVector{T},AnyAbstractBlockSparseMatrix{T}
30+
}
31+
2632
function DerivableInterfaces.interface(::Type{<:AnyAbstractBlockSparseArray})
2733
return BlockSparseArrayInterface()
2834
end
@@ -355,9 +361,9 @@ function SparseArraysBase.isstored(
355361
end
356362

357363
function Base.replace_in_print_matrix(
358-
A::AnyAbstractBlockSparseArray{<:Any,2}, i::Integer, j::Integer, s::AbstractString
364+
a::AnyAbstractBlockSparseVecOrMat, i::Integer, j::Integer, s::AbstractString
359365
)
360-
return isstored(A, i, j) ? s : Base.replace_with_centered_mark(s)
366+
return isstored(a, i, j) ? s : Base.replace_with_centered_mark(s)
361367
end
362368

363369
# attempt to catch things that wrap GPU arrays

src/blocksparsearray/blocksparsearray.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ function BlockSparseArray{T,N}(
174174
return BlockSparseArray{T,N,Array{T,N}}(undef, axes)
175175
end
176176

177+
function BlockSparseArray{T,N}(
178+
::UndefInitializer, axes::Tuple{Vararg{AbstractUnitRange{<:Integer}}}
179+
) where {T,N}
180+
return throw(ArgumentError("Length of axes doesn't match number of dimensions."))
181+
end
182+
177183
function BlockSparseArray{T,N}(
178184
::UndefInitializer, axes::Vararg{AbstractUnitRange{<:Integer},N}
179185
) where {T,N}

test/test_basics.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ arrayts = (Array, JLArray)
130130
@test iszero(storedlength(a))
131131
end
132132
end
133+
134+
for dims in (
135+
([2, 2], [2, 2]),
136+
(([2, 2], [2, 2]),),
137+
blockedrange.(([2, 2], [2, 2])),
138+
(blockedrange.(([2, 2], [2, 2])),),
139+
)
140+
@test_throws ArgumentError BlockSparseVector{elt}(undef, dims...)
141+
end
133142
end
134143
@testset "blockstype, blocktype" begin
135144
a = arrayt(randn(elt, 2, 2))

0 commit comments

Comments
 (0)