Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 1fc6e6d6 authored by hhakim's avatar hhakim
Browse files

Add indexing by vector in matfaust.Faust.subsref() binding it to C++ core impl.

Example: F([1,3,9],:)

This commit is issue #32 related.
parent 6966918a
Branches
Tags
No related merge requests found
......@@ -1037,37 +1037,65 @@ classdef Faust
end_ids = zeros(1,2);
start_ids = zeros(1,2);
indexing_by_slice = [ true, true ];
ind_lists = cell(1,2);
ROW=1;
COL=2;
for i=ROW:COL
slicing_list=S.subs{i};
if ischar(slicing_list)
ind_list=S.subs{i};
if ischar(ind_list)
start_ids(i) = 1;
end_ids(i) = size(F,i);
%indexing_by_slice(i) = true
ind_list = 1:size(F,i); % needed if other dim is not a slice
else
start_ids(i) = slicing_list(1);
end_ids(i) = slicing_list(end);
end
if(start_ids(i) < 1 || end_ids(i) < 1)
error(' Subscript indices must be integers >= 1.')
end
if(start_ids(i) > size(F,i) || end_ids(i) > size(F,i))
error(' Index exceeds Faust dimensions.')
if(any(ind_list < 1))
error(' Subscript indices must be integers >= 1.')
elseif(any(ind_list > size(F,i)))
error(' Index exceeds Faust dimensions.')
end
% check if indices in range are indexing_by_slice
sl_sz = size(ind_list,2);
if(sl_sz >= 2)
% TODO: couldn't be without a loop by verifiying two shifted views of array ?
for j=2:sl_sz
d = ind_list(j)-ind_list(j-1);
if(abs(d) > 1 || d < 0)
indexing_by_slice(i) = false;
break
end
end
end
if(indexing_by_slice(i))
start_ids(i) = ind_list(1);
end_ids(i) = ind_list(end);
end
end
ind_lists{i} = ind_list;
end
if(F.isReal)
submatrix = matfaust.Faust(F, mexFaustReal('subsref', F.matrix.objectHandle, start_ids(ROW), end_ids(ROW), start_ids(COL), end_ids(COL)));
if(indexing_by_slice)
submatrix = matfaust.Faust(F, mexFaustReal('subsref', F.matrix.objectHandle, start_ids(ROW), end_ids(ROW), start_ids(COL), end_ids(COL)));
else
% -1 is for converting to 0-base index used in C world
submatrix = matfaust.Faust(F, mexFaustReal('subsref_byvec', F.matrix.objectHandle, uint64(ind_lists{1}-1), uint64(ind_lists{2}-1)));
end
else
submatrix = matfaust.Faust(F, mexFaustCplx('subsref', F.matrix.objectHandle, start_ids(ROW), end_ids(ROW), start_ids(COL), end_ids(COL)));
if(indexing_by_slice)
submatrix = matfaust.Faust(F, mexFaustCplx('subsref', F.matrix.objectHandle, start_ids(ROW), end_ids(ROW), start_ids(COL), end_ids(COL)));
else
submatrix = matfaust.Faust(F, mexFaustCplx('subsref_byvec', F.matrix.objectHandle, uint64(ind_lists{1}-1), uint64(ind_lists{2}-1)));
end
end
if(start_ids(ROW) == end_ids(ROW) && start_ids(COL) == end_ids(COL))
submatrix = full(submatrix);
submatrix = submatrix(1,1);
if(indexing_by_slice(i))
if(start_ids(ROW) == end_ids(ROW) && start_ids(COL) == end_ids(COL))
submatrix = full(submatrix);
submatrix = submatrix(1,1);
end
end
end
......
......@@ -574,6 +574,19 @@ void save(Faust::TransformHelper<SCALAR,Cpu>* core_ptr, int nargs, const mxArray
return;
}
if(!strcmp("subsref_byvec", cmd))
{
unsigned long int *row_pr;
row_pr = (unsigned long int*) mxGetData(prhs[2]);
unsigned long int *col_pr;
col_pr = (unsigned long int*) mxGetData(prhs[3]);
Faust::TransformHelper<SCALAR, Cpu>* th = core_ptr->fancy_index(row_pr, mxGetNumberOfElements(prhs[2]), col_pr, mxGetNumberOfElements(prhs[3]));
plhs[0] = convertPtr2Mat<Faust::TransformHelper<SCALAR,Cpu> >(th);
return;
}
if(!strcmp("mul_faust", cmd)) {
Faust::TransformHelper<SCALAR,Cpu>* right_term = convertMat2Ptr<Faust::TransformHelper<SCALAR,Cpu> >(prhs[2]);
if(right_term->getNbRow() != core_ptr->getNbCol()) mexErrMsgTxt("The dimensions of the two Fausts must agree.");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment