Provide support for the Kronecker product
Description
The Blaze library should provide support for the computation of the Kronecker product. More specifically, it should be possible to ...
- ... compute the Kronecker product between two dense matrices;
- ... compute the Kronecker product between a dense and a sparse matrix;
- ... compute the Kronecker product between a sparse and a dense matrix;
- ... compute the Kronecker product between two sparse matrices.
Conceptually, the computation of the Kronecker product should work as follows:
Conceptual Example
// Creating the matrix
// ( 1 2 3 )
// ( 4 1 2 )
blaze::StaticMatrix<int,2UL,3UL> A{ { 1, 2, 3 }
, { 4, 1, 2 } };
// Creating the matrix
// ( 1 -2 )
// ( -3 1 )
blaze::StaticMatrix<int,2UL,2UL> B{ { 1, -2 }
, { -3, 1 } };
// Evaluating the Kronecker product
blaze::StaticMatrix<int,4UL,6UL> C;
C = kronecker( A, B ); // Results in ( 1 -2 2 -4 3 -6 )
// ( -3 1 -6 2 -9 3 )
// ( 4 -8 1 -2 2 -4 )
// ( -12 4 -3 1 -6 2 )
Tasks
- implement the Kronecker product between two dense matrices
- implement the Kronecker product between a dense and a sparse matrix
- implement the Kronecker product between a sparse and a dense matrix
- implement the Kronecker product between two sparse matrices
- provide a full documentation of the Kronecker product
- ensure compatibility with all existing matrix classes
- ensure compatibility with all existing matrix expressions
- guarantee maximum performance for the operations
- add test cases for the entire Kronecker product functionality
Comments (5)
-
reporter -
reporter - edited description
-
reporter -
assigned issue to
Description
The Blaze library should provide support for the computation of the Kronecker product. More specifically, it should be possible to ...
- ... compute the Kronecker product between two dense matrices;
- ... compute the Kronecker product between a dense and a sparse matrix;
- ... compute the Kronecker product between a sparse and a dense matrix;
- ... compute the Kronecker product between two sparse matrices.
Conceptually, the computation of the Kronecker product should work as follows:
Conceptual Example
// Creating the matrix // ( 1 2 3 ) // ( 4 1 2 ) blaze::StaticMatrix<int,2UL,3UL> A{ { 1, 2, 3 } , { 4, 1, 2 } }; // Creating the matrix // ( 1 -2 ) // ( -3 1 ) blaze::StaticMatrix<int,2UL,2UL> B{ { 1, -2 } , { -3, 1 } }; // Evaluating the Kronecker product blaze::StaticMatrix<int,4UL,6UL> C; C = kronecker( A, B ); // Results in ( 1 -2 2 -4 3 -6 ) // ( -3 1 -6 2 -9 3 ) // ( 4 -8 1 -2 2 -4 ) // ( -12 4 -3 1 -6 2 )
Tasks
- implement the Kronecker product between two dense matrices
- implement the Kronecker product between a dense and a sparse matrix
- implement the Kronecker product between a sparse and a dense matrix
- implement the Kronecker product between two sparse matrices
- provide a full documentation of the Kronecker product
- ensure compatibility with all existing matrix classes
- ensure compatibility with all existing matrix expressions
- guarantee maximum performance for the operations
- add test cases for the entire Kronecker product functionality
-
assigned issue to
-
reporter - changed status to open
-
reporter - changed status to resolved
Summary
The feature has been implemented, tested, optimized, and documented as required. It is immediately available via cloning the Blaze repository and will be officially released in Blaze 3.6.
Kronecker Product
Vector Kronecker Product
The Kronecker product of two vectors with the same transpose flag can be computed via the
kron()
function:using blaze::DynamicVector; using blaze::CompressedVector; DynamicVector<double> v1( 28UL ); CompressedVector<float> v2( 17UL ); // ... Initialization of the vectors CompressedVector<double> v3 = kron( v1, v2 );
Both dense and sparse vectors can be used for a Kronecker product. It is possible to multiply two vectors with different element type, as long as the element types themselves can be multiplied.
Matrix Kronecker Product
The Kronecker product of two matrices can be computed via the
kron()
function:using blaze::DynamicMatrix; using blaze::CompressedMatrix; DynamicMatrix<double> M1( 28UL, 35UL ); CompressedMatrix<float> M2( 17UL, 11UL ); // ... Initialization of the matrices CompressedMatrix<double> M3 = kron( M1, M2 );
Both dense and sparse matrices can be used for a Kronecker product. The storage order of the two matrices poses no restrictions on the operation, all variations are possible. It is also possible to multiply two matrices with different element type, as long as the element types themselves can be multiplied.
- Log in to comment
The following function implements the Kronecker product for both dense and sparse matrices:
Please note that this function provides the required functionality, but is not optimized for speed! Also, the signature is different from the desired signature of a
kronecker()
function.Please feel free to use this function until the functionality has been integrated into Blaze and is officially supported.