time | Calls | line |
---|
| | 1 | function K = kron(A,B)
|
| | 2 | %KRON Kronecker tensor product.
|
| | 3 | % KRON(X,Y) is the Kronecker tensor product of X and Y.
|
| | 4 | % The result is a large matrix formed by taking all possible
|
| | 5 | % products between the elements of X and those of Y. For
|
| | 6 | % example, if X is 2 by 3, then KRON(X,Y) is
|
| | 7 | %
|
| | 8 | % [ X(1,1)*Y X(1,2)*Y X(1,3)*Y
|
| | 9 | % X(2,1)*Y X(2,2)*Y X(2,3)*Y ]
|
| | 10 | %
|
| | 11 | % If either X or Y is sparse, only nonzero elements are multiplied
|
| | 12 | % in the computation, and the result is sparse.
|
| | 13 | %
|
| | 14 | % Class support for inputs X,Y:
|
| | 15 | % float: double, single
|
| | 16 | % integers: uint8, int8, uint16, int16, uint32, int32, uint64, int64
|
| | 17 |
|
| | 18 | % Thanks to Bruno Luong for full matrices implementation.
|
| | 19 | % See license.txt for license information.
|
| | 20 | % Thanks to Paul Fackler and Jordan Rosenthal for previous versions.
|
| | 21 | % Copyright 1984-2016 The MathWorks, Inc.
|
| | 22 |
|
< 0.001 | 4067 | 23 | if ~ismatrix(A) || ~ismatrix(B)
|
| | 24 | error(message('MATLAB:kron:TwoDInput'));
|
| | 25 | end
|
| | 26 |
|
0.059 | 4067 | 27 | [ma,na] = size(A);
|
0.017 | 4067 | 28 | [mb,nb] = size(B);
|
| | 29 |
|
0.006 | 4067 | 30 | if ~issparse(A) && ~issparse(B)
|
| | 31 | % Both inputs full, result is full.
|
0.026 | 5 | 32 | A = reshape(A,[1 ma 1 na]);
|
0.008 | 5 | 33 | B = reshape(B,[mb 1 nb 1]);
|
0.159 | 5 | 34 | K = reshape(A.*B,[ma*mb na*nb]);
|
< 0.001 | 4062 | 35 | else
|
| | 36 | % At least one input is sparse, result is sparse.
|
0.115 | 4062 | 37 | K = matlab.internal.sparse.kronSparse(sparse(A), sparse(B));
|
0.004 | 4067 | 38 | end
|
Other subfunctions in this file are not included in this listing.