1 //------------------------------------------------------------------------------
2 // SLIP_LU/slip_get_nonzero_pivot: find a nonzero pivot 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 obtains the first eligible nonzero pivot
12  * This is enabled if the user sets option->pivot = SLIP_FIRST_NONZERO
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 kth pivot is returned.
18  */
19 
20 #include "slip_internal.h"
21 
slip_get_nonzero_pivot(int64_t * pivot,SLIP_matrix * x,int64_t * pivs,int64_t n,int64_t top,int64_t * xi)22 SLIP_info slip_get_nonzero_pivot // find the first eligible nonzero pivot
23 (
24     int64_t *pivot,         // the index of first eligible nonzero pivot
25     SLIP_matrix* x,         // kth column of L and U
26     int64_t* pivs,          // vector indicating which rows are pivotal
27     int64_t n,              // size of x
28     int64_t top,            // nonzero pattern is located in xi[top..n-1]
29     int64_t* xi             // nonzero pattern of x
30 )
31 {
32 
33     //--------------------------------------------------------------------------
34     // check inputs
35     //--------------------------------------------------------------------------
36 
37     SLIP_REQUIRE(x, SLIP_DENSE, SLIP_MPZ);
38 
39     SLIP_info info ;
40     if (!pivs || !xi || !pivot) {return SLIP_INCORRECT_INPUT;}
41 
42     //--------------------------------------------------------------------------
43     // initializations
44     //--------------------------------------------------------------------------
45 
46     (*pivot) = -1; // used later to check for singular matrix
47 
48     //--------------------------------------------------------------------------
49     // Iterate across the nonzeros in x
50     //--------------------------------------------------------------------------
51 
52     for (int64_t i = top; i < n; i++)
53     {
54         // inew is the location of the ith nonzero
55         int64_t inew = xi[i];
56         // check if x[inew] is an eligible pivot
57         int sgn ;
58         SLIP_CHECK (SLIP_mpz_sgn (&sgn, x->x.mpz[inew])) ;
59         if (sgn != 0 && pivs [inew] < 0)
60         {
61             (*pivot) = inew;
62             // End the loop
63             return SLIP_OK;
64         }
65     }
66 
67     // return error code since no qualified pivot found
68     return SLIP_SINGULAR;
69 }
70 
71