Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 224c9247 authored by hhakim's avatar hhakim
Browse files

Bind wrapper to Faust::prox_blockdiag into matfaust.proj.blockdiag class/functor.

parent 9518cbaa
No related branches found
No related tags found
No related merge requests found
%==================================================
%> Functor for the BLOCKDIAG projector.
%==================================================
classdef blockdiag %< matfaust.proj.proj_gen
properties
m_vec
n_vec
normalized
pos
end
methods
function proj = blockdiag(shape, mn_cell, varargin)
M = zeros(shape(1), shape(2));
m_vec = zeros(1, length(mn_cell));
n_vec = zeros(1, length(mn_cell));
for i=1:length(mn_cell)
m_vec(i) = mn_cell{i}{1};
n_vec(i) = mn_cell{i}{2};
end
proj.m_vec = m_vec;
proj.n_vec = n_vec;
proj.normalized = false;
proj.pos = false;
end
function pM = subsref(self, S)
if(~ strcmp(S.type, '()') && ~ strcmp(S.type, '.'))
error('Invalid use of projector functor object: only () or . are handled')
end
if(iscell(S.subs) && length(S.subs) >= 1 && ismatrix(S.subs{1}))
%error('The projector must be called on a matrix')
M = S.subs{1};
% pM = self.constraint.project(M);
if(isreal(M))
pM = mexFaustReal('prox_blockdiag', M, self.m_vec, self.n_vec, self.normalized, self.pos);
else
pM = mexFaustCplx('prox_blockdiag', M, self.m_vec, self.n_vec, self.normalized, self.pos);
end
elseif(ischar(S.subs) && strcmp('constraint', S.subs))
pM = self.constraint;
else
error('bad use of projector: must be projector(matrix) or projector.constraint.')
end
end
end
end
......@@ -319,6 +319,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
case CONSTRAINT_NAME_HANKEL:
Faust::prox_hankel(mat);
break;
break;
default:
mexErrMsgTxt("Unknown constraint name/type.");
}
......@@ -328,6 +329,50 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
return;
}
if(!strcmp("prox_blockdiag", cmd))
{
if(nlhs!=1)
mexErrMsgTxt("prox_blockdiag(): 1 output variable is expected.");
if(nrhs < 4)
mexErrMsgTxt("prox_blockdiag(): wrong number of arguments (must be 4)");
SCALAR* mat_data = NULL;
const mxArray* mxMat_in = prhs[1];
const mxArray* mx_m_ptr = prhs[2], *mx_n_ptr = prhs[3];
double * m_ptr = NULL, *n_ptr = NULL;
size_t nblocks;
const size_t nrows_mat = mxGetM(mxMat_in);
const size_t ncols_mat = mxGetN(mxMat_in);
mxArray2Ptr(mxMat_in, mat_data);
Faust::MatDense<SCALAR, Cpu> mat(mat_data, nrows_mat, ncols_mat);
mxArray2Ptr<double>(mx_n_ptr, n_ptr);
mxArray2Ptr<double>(mx_m_ptr, m_ptr);
std::vector<faust_unsigned_int> m_vec;
std::vector<faust_unsigned_int> n_vec;
bool normalized = (bool) mxGetScalar(prhs[2]);
bool pos = (bool) mxGetScalar(prhs[3]);
nblocks = mxGetM(mx_m_ptr);
if(nblocks == 1 && mxGetN(mx_n_ptr) > 1)
nblocks = mxGetN(mx_n_ptr);
if(mxGetM(mx_m_ptr) != nblocks && mxGetN(mx_n_ptr) != nblocks)
mexErrMsgTxt("the number of row and col offsets must agree.");
for(int i = 0; i < nblocks; i++)
{
m_vec.push_back((faust_unsigned_int)(m_ptr[i]));
n_vec.push_back((faust_unsigned_int)(n_ptr[i]));
}
// Faust::MatDense<FPP,Cpu> & M, std::vector<faust_unsigned_int> & m_vec, std::vector<faust_unsigned_int>& n_vec, const bool normalized /* default to false */, const bool pos
//
Faust::prox_blockdiag(mat, m_vec, n_vec, normalized, pos);
plhs[0] = FaustMat2mxArray(mat);
return;
}
// New
if (!strcmp("new", cmd))
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment