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

Khatri-Rao product #105

Closed
pierrejoyot opened this issue Apr 11, 2020 · 3 comments
Closed

Khatri-Rao product #105

pierrejoyot opened this issue Apr 11, 2020 · 3 comments

Comments

@pierrejoyot
Copy link
Contributor

Currently, the Kronecker product (kron(A) function) of a BlockMatrix does not take into account the block structure of the matrix.

For BlockMatrix, the classical definition of the Kronecker product is replaced by the Khatri–Rao product or the Tracy–Singh product (https://en.wikipedia.org/wiki/Kronecker_product).

I would find it very interesting to add these functions to your very useful library.

My implementation of the Khatri–Rao product:

function kron_khatri_rao(A::AbstractBlockMatrix, B::AbstractBlockMatrix)
    # https://en.wikipedia.org/wiki/Kronecker_product
    _Ablksize = blocksize(A)
    _Bblksize = blocksize(A)
    @assert _Ablksize == _Bblksize

    _kblk = []
    for _iblk in 1:_Ablksize[1]
        _kblk_j = []
        for _jblk in 1:_Ablksize[2]
            _Ablk = A[Block(_iblk, _jblk)]
            _Bblk = B[Block(_iblk, _jblk)]
            push!(_kblk_j, kron(_Ablk, _Bblk))
        end
        push!(_kblk, tuple(_kblk_j...))
    end
    mortar(_kblk...)
end
@dlfivefifty
Copy link
Member

Would love a PR for this!

We should support both and have one be the default. Note also test that the special routines work with Array: these are treated as block arrays with one block, so it would be great to have a convenient way to create a block array for the kronecker product

@pierrejoyot
Copy link
Contributor Author

Ok, I'm preparing a PR

@dlfivefifty
Copy link
Member

This is done. We also have blockkron.

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