/*************************************************************************
        Checks whether inversion result indicate singular matrix
        Returns True on success.
        *************************************************************************/
        private static bool cmatrixcheckinversesingular(ref AP.Complex[,] inva,
            int n,
            double threshold,
            int info,
            ref matinv.matinvreport rep)
        {
            bool result = new bool();
            int i = 0;
            int j = 0;

            result = true;
            if( info!=-3 & info!=1 )
            {
                result = false;
            }
            else
            {
                result = result & !((double)(rep.r1)<(double)(0) | (double)(rep.r1)>(double)(1000*AP.Math.MachineEpsilon));
                result = result & !((double)(rep.rinf)<(double)(0) | (double)(rep.rinf)>(double)(1000*AP.Math.MachineEpsilon));
                if( info==-3 )
                {
                    for(i=0; i<=n-1; i++)
                    {
                        for(j=0; j<=n-1; j++)
                        {
                            result = result & inva[i,j]==0;
                        }
                    }
                }
            }
            return result;
        }
        /*************************************************************************
        Checks whether inverse is correct
        Returns True on success.
        *************************************************************************/
        private static bool spdmatrixcheckinverse(double[,] a,
            double[,] inva,
            bool isupper,
            int n,
            double threshold,
            int info,
            ref matinv.matinvreport rep)
        {
            bool result = new bool();
            int i = 0;
            int j = 0;
            double v = 0;
            int i_ = 0;

            a = (double[,])a.Clone();
            inva = (double[,])inva.Clone();

            for(i=0; i<=n-2; i++)
            {
                if( isupper )
                {
                    for(i_=i+1; i_<=n-1;i_++)
                    {
                        a[i_,i] = a[i,i_];
                    }
                    for(i_=i+1; i_<=n-1;i_++)
                    {
                        inva[i_,i] = inva[i,i_];
                    }
                }
                else
                {
                    for(i_=i+1; i_<=n-1;i_++)
                    {
                        a[i,i_] = a[i_,i];
                    }
                    for(i_=i+1; i_<=n-1;i_++)
                    {
                        inva[i,i_] = inva[i_,i];
                    }
                }
            }
            result = true;
            if( info<=0 )
            {
                result = false;
            }
            else
            {
                result = result & !((double)(rep.r1)<(double)(100*AP.Math.MachineEpsilon) | (double)(rep.r1)>(double)(1+1000*AP.Math.MachineEpsilon));
                result = result & !((double)(rep.rinf)<(double)(100*AP.Math.MachineEpsilon) | (double)(rep.rinf)>(double)(1+1000*AP.Math.MachineEpsilon));
                for(i=0; i<=n-1; i++)
                {
                    for(j=0; j<=n-1; j++)
                    {
                        v = 0.0;
                        for(i_=0; i_<=n-1;i_++)
                        {
                            v += a[i,i_]*inva[i_,j];
                        }
                        if( i==j )
                        {
                            v = v-1;
                        }
                        result = result & (double)(Math.Abs(v))<=(double)(threshold);
                    }
                }
            }
            return result;
        }
        /*************************************************************************
        Checks whether inverse is correct
        Returns True on success.
        *************************************************************************/
        private static bool cmatrixcheckinverse(ref AP.Complex[,] a,
            ref AP.Complex[,] inva,
            int n,
            double threshold,
            int info,
            ref matinv.matinvreport rep)
        {
            bool result = new bool();
            int i = 0;
            int j = 0;
            AP.Complex v = 0;
            int i_ = 0;

            result = true;
            if( info<=0 )
            {
                result = false;
            }
            else
            {
                result = result & !((double)(rep.r1)<(double)(100*AP.Math.MachineEpsilon) | (double)(rep.r1)>(double)(1+1000*AP.Math.MachineEpsilon));
                result = result & !((double)(rep.rinf)<(double)(100*AP.Math.MachineEpsilon) | (double)(rep.rinf)>(double)(1+1000*AP.Math.MachineEpsilon));
                for(i=0; i<=n-1; i++)
                {
                    for(j=0; j<=n-1; j++)
                    {
                        v = 0.0;
                        for(i_=0; i_<=n-1;i_++)
                        {
                            v += a[i,i_]*inva[i_,j];
                        }
                        if( i==j )
                        {
                            v = v-1;
                        }
                        result = result & (double)(AP.Math.AbsComplex(v))<=(double)(threshold);
                    }
                }
            }
            return result;
        }
 /*************************************************************************
 Unsets report
 *************************************************************************/
 private static void unsetrep(ref matinv.matinvreport r)
 {
     r.r1 = -1;
     r.rinf = -1;
 }