1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
// CSparse/Source/cs_pinv: construct an inverse permutation
// CSparse, Copyright (c) 2006-2022, Timothy A. Davis. All Rights Reserved.
// SPDX-License-Identifier: LGPL-2.1+
#include "cs.h"
/* pinv = p', or p = pinv' */
csi *cs_pinv (csi const *p, csi n)
{
csi k, *pinv ;
if (!p) return (NULL) ; /* p = NULL denotes identity */
pinv = cs_malloc (n, sizeof (csi)) ; /* 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 */
}
|