MichielStock / Kronecker.jl

A general-purpose toolbox for efficient Kronecker-based algebra.
MIT License
86 stars 14 forks source link

Issue with Kronecker product involving column vector #89

Closed LuisLake90 closed 3 years ago

LuisLake90 commented 3 years ago

Dear developer(s),

First of all, thanks for the excellent work on this particular Julia package. The reason why I decided to submit this request is based on a recent issue that I encountered while trying to perform the Kronecker product involving a matrix and a column vector. It seems that when trying to perform the above-mentioned operation I receive the following error message ERROR: MethodError: no method matching kronecker(::Array{Float64,2}, ::Array{Float64,1}). Next, I include the piece of toy example that generated the aforementioned error. Although Julia natively supports this operation via the native Base.kron(), the true is that the Kronecker.jl package provides substantial improvements, particularly in terms of runtime, which I've had the opportunity to test on large matrix operations. It would be great if this issue could be solved. Thanks in advance.


julia> using Kronecker
julia> A = rand(4,5);
julia> v = rand(5);
julia> b = kronecker(A, v);
ERROR: MethodError: no method matching kronecker(::Array{Float64,2}, ::Array{Float64,1})
MichielStock commented 3 years ago

Hi Luis, Kronecker only works for AbstractMatrix types, so an easy fix is to do reshape v into a Matrix:

b = kronecker(A, reshape(v, :, 1));

As this is likely a common thing, I look into overloading this so it happens automatically.

LuisLake90 commented 3 years ago

Hi Michiel, Thank you so much for your valuable recommendation, I wasn't fully aware that I had to perform this transformation on the vector in question first, as the vector was not part of the supported AbstractMatrix type. I will definitely use this approach in this particular case.

MichielStock commented 3 years ago

No problem. This is now done automatically in #90.