1function ok = spok (A) %#ok 2%SPOK checks if a sparse matrix is OK 3% 4% Returns 1 if the sparse matrix A is OK. Also returns 1 if A is not sparse 5% (but a warning is raised, stating that the non-sparse matrix was not checked. 6% 7% Aborts with an error if the matrix is corrupted beyond repair. If that 8% happens, you should quit MATLAB since it's possible your workspace has also 9% been corrupted. 10% 11% Returns 0 if the matrix has out-of-order or duplicate row indices, or 12% explicit zero entries, and raises a warning. If the matrix has out-of-order 13% row indices, they can be repaired in MATLAB with A=A''. If the matrix A has 14% duplicate row indices, then A=A'' will still have duplicates, and spok(A'') 15% will still issue a warning. If the matrix has explicit zeros, you can remove 16% them with A=A*1. 17% 18% SPOK cannot check everything. For example, if your mexFunction has created 19% a sparse matrix but written beyond the end of the array, spok may see a valid 20% matrix. However, your workspace has still been corrupted beyond repair. 21% 22% Example: 23% 24% load west0479 25% ok = spok (west0479) % returns 1, for a real sparse matrix 26% ok = spok (west0479 > .5) % returns 1, for a logical sparse matrix 27% ok = spok (1i*west0479) % returns 1, for a complex sparse matrix 28% ok = spok (speye (5)) % returns 1, for a real sparse matrix 29% ok = spok (rand (42)) % returns 1, but issues a warning (not sparse) 30% 31% See also sparse. 32 33% Copyright 2008-2011, Timothy A. Davis, http://suitesparse.com 34% SPDX-License-Identifier: Apache-2.0 35 36error ('spok mexFunction not installed') ; 37