function [f, grad] = simple_mlp_evalMSErVecWrap(x, param)
% Wrapper of the cell array form MLP for a general optimization algorithm
% that thinks it is optimizing just some vector;
%
% The optimizer will call this with x, and additional "user parameters"
%
% The struct 'param' should have everything that the MLP evaluator needs,
% namely the neural net structure and inputs and targets for training.;

tmpnet = param.net; % A temporary net structure..
tmpnet.W = simple_mlp_vec2cell(x, param.net.nneur);

% A hack for solvopt, if it asks for 'only gradient'..
if nargout == 1 && isfield(param,'onlyGrad')
  [f, G] = simple_mlp_evalMSEr(tmpnet, param.inputs, param.targets);
  grad = simple_mlp_cell2vec(G);
  f = grad;
  return
end

if nargout==1
  f = simple_mlp_evalMSEr(tmpnet, param.inputs, param.targets);
elseif nargout==2
  [f, G] = simple_mlp_evalMSEr(tmpnet, param.inputs, param.targets);
  grad = simple_mlp_cell2vec(G);
end
