1 //------------------------------------------------------------------------------
2 // SLIP_LU/slip_get_largest_pivot: find a pivot entry in a column
3 //------------------------------------------------------------------------------
4
5 // SLIP_LU: (c) 2019-2020, Chris Lourenco, Jinhao Chen, Erick Moreno-Centeno,
6 // Timothy A. Davis, Texas A&M University. All Rights Reserved. See
7 // SLIP_LU/License for the license.
8
9 //------------------------------------------------------------------------------
10
11 /* Purpose: This function selects the pivot element as the largest in the
12 * column This is activated if the user sets option->pivot = SLIP_LARGEST.
13 *
14 * Note: This pivoting scheme is NOT recommended for SLIP LU. It is provided
15 * for comparison with other pivoting options.
16 *
17 * On output, the index of the largest pivot is returned.
18 */
19
20 #define SLIP_FREE_ALL \
21 SLIP_MPZ_CLEAR(big);
22
23 #include "slip_internal.h"
24
slip_get_largest_pivot(int64_t * pivot,SLIP_matrix * x,int64_t * pivs,int64_t n,int64_t top,int64_t * xi)25 SLIP_info slip_get_largest_pivot
26 (
27 int64_t *pivot, // the index of largest pivot
28 SLIP_matrix* x, // kth column of L and U
29 int64_t* pivs, // vector which indicates whether each row
30 // has been pivotal
31 int64_t n, // dimension of problem
32 int64_t top, // nonzero pattern is located in xi[top..n-1]
33 int64_t* xi // nonzero pattern of x
34 )
35 {
36
37 //--------------------------------------------------------------------------
38 // check inputs
39 //--------------------------------------------------------------------------
40
41 SLIP_REQUIRE(x, SLIP_DENSE, SLIP_MPZ);
42
43 SLIP_info info ;
44 if (!pivs || !xi || !pivot) {return SLIP_INCORRECT_INPUT;}
45
46 //--------------------------------------------------------------------------
47 // allocate workspace
48 //--------------------------------------------------------------------------
49
50 int64_t i, inew ;
51 int r ;
52 (*pivot) = -1 ;
53 mpz_t big ;
54 SLIP_MPZ_SET_NULL (big) ;
55 SLIP_CHECK (SLIP_mpz_init (big)) ;
56
57 //--------------------------------------------------------------------------
58 // Iterate accross the nonzeros in x
59 //--------------------------------------------------------------------------
60
61 for (i = top; i < n; i++)
62 {
63 // Location of the ith nonzero
64 inew = xi[i];
65 // inew can be pivotal
66 SLIP_CHECK(SLIP_mpz_cmpabs(&r, big, x->x.mpz[inew]));
67 if (pivs[inew] < 0 && r < 0)
68 {
69 // Current largest pivot location
70 (*pivot) = inew;
71 // Current largest pivot value
72 SLIP_CHECK(SLIP_mpz_set(big, x->x.mpz[inew]));
73 }
74 }
75
76 //--------------------------------------------------------------------------
77 // free workspace and return result
78 //--------------------------------------------------------------------------
79
80 SLIP_FREE_ALL;
81 if ((*pivot) == -1)
82 {
83 return SLIP_SINGULAR;
84 }
85 else
86 {
87 return SLIP_OK;
88 }
89 }
90
91