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

kron for more than 2 operands #4695

Closed
Jutho opened this issue Oct 31, 2013 · 7 comments
Closed

kron for more than 2 operands #4695

Jutho opened this issue Oct 31, 2013 · 7 comments
Labels
linear algebra Linear algebra

Comments

@Jutho
Copy link
Contributor

Jutho commented Oct 31, 2013

As an associative operation, it would make sense to extend kron to an arbitrary number of arguments. I think adding these definitions to linalg/dense.jl would do the trick, but I leave it to the developers to choose the strategy that fits best with the multiple dispatch philosophy (hence no pull request):

kron(a::Vector, args...) = kron(a,kron(args...))
kron(a::Matrix, args...) = kron(a,kron(args...))
kron(a::Number, args...) = kron(a,kron(args...))

Also, how would you feel of having a new binary operator ⊗ (U+2297) that refers to kron?

@jiahao
Copy link
Member

jiahao commented Oct 31, 2013

There is an old issue about custom infix operators.

@staticfloat
Copy link
Sponsor Member

I believe the issue @jiahao is referring to is #552 (wow, all the way back in the triple-digits!)

@Jutho
Copy link
Contributor Author

Jutho commented Oct 31, 2013

Indeed, I should have looked first. However, aside from the discussion of allowing infix operators and using unicode for them, it is interesting that StefanKarpinski mentions in #552 that you can always do kron(A,B,C), which is not true (for me at least, with the latest Julia build).

@stevengj
Copy link
Member

Putting aside the issue of infix operators, I think it would be great to have kron for more than 2 operands. I would suggest following the model of the multi-operand + etc. code in operators.jl (lines 67–68), and define:

kron(a, b, c) = kron(kron(a,b), c)
kron(a, b, c, xs...) = kron(kron(kron(a,b),c), xs...)

@JeffBezanson
Copy link
Sponsor Member

An even simpler definition would be:

kron(a, b, c, xs...) = throw(MemoryError())

:)

@lsorber
Copy link

lsorber commented Oct 31, 2013

+1

@stevengj
Copy link
Member

stevengj commented Nov 1, 2013

@JeffBezanson, a counterexample would be a Hadamard matrix, which can be defined as a Kronecker product of 2×2 matrices. Since they are 2×2, you can afford to ⊗ a dozen of them before worrying about memory. (Of course, you are better off representing the matrix implicitly and using Hadamard.jl, but sometimes it's nice to play around with the full matrix.)

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

No branches or pull requests

6 participants