Skip to content

Commit 4cbd4f3

Browse files
committed
update
1 parent 82a7673 commit 4cbd4f3

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

src/abstractblocksparsearray/arraylayouts.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using ArrayLayouts: ArrayLayouts, DualLayout, MemoryLayout, MulAdd
1+
using ArrayLayouts: ArrayLayouts, DenseColumnMajor, DualLayout, MemoryLayout, MulAdd
22
using BlockArrays: BlockLayout
33
using SparseArraysBase: SparseLayout
44
using TypeParameterAccessors: parenttype, similartype
@@ -56,6 +56,20 @@ function Base.similar(
5656
return similar(BlockSparseArray{elt, length(axes), output_blocktype′}, axes)
5757
end
5858

59+
# BlockSparseMatrix * dense Vector → dense Vector
60+
# Returns a plain Vector instead of a BlockedVector
61+
function Base.similar(
62+
mul::MulAdd{
63+
<:BlockLayout{<:SparseLayout},
64+
<:DenseColumnMajor,
65+
<:Any,
66+
},
67+
elt::Type,
68+
axes::Tuple{<:AbstractUnitRange},
69+
)
70+
return Vector{elt}(undef, length(only(axes)))
71+
end
72+
5973
# Materialize a SubArray view.
6074
function ArrayLayouts.sub_materialize(layout::BlockLayout{<:SparseLayout}, a, axes)
6175
# TODO: Define `blocktype`/`blockstype` for `SubArray` wrapping `BlockSparseArray`.

test/test_basics.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -432,16 +432,15 @@ arrayts = (Array, JLArray)
432432
a[Block(2, 1)] = dev(randn(elt, size(@view(a[Block(2, 1)]))))
433433
v = dev(randn(elt, 5)) # Dense vector matching column dimension
434434

435-
# Matrix-vector multiplication uses scalar indexing for block iteration
436-
c = @allowscalar a * v
437-
@allowscalar @test Array(c) Array(a) * Array(v)
438-
@test eltype(c) == elt
435+
c = a * v
436+
@test Array(c) Array(a) * Array(v)
437+
@test c isa Vector{elt} # Result should be a plain Vector
439438
@test length(c) == size(a, 1)
440439

441440
# Test with adjoint/transpose
442441
v2 = dev(randn(elt, 5)) # Vector matching row dimension for transposed multiplication
443-
@allowscalar @test Array(a' * v2) Array(a)' * Array(v2)
444-
@allowscalar @test Array(transpose(a) * v2) transpose(Array(a)) * Array(v2)
442+
@test Array(a' * v2) Array(a)' * Array(v2)
443+
@test Array(transpose(a) * v2) transpose(Array(a)) * Array(v2)
445444
end
446445
@testset "cat" begin
447446
a1 = dev(BlockSparseArray{elt}(undef, [2, 3], [2, 3]))

0 commit comments

Comments
 (0)