12 lines
402 B
C
12 lines
402 B
C
#include "cs.h"
|
|
/* pinv = p', or p = pinv' */
|
|
int *cs_pinv (int const *p, int n)
|
|
{
|
|
int k, *pinv ;
|
|
if (!p) return (NULL) ; /* p = NULL denotes identity */
|
|
pinv = cs_malloc (n, sizeof (int)) ; /* allocate result */
|
|
if (!pinv) return (NULL) ; /* out of memory */
|
|
for (k = 0 ; k < n ; k++) pinv [p [k]] = k ;/* invert the permutation */
|
|
return (pinv) ; /* return result */
|
|
}
|