Mentions légales du service

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

Add matfaust.factparams.ConstraintList in the same idea than previous commit did for pyfaust.

Example of what it changes:
Previously: fact_cons = {ConstraintInt('splin', 500, 32, 5), ConstraintInt('sp', 32, 32, 96), ConstraintInt('sp', 32, 32, 96)};
Now: fact_cons = ConstraintList('splin', 5, 500, 32, 'sp', 96, 32, 32, 'sp', 96, 32, 32);

The former expression is still valid, the new one is a shorthand.
parent bc82167f
No related branches found
No related tags found
No related merge requests found
Pipeline #833846 skipped
classdef ConstraintList
properties(SetAccess = public)
clist
end
methods
function this = ConstraintList(varargin)
import matfaust.factparams.*
tuple_len = 4; % name, value, nrows, ncols
i = 1;
j = 1; % the number of processed constraints
nargs = length(varargin);
this.clist = {};
while(i <= length(varargin))
cname = ConstraintName(varargin{i});
if(i+1 > nargs)
% ENOTE: throw() is a function (it needs ())
throw(MException('ConstraintList:ErroneousVarargin',...
['No value/parameter given to define the ', int2str(j), '-th constraint.']))
end
cval = varargin{i+1};
if(i+2 > nargs)
throw MException('ConstraintList:ErroneousVarargin',...
['No number of rows given to define the ', int2str(j), '-th constraint.'])
end
nrows = varargin{i+2};
if(i+3 > nargs)
throw(MException('ConstraintList:ErroneousVarargin',...
['No number of columns given to define the ', int2str(j), '-th constraint.']))
end
ncols = varargin{i+3};
if(cname.is_int_constraint())
cons = ConstraintInt(cname, nrows, ncols, cval);
elseif(cname.is_real_constraint())
cons = ConstraintReal(cname, nrows, ncols, cval);
elseif(cname.is_mat_constraint())
cons = ConstraintMat(cname, nrows, ncols, cval);
else
% it shouldn't happen because ConstraintName has verified the input data
msg = ' Not a valid name for a ConstraintGeneric object.';
throw(MExecption('ConstraintList:ErroneousVarargin', msg))
end
this.clist = [ this.clist, {cons} ];
i = i + tuple_len;
end
end
end
end
......@@ -15,6 +15,12 @@ classdef ParamsHierarchicalFact < matfaust.factparams.ParamsFact
methods
function p = ParamsHierarchicalFact(fact_constraints, res_constraints, stop_crit1, stop_crit2, varargin)
import matfaust.factparams.*
if(isa(fact_constraints, 'ConstraintList'))
fact_constraints = fact_constraints.clist;
end
if(isa(res_constraints, 'ConstraintList'))
res_constraints = res_constraints.clist;
end
if(~ iscell(fact_constraints))
error('fact_constraints (argument 1) must be a cell array')
end
......
......@@ -14,6 +14,9 @@ classdef ParamsPalm4MSA < matfaust.factparams.ParamsFact
methods
function p = ParamsPalm4MSA(constraints, stop_crit, varargin)
import matfaust.factparams.*
if(isa(constraints, 'ConstraintList'))
constraints = constraints.clist;
end
if(~ iscell(constraints))
error('constraints (argument 1) must be a cell array')
end
......
......@@ -66,7 +66,7 @@ classdef FaustFactory
%> import matfaust.*
%> import matfaust.factparams.*
%> M = rand(500, 32);
%> cons = {ConstraintInt('splin', 500, 32, 5), ConstraintReal('normcol', 32, 32, 1.0)};
%> cons = ConstraintList('splin', 5, 500, 32, 'normcol', 1, 32, 32);
%> stop_crit = StoppingCriterion(200);
%> params = ParamsPalm4MSA(cons, stop_crit, 'is_update_way_R2L', false, 'init_lambda', 1.0);
%> F = FaustFactory.fact_palm4msa(M, params)
......@@ -132,10 +132,8 @@ classdef FaustFactory
%> import matfaust.*
%> import matfaust.factparams.*
%> M = rand(500, 32);
%> fact_cons = cell(3, 1);
%> res_cons = cell(3, 1);
%> fact_cons = {ConstraintInt('splin', 500, 32, 5), ConstraintInt('sp', 32, 32, 96), ConstraintInt('sp', 32, 32, 96)};
%> res_cons = {ConstraintReal('normcol', 32, 32, 1), ConstraintInt('sp', 32, 32, 666), ConstraintInt('sp', 32, 32, 333)};
%> fact_cons = ConstraintList('splin', 5, 500, 32, 'sp', 96, 32, 32, 'sp', 96, 32, 32);
%> res_cons = ConstraintList('normcol', 1, 32, 32, 'sp', 666, 32, 32, 'sp', 333, 32, 32);
%> stop_crit = StoppingCriterion(200);
%> stop_crit2 = StoppingCriterion(200);
%> params = ParamsHierarchicalFact(fact_cons, res_cons, stop_crit, stop_crit2, 'is_update_way_R2L', false, 'init_lambda', 1.0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment