Universal MEX wrapper
19 Mar 2012
Call any function in a shared library from Matlab (with some limits on the function signature).
%This tests examines a diagonal-pivoting incomplete Cholesky factorization
%for semidefinite dense matrices. Note that there is no identical Matlab
%builtin. (chol is for PD matrices, ldl for symmetric indefinite matrices.)
dl_load(0); %Loading the resident namespace doesn't leak memory, so we
%can call it as much as we want.
n = 2000;
rank = 1900;
work = rand(n, rank);
A = work*work';
intT = 'int64';
[UPLO N A2 LDA PIV RNK TOL WORK INFO] = dl_exec('dpstrf_', ...
A, cast(n,intT), cast(zeros(n,1), intT), ...
1e-12, zeros(2*n,1), cast(0,intT));
L = tril(A2);
L = L(:,1:RNK);
norm(A(PIV, PIV) - L*L',1)