Skip to content

Commit

Permalink
Loop over colsupport(vector) in matrix-vector multiplication (#390)
Browse files Browse the repository at this point in the history
* Loop over colsupport(vector) in matrix-vector multiplication

* Bump version to v0.17.36

* Add tests
  • Loading branch information
jishnub authored Aug 17, 2023
1 parent 0ea04c9 commit cf56520
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "BandedMatrices"
uuid = "aae01518-5342-5314-be14-df237901396f"
version = "0.17.35"
version = "0.17.36"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
20 changes: 13 additions & 7 deletions src/generic/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ end
checkdimensions(M)
α,A,B,β,C = M.α,M.A,M.B,M.β,M.C
_fill_lmul!(β, C)
@inbounds for j = rowsupport(A), k = colrange(A,j)
C[k] += α*inbands_getindex(A,k,j)*B[j]
@inbounds for j = intersect(rowsupport(A), colsupport(B))
for k = colrange(A,j)
C[k] += α*inbands_getindex(A,k,j)*B[j]
end
end
C
end
Expand All @@ -111,8 +113,10 @@ end
A = transpose(At)
_fill_lmul!(β, C)

@inbounds for j = rowsupport(A), k = colrange(A,j)
C[j] += α*transpose(inbands_getindex(A,k,j))*B[k]
@inbounds for j = rowsupport(A)
for k = intersect(colrange(A,j), colsupport(B))
C[j] += α*transpose(inbands_getindex(A,k,j))*B[k]
end
end
C
end
Expand All @@ -122,8 +126,10 @@ end
α,Ac,B,β,C = M.α,M.A,M.B,M.β,M.C
A = Ac'
_fill_lmul!(β, C)
@inbounds for j = rowsupport(A), k = colrange(A,j)
C[j] += α*inbands_getindex(A,k,j)'*B[k]
@inbounds for j = rowsupport(A)
for k = intersect(colrange(A,j), colsupport(B))
C[j] += α*inbands_getindex(A,k,j)'*B[k]
end
end
C
end
Expand Down Expand Up @@ -276,4 +282,4 @@ function materialize!(M::MulAdd{<:AbstractColumnMajor, <:BandedColumns, <:Abstra
end

return C
end
end
31 changes: 30 additions & 1 deletion test/test_linalg.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
using BandedMatrices, ArrayLayouts, LinearAlgebra, FillArrays, Test
using ArrayLayouts
using BandedMatrices
using FillArrays
using LinearAlgebra
using Test

import Base.Broadcast: materialize, broadcasted
import BandedMatrices: BandedColumns, _BandedMatrix

# wrap a OneElement to dispatch without type-piracy

struct MyOneElement{T,N,A<:OneElement{T,N}} <: AbstractArray{T,N}
arr :: A
end
Base.size(M::MyOneElement) = size(M.arr)
Base.axes(M::MyOneElement) = axes(M.arr)
Base.getindex(M::MyOneElement{<:Any,N}, inds::Vararg{Int,N}) where {N} =
getindex(M.arr, inds...)

ArrayLayouts.colsupport(::UnknownLayout, A::MyOneElement{<:Any,1}, _) =
intersect(axes(A,1), A.arr.ind[1]:A.arr.ind[1])

@testset "Linear Algebra" begin
@testset "Matrix types" begin
A = brand(5,5,1,2)
Expand Down Expand Up @@ -90,6 +108,17 @@ import BandedMatrices: BandedColumns, _BandedMatrix
end
end

@testset "BandedMatrix * sparse" begin
B = brand(6,6,2,2)
x = MyOneElement(OneElement(2, 4, 6))
y = Array(x)
@test B * x B * y
@test B' * x B' * y

B = brand(Complex{Int8}, 6,6,2,2)
@test B' * x B' * y
end

@testset "gbmm!" begin
@testset "gbmm! subpieces step by step and column by column" begin
for n in (1,5,50), ν in (1,5,50), m in (1,5,50),
Expand Down

2 comments on commit cf56520

@jishnub
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/89822

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.17.36 -m "<description of version>" cf5652019443267ef546e1dea7cec4a900c6740c
git push origin v0.17.36

Please sign in to comment.