Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performances of mul!(x, transpose(B), y) #42

Open
matthieugomez opened this issue Aug 8, 2019 · 2 comments
Open

Performances of mul!(x, transpose(B), y) #42

matthieugomez opened this issue Aug 8, 2019 · 2 comments

Comments

@matthieugomez
Copy link

matthieugomez commented Aug 8, 2019

Thanks for the great package! I am trying to use BandedBlockBandedMatrix as a Jacobian in NLsolve (following SciML/DifferentialEquations.jl#483). However the performances get worse than for a sparse matrix. I think this comes from this line in NLSolve. To give an example

using LinearAlgebra, SparseArrays, BlockBandedMatrices, BenchmarkTools
x = rand(10000)
y = rand(10000)
J = BandedBlockBandedMatrix(Ones(10000, 10000), (fill(100, 100), fill(100, 100)), (1, 1), (1, 1))
@btime mul!($x, transpose($J), $y)
# 2.528 s (1 allocation: 16 bytes)
sparseJ = sparse(J)
@btime mul!($x, transpose($sparseJ), $y)
#  60.817 μs (1 allocation: 16 bytes)

Is there a way to make this operation faster?

@ChrisRackauckas
Copy link

If that matrix is a Jacobian, you probably just want to do reverse mode AD instead.

@dlfivefifty
Copy link
Member

Yes I haven't made sure Transpose{T,<:BandedBlockBandedMatrix} implements the necessary routines. This should in principle be possible, though will take some work.

If you are eager, the starting point is to create a BandedBlockBandedRowMajor() memory layout, see:
https://github.com/JuliaMatrices/BlockBandedMatrices.jl/blob/24c5d6b3f030a7735ece01b0f918b3d634802957/src/BandedBlockBandedMatrix.jl#L279

Then we'd need to make sure sub-blocks are BandedRowMajor():
https://github.com/JuliaMatrices/BlockBandedMatrices.jl/blob/24c5d6b3f030a7735ece01b0f918b3d634802957/src/BandedBlockBandedMatrix.jl#L456

We probably need a call to @lazymul to make sure mul! lowers to the LazyArrays.jl multiplication routines.

In theory then we're done: mul!(x, transpose(A), y) should lower to

https://github.com/JuliaMatrices/BlockBandedMatrices.jl/blob/24c5d6b3f030a7735ece01b0f918b3d634802957/src/linalg.jl#L33

which then will call BandedMatrices.jl's implementation of BandedRowMajor multiplication. Though there is likely missing functionality that will be hit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants