Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 5d28c317 authored by hhakim's avatar hhakim
Browse files

Update matfaust.lazylinop.kron to fit the new implementation of LazyLinearOp...

Update matfaust.lazylinop.kron to fit the new implementation of LazyLinearOp and update related unit tests.
parent 97f6a6f0
No related branches found
No related tags found
No related merge requests found
......@@ -19,17 +19,17 @@ classdef LazyLinearOpKronTest < LazyLinearOpTest
function instantiateTestFaust(this)
import matfaust.rand
import matfaust.lazylinop.asLazyLinearOp
import matfaust.lazylinop.aslazylinearoperator
import matfaust.lazylinop.kron
F1 = rand(10, 15);
F2 = rand(10, 15);
lop_A = asLazyLinearOp(F1);
lop_B = asLazyLinearOp(F2);
lop_A = aslazylinearoperator(F1);
lop_B = aslazylinearoperator(F2);
this.lop = kron(lop_A, lop_B)
this.lopA = full(this.lop);
this.lop2 = asLazyLinearOp(rand(size(this.lop, 1), size(this.lop, 2)));
this.lop2 = aslazylinearoperator(rand(size(this.lop, 1), size(this.lop, 2)));
this.lop2A = full(this.lop2);
this.lop3 = asLazyLinearOp(rand(size(this.lop, 2), 10));
this.lop3 = aslazylinearoperator(rand(size(this.lop, 2), 10));
this.lop3A = full(this.lop3);
end
end
......
......@@ -40,9 +40,36 @@
%> 1
%> @endcode
%>
%> @b See @b also: LazyLinearOpKron, kron matlab built-in.
%> @b See @b also: kron matlab built-in.
%=============================================================
function KL = kron(A, B)
import matfaust.lazylinop.LazyLinearOpKron
KL = LazyLinearOpKron(A, B);
function LK = kron(A, B)
import matfaust.lazylinop.*
hasmeth = @(x, meth) any(ismember(methods(x), meth));
function LmK = kron_(A, B, shape, op)
op_is_scalar = all(size(op) == [1, 1]);
if ~ op_is_scalar && ~ shape(2) == size(op, 1)
error('Dimensions must agree')
end
if op_is_scalar
new_size = shape;
else
new_size = [shape(1), size(op, 2)];
end
if ismatrix(op) && isnumeric(op) && ~ op_is_scalar && hasmeth(op, 'reshape') && hasmeth(op, 'mtimes') %&& hasmeth(op, 'subsref')
% op is not a LazyLinearOp because isnumeric(LazyLinearOp) is always false
% op is a dense matrix that is not limited to one element
LmK = zeros(new_size);
for j=1:new_size(2)
op_mat = reshape(op(:, j), [size(B, 2), size(A, 2)]);
LmK(:, j) = reshape(B * op_mat * transpose(A), [new_size(1), 1]);
end
else
error(['op must possess reshape and mtimes methods to'
' be multiplied by a Kronecker LazyLinearOp (use full() on the'
' latter to multily by the former)'])
end
end
shape = [size(A, 1) * size(B, 1), size(A, 2) * size(B, 2)];
LK = LazyLinearOperator(shape, 'matmat', @(x) kron_(A, B, shape, x), ...
'rmatmat', @(x) kron_(A', B', [shape(2), shape(1)], x));
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment