function varargout = cholincsp(varargin)
%
% CHOLINCSP - Incomplete Cholesky factorization with symmetric pivoting
%
%    R = CHOLINCSP(X) computes an inclomplete Cholesky factorization of a
%    symmetrix matrix X, such that R*R' is a permutation of the rows and
%    columns of X.  The columns of Cholesky factor R are computed one at
%    a time, with symmetric pivoting, as described in [1]. 
%
%    [R,I] = CHOLINC(X) also gives the permutation in I, such that
%    R*R' = X(I,I) .  If R contains n columns, then the first n elements of I
%    specify a set of linearly independent columns forming a basis for the
%    remaining columns of X.
%
%    R = CHOLINCSP(X, TOL) allows the termination criterion (TOL) to be
%    adjusted (a default value of 1e-12 is used if only one argument is
%    given.
%
%    References :
%
%       [1] Fine, S. and Scheinberg, K., "Efficient SVM training using
%           low-rank kernel representations", Journal of Machine Learning
%           Research, vol. 2, pp 243-264, December 2001.
%
%    See also : CHOLINCSP_TEST

%
% File        : cholincsp.m
%
% Date        : Saturday 25th March 2005
%
% Author      : Gavin C. Cawley
%
% Description : Help file for Mex implementation of the incomplete Cholesky
%               factorisation with symmetric pivoting, as described by
%               Fine and Scheinberg [1].
%
% References  : [1] Fine, S. and Scheinberg, K., "Efficient SVM training
%                   using low-rank kernel representations", Journal of Machine
%                   Learning Research, vol. 2, pp 243-264, December 2001.
%
% History     : 25/03/2005 - v1.00
%
% Copyright   : (c) Dr Gavin C. Cawley, March 2005.
%
%    This program is free software; you can redistribute it and/or modify
%    it under the terms of the GNU General Public License as published by
%    the Free Software Foundation; either version 2 of the License, or
%    (at your option) any later version.
%
%    This program is distributed in the hope that it will be useful,
%    but WITHOUT ANY WARRANTY; without even the implied warranty of
%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%    GNU General Public License for more details.
%
%    You should have received a copy of the GNU General Public License
%    along with this program; if not, write to the Free Software
%    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
%

% store the current working directory

cwd = pwd;

% find out name of the currently running m-file (i.e. this one!)

name = mfilename;

% find out what directory it is defined in

dir             = which(name);
dir(dir == '\') = '/';
dir             = dir(1:max(find(dir == '/')-1));

% try changing to that directory

try

   cd(dir);

catch

   % this should never happen, but just in case!

   cd(cwd);

   error(['unable to locate directory containing ''' name '.m''']);

end

% try recompiling the MEX file

try

   mex([name '.c'], '-lm');

catch

   % this may well happen happen, get back to current working directory!

   cd(cwd);

   error('unable to compile MEX version of ''%s''%s\n%s%s', name, ...
         ', please make sure your', 'MEX compiler is set up correctly', ...
         ' (try ''mex -setup'').');


end

% change back to the current working directory

cd(cwd);

% refresh the function and file system caches

rehash;

% try to invoke MEX version using the same input and output arguments

[varargout{1:nargout}] = feval(name, varargin{:});

% bye bye...

