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

No method for multiplying compatible BlockSkyLineMatrix and BandedMatrix #31

Open
TSGut opened this issue Apr 2, 2019 · 2 comments
Open

Comments

@TSGut
Copy link

TSGut commented Apr 2, 2019

Matrix multiplication is apparently not currently defined for BlockSkyLineMatrix and BandedMatrix even when dimensions should be compatible (i.e m x n array times n x k array).

Not entirely sure if this belongs in BandedMatrices or BlockBandedMatrices but I tend towards the latter so I'll put this here for now.

Here's a simple snippet that reproduces the error:

using BandedMatrices, BlockBandedMatrices

# generate some simple arrays
function M1(N::Integer)
    M = BlockBandedMatrix(Zeros(sum(1:N),N), (1:N,Ones{Int}(N)), (0,0))
        for n=1:N
            for j=1:n
                view(M, Block(n,n))[j,1] = 1.
            end
        end
    return M
end
function M2(N::Integer)
    M=BandedMatrix{Float64}(undef, (N, N), (0,1))
    for n=1:N-1
        M[n,n]=1.
        M[n,n+1]=1.
    end
    M[N,N]=1.
    return M
end

# works as intended, 55x10 * 10x10 * 10x1 array gives 55x1 array
N = 10
M1(N)
M2(N)
testvec = Ones(N,1)
M1(N)*(M2(N)*testvec)

# doesn't work:
M1(N)*M2(N)*testvec
# because this doesn't work
M1(N)*M2(N)

# also doesn't work:
M2(sum(1:N))*M1(N)*testvec
#while this does:
M2(sum(1:N))*(M1(N)*testvec)
@dlfivefifty
Copy link
Member

Can you post the output?

@TSGut
Copy link
Author

TSGut commented Apr 2, 2019

Sure, it gives a method error due to ambiguity. The first one I mentioned which doesn't work outputs

M1(N)*M2(N)
ERROR: MethodError: *(::BlockSkylineMatrix{Float64,Fill{Int64,1,Tuple{Base.OneTo{Int64}}},Fill{Int64,1,Tuple{Base.OneTo{Int64}}}}, ::BandedMatrix{Float64,Array{Float64,2},Base.OneTo{Int64}}) is ambiguous. Candidates:
  *(A::AbstractArray{T,2} where T, B::BandedMatrices.AbstractBandedMatrix, C...) in BandedMatrices at /home/timon/.julia/packages/LazyArrays/jsu0l/src/linalg/lazymul.jl:20
  *(A::BlockBandedMatrices.AbstractBlockBandedMatrix, B::AbstractArray{T,2} where T, C...) in BlockBandedMatrices at /home/timon/.julia/packages/LazyArrays/jsu0l/src/linalg/lazymul.jl:18
Possible fix, define
  *(::BlockBandedMatrices.AbstractBlockBandedMatrix, ::BandedMatrices.AbstractBandedMatrix, ::Vararg{Any,N} where N)

More or less the same for M2(sum(1:N))*M1(N)*testvec:

M2(sum(1:N))*M1(N)*testvec
ERROR: MethodError: *(::BandedMatrix{Float64,Array{Float64,2},Base.OneTo{Int64}}, ::BlockSkylineMatrix{Float64,Fill{Int64,1,Tuple{Base.OneTo{Int64}}},Fill{Int64,1,Tuple{Base.OneTo{Int64}}}}, ::Ones{Float64,2,Tuple{Base.OneTo{Int64},Base.OneTo{Int64}}}) is ambiguous. Candidates:
  *(A::AbstractArray{T,2} where T, B::BlockBandedMatrices.AbstractBlockBandedMatrix, C...) in BlockBandedMatrices at /home/timon/.julia/packages/LazyArrays/jsu0l/src/linalg/lazymul.jl:20
  *(A::BandedMatrices.AbstractBandedMatrix, B::AbstractArray{T,2} where T, C...) in BandedMatrices at /home/timon/.julia/packages/LazyArrays/jsu0l/src/linalg/lazymul.jl:18
Possible fix, define
  *(::BandedMatrices.AbstractBandedMatrix, ::BlockBandedMatrices.AbstractBlockBandedMatrix, ::Vararg{Any,N} where N)

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

2 participants