Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 4df8cd0d authored by hhakim's avatar hhakim
Browse files

Implement in matfaust addition and substraction between Fausts or Faust and...

Implement in matfaust addition and substraction between Fausts or Faust and scalar. Add also unit tests.

Issues: #71, #35.
parent 8da6dd57
No related branches found
No related tags found
No related merge requests found
......@@ -359,6 +359,48 @@ classdef FaustTest < matlab.unittest.TestCase
end
end
function testplus(this)
disp('test addition of Faust and scalar (complex and real)')
scals = [rand(1,1)] %, rand(1,1)+rand(1,1)*j] %TODO: re-enable complex when #72 is solved
F = this.test_faust;
for i=1:size(scals,2)
s = scals(i);
disp(['test add of a Faust and scalar = ' num2str(s)])
full_test_F = full(F+s);
ref = full(F)+s;
this.verifyEqual(full_test_F, ref, 'RelTol', 10^-2)
end
disp('test plus(Faust1,Faust2)')
import matfaust.FaustFactory
import matfaust.Faust
fausts = {FaustFactory.rand(5,size(F,1))*Faust(rand(size(F,1),size(F,2)))} %, FaustFactory.rand(5,size(F,1), .5, 'complex')*rand(size(F,2),size(F,2))} %TODO: re-enable complex Faust when #72 is solved
for i=1:length(fausts)
F2 = fausts{i}
this.verifyEqual(full(F+F2),full(F)+full(F2),'RelTol', 10^-2)
end
end
function testminus(this)
disp('test substraction of Faust and scalar (complex and real)')
scals = [rand(1,1)] %, rand(1,1)+rand(1,1)*j] %TODO: re-enable complex when #72 is solved
F = this.test_faust;
for i=1:size(scals,2)
s = scals(i);
disp(['test substraction of a Faust and scalar = ' num2str(s)])
full_test_F = full(F-s);
ref = full(F)-s;
this.verifyEqual(full_test_F, ref, 'RelTol', 10^-2)
end
disp('test minus(Faust1,Faust2)')
import matfaust.FaustFactory
import matfaust.Faust
fausts = {FaustFactory.rand(5,size(F,1))*Faust(rand(size(F,1),size(F,2)))} %, FaustFactory.rand(5,size(F,1), .5, 'complex')*rand(size(F,2),size(F,2))} %TODO: re-enable complex Faust when #72 is solved
for i=1:length(fausts)
F2 = fausts{i}
this.verifyEqual(full(F-F2),full(F)-full(F2),'RelTol', 10^-2)
end
end
function testcat(this)
import matfaust.*
disp('Test cat')
......
......@@ -247,6 +247,38 @@ classdef Faust
delete(F.matrix)
end
%======================================================================
%======================================================================
function F = plus(varargin)
import matfaust.Faust
F = varargin{1}
for i=2:nargin
G = varargin{i};
if(isa(G,'matfaust.Faust'))
if(size(G) ~= size(F))
error('Dimensions must agree.')
end
C = [F,G];
Id = speye(size(C,2)/2);
F = C*Faust([ Id ; Id ]);
elseif(isscalar(G))
F = F+(Faust({speye(size(F,1),size(F,2)), ones(size(F,2), 1)*G, ones(1, size(F,2))}));
else
error('Cannot add a Faust to something that is not a Faust or a scalar.')
end
end
end
%======================================================================
%======================================================================
function M = minus(varargin)
M = varargin{1}
for i=2:nargin
varargin{i} = varargin{i}*-1;
end
M = plus(M, varargin{2:end});
end
%======================================================================
%> / Slash or right Faust divide.
%===
......@@ -1536,7 +1568,7 @@ classdef Faust
else
error(err_1st_arg)
end
C = F
C = F;
for i=3:nargin
A = varargin{i};
if(ismatrix(A) && ~ isa(A, 'matfaust.Faust'))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment