An efficiently implemented Matlab function for computing the Khatri-Rao product of sparse matrices.
All that needs to be done is compiling the C code, which can be done by navigating to the root folder of this project in Matlab and then executing the command mex sparse_khatrirao_c.c. The function is then used by calling the m file sparse_khatrirao in the root folder.
The function sparse_khatrirao can be called either with two sparse matrices as input, or with a single input in the form of a row or column cell containing sparse matrices. Both cases are illustrated below.
A = cell(1,4);
for n = 1:4
A{n} = sprand(10, 10, .5);
end
% Provide two matrices as input
C1 = sparse_khatrirao(A{1},A{2});
% Provide a cell of matrices as input
C2 = sparse_khatrirao(A);
Please feel free to contact me at any time if you have any questions or would like to provide feedback on this code. I can be reached at [email protected].