Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 23e012df authored by hhakim's avatar hhakim
Browse files

Bind matlab Faust.susbref() to the new impl. of slicing/subscript (c4c2c431).

- Updating tests.
- Losing negative step in slices.
parent 96ec38f9
No related branches found
No related tags found
No related merge requests found
Pipeline #833834 skipped
......@@ -156,10 +156,12 @@ classdef FaustTest < matlab.unittest.TestCase
disp('testend()')
prod_F = this.mulFactors()
for i=1:size(this.factors{1},1)
this.verifyEqual(prod_F(i,end), this.test_faust(i,end),'RelTol', 0.01)
end_F = full(this.test_faust(i,end));
this.verifyEqual(prod_F(i,end), end_F(1,1),'RelTol', 0.01)
end
for j=1:size(this.factors{this.num_factors},2)
this.verifyEqual(prod_F(end,j), this.test_faust(end,j), 'RelTol', 0.01)
end_F = full(this.test_faust(end,j));
this.verifyEqual(prod_F(end,j), end_F(1,1), 'RelTol', 0.01)
end
end
......@@ -167,16 +169,20 @@ classdef FaustTest < matlab.unittest.TestCase
disp('testsubsref()')
% test whole faust
ref_F = this.mulFactors();
test_F = this.test_faust(1:end,1:end);
test_F = full(this.test_faust(1:end,1:end));
this.verifyEqual(ref_F(1:end,1:end), test_F, 'RelTol', 0.01)
% test a random row
row_i = randi(1,size(this.test_faust,1));
test_F = this.test_faust(row_i,:);
row_i = randi([1,size(this.test_faust,1)]);
test_F = full(this.test_faust(row_i,:));
this.verifyEqual(test_F, ref_F(row_i,:), 'RelTol', 0.01)
% test a random col
col_i = randi(1,size(this.test_faust,2));
test_F = this.test_faust(:,col_i);
col_i = randi([1,size(this.test_faust,2)]);
test_F = full(this.test_faust(:,col_i));
this.verifyEqual(test_F, ref_F(:,col_i), 'RelTol', 0.01)
size(test_F)
size(ref_F(:,col_i))
size(ref_F)
col_i
end
function testFull(this)
......
......@@ -639,10 +639,10 @@ for i=1:dim1
if (size(F_trans_j_i) ~= [1 1])
error('invalid size of F_trans(j,i)');
end
if (F_i_j ~= F_dense(i,j))
if (full(F_i_j) ~= full(F_dense(i,j)))
error('F(i,j) ~= F_dense(i,j)');
end
if (F_trans_j_i ~= F_dense_trans(j,i))
if (full(F_trans_j_i) ~= full(F_dense_trans(j,i)))
error('F(j,i) ~= F_dense_trans(j,i)');
end
end
......@@ -652,7 +652,7 @@ F_slice_slice=F(:,:);
if (size(F_slice_slice,1) ~= dim1) | (size(F_slice_slice,2) ~= dim2)
error('invalid dimension');
end
if (F_slice_slice ~= F_dense)
if (full(F_slice_slice) ~= full(F_dense))
error('F(:,:) ~= F_dense');
end
......@@ -661,7 +661,7 @@ F_trans_slice_slice=F_trans(:,:);
if (size(F_trans_slice_slice,1) ~= dim2) | (size(F_trans_slice_slice,2) ~= dim1)
error('invalid dimension');
end
if (F_trans_slice_slice ~= F_dense')
if (full(F_trans_slice_slice) ~= full(F_dense'))
error('F_trans(:,:) ~= F_dense''');
end
......@@ -670,19 +670,20 @@ F_slice_slice_2=F(1:dim1,1:dim2);
if (size(F_slice_slice_2,1) ~= dim1) | (size(F_slice_slice_2,2) ~= dim2)
error('invalid dimension');
end
if (F_slice_slice_2 ~= F_dense)
if (full(F_slice_slice_2) ~= full(F_dense))
error('F(1:dim1,1:dim2) ~= F_dense');
end
F_inv=F(dim1:-1:1,dim2:-1:1);
if (size(F_inv,1) ~= dim1) | (size(F_inv,2) ~= dim2)
error('invalid dimension');
end
%TODO: re-enable later when negative step will be implemented
%F_inv=F(dim1:-1:1,dim2:-1:1);
%if (size(F_inv,1) ~= dim1) | (size(F_inv,2) ~= dim2)
% error('invalid dimension');
%end
if (F_inv ~= F_dense(dim1:-1:1,dim2:-1:1))
error('F(1:dim1,1:dim2) ~= F_dense(dim1:-1:1,dim2:-1:1)');
end
%if (F_inv ~= F_dense(dim1:-1:1,dim2:-1:1))
% error('F(1:dim1,1:dim2) ~= F_dense(dim1:-1:1,dim2:-1:1)');
%end
%% operator end with slicing
......@@ -691,7 +692,7 @@ if (size(F_end,1) ~= dim1) | (size(F_end,2) ~= dim2)
error('invalid dimension');
end
if (F_end ~= F_dense(1:end,1:end))
if (full(F_end) ~= full(F_dense(1:end,1:end)))
error('F(1:end,1:end) ~= F_dense(1:end,1:end)');
end
......
......@@ -98,19 +98,19 @@ for i=1:nb_access_coeff
if (col ~=F_dense(:,1))
if (full(col) ~=F_dense(:,1))
error('access to the col');
end
if (row ~=F_dense(1,:))
if (full(row) ~=F_dense(1,:))
error('access to the row');
end
if (col_trans ~=F_dense(1,:)')
if (full(col_trans) ~=F_dense(1,:)')
error('access to the col');
end
if (row_trans ~=F_dense(:,1)')
if (full(row_trans) ~=F_dense(:,1)')
error('access to the row');
end
end
......
......@@ -519,7 +519,9 @@ classdef Faust
%>
%> This function overloads a Matlab built-in function.
%>
%> @b Example
%>
%>
%> @b Example
%> @code
%> % in a matlab terminal
%>
......@@ -674,16 +676,16 @@ classdef Faust
end
%==========================================================================================
%> @brief Gets a submatrix of the full matrix of F.
%> @brief Returns a Faust representing a submatrix of the dense matrix of F.
%>
%> This function is a Matlab built-in overload.
%>
%> @b WARNING: this function costs as much as Faust.mtimes.
%> @b WARNING: this function doesn't handle a slice step different to 1 (e.g. F(i:2:j,:) where slice step is 2.)
%>
%> @param F the Faust object.
%> @param S the subscript defining the submatrix (see examples below).
%> @param S the subscript defining the Faust to extract like a submatrix (see examples below).
%>
%> @retval submatrix the full submatrix requested.
%> @retval The Faust object requested.
%>
%> @b Example
%> @code
......@@ -691,13 +693,14 @@ classdef Faust
%> i = randi(min(size(F)), 1, 2)
%> i1 = i(1);i2 = i(2)
%>
%> F(i1,i2) % element at line i1, column i2
%> F(i1,i2) % a Faust representing a matrix with only one element
%> % at row i1, column i2
%>
%> F(:,i2) % full column i2
%>
%> F(3:4,2:5) % submatrix from line 3 to line 4, each line containing only elements from column 2 to 5.
%> F(3:4,2:5) % from row 3 to line 4, each row containing only elements from column 2 to 5.
%>
%> F(1:end,5:end-1) % submatrix from line 1 to end line, each line containing only elements from column 5 to column before the last one.
%> F(1:end,5:end-1) % from row 1 to end row, each one containing only elements from column 5 to column before the last one.
%> @endcode
%>
%> <p>@b See @b also Faust.end.
......@@ -717,13 +720,12 @@ classdef Faust
%
% See also end.
if (~isfield(S,'type')) | (~isfield(S,'subs'))
error(' subsref invalid structure S missing field type or subs');
end
if (~ischar(S.type)) | (~iscell(S.subs))
error(' subsref invalid structure S, S.type must be a char, S.subs must be a cell-array');
error(' subsref invalid structure S, S.type must be a character array, S.subs must be a cell array');
end
if ~strcmp(S.type,'()')
......@@ -740,55 +742,27 @@ classdef Faust
[dim1 dim2]=size(F);
if ischar(slicing_row)
nb_row_selected = dim1;
start_row_id = 1;
end_row_id = dim1;
else
nb_row_selected = length(slicing_row);
start_row_id = slicing_row(1);
end_row_id = slicing_row(end);
end
if ischar(slicing_col)
nb_col_selected = dim2;
start_col_id = 1;
end_col_id = dim2;
else
nb_col_selected = length(slicing_col);
start_col_id = slicing_col(1);
end_col_id = slicing_col(end);
end
% evaluate the complexity of getting the coeff by doing
% A*Identity or A'*Identity
transpose_evaluation = (nb_col_selected > nb_row_selected);
if transpose_evaluation
identity=eye(dim1);
transpose_flag=1;
% switch the 2 different slicing
tmp=slicing_row;
slicing_row=slicing_col;
slicing_col=tmp;
if(F.isReal)
submatrix = Faust(F, mexFaustReal('subsref', F.matrix.objectHandle, start_row_id, end_row_id, start_col_id, end_col_id));
else
identity=eye(dim2);
transpose_flag=0;
submatrix = Faust(F, mexFaustCplx('subsref', F.matrix.objectHandle, start_row_id, end_row_id, start_col_id, end_col_id));
end
% selects the column of the identity, if slicing_col is a char, all
% the column are selected
if ~ischar(slicing_col)
identity=identity(:,slicing_col);
end
% perform A*identity or A'*identity
submatrix=mtimes_trans(F,identity,transpose_flag);
% selects the row of the submatrix, if slicing_row is a char, all
% the row are selected
if ~ischar(slicing_row)
submatrix=submatrix(slicing_row,:);
end
% transpose if needed
if transpose_evaluation
submatrix=submatrix';
end
end
%======================================================================
......
......@@ -495,6 +495,16 @@ void save(Faust::TransformHelper<SCALAR,Cpu>* core_ptr, int nargs, const mxArray
}
if(!strcmp("subsref", cmd)){
int start_row_id = (int) mxGetScalar(prhs[2]);
int end_row_id = (int) mxGetScalar(prhs[3]);
int start_col_id = (int) mxGetScalar(prhs[4]);
int end_col_id = (int) mxGetScalar(prhs[5]);
Faust::TransformHelper<SCALAR, Cpu>* th = core_ptr->slice(start_row_id-1, end_row_id, start_col_id-1, end_col_id);
plhs[0] = convertPtr2Mat<Faust::TransformHelper<SCALAR,Cpu> >(th);
return;
}
// // Call the various class methods
// // Train
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment