All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jnt.scimark2.LU Maven / Gradle / Ivy

Go to download

SciMark 2.0 is a Java benchmark for scientific and numerical computing. It measures several computational kernels and reports a composite score in approximate Mflops (Millions of floating point operations per second).

The newest version!
package jnt.scimark2;

/**
    LU matrix factorization. (Based on TNT implementation.)
    Decomposes a matrix A  into a triangular lower triangular
    factor (L) and an upper triangular factor (U) such that
    A = L*U.  By convnetion, the main diagonal of L consists
    of 1's so that L and U can be stored compactly in
    a NxN matrix.


*/
public class LU 
{
    /**
        Returns a copy of the compact LU factorization.
        (useful mainly for debugging.)

        @return the compact LU factorization.  The U factor
        is stored in the upper triangular portion, and the L
        factor is stored in the lower triangular portion.
        The main diagonal of L consists (by convention) of
        ones, and is not explicitly stored.
    */


	public static final double num_flops(int N)
	{
		// rougly 2/3*N^3

		double Nd = (double) N;

		return (2.0 * Nd *Nd *Nd/ 3.0);
	}

    protected static double[] new_copy(double x[])
    {
        int N = x.length;
        double T[] = new double[N];
        for (int i=0; icopy of the pivot vector.

        @return the pivot vector used in obtaining the
        LU factorzation.  Subsequent solutions must
        permute the right-hand side by this vector.

    */
    public int[] getPivot()
    {
        return new_copy(pivot_);
    }
    
    /**
        Initalize LU factorization from matrix.

        @param A (in) the matrix to associate with this
                factorization.
    */
    public LU( double A[][] )
    {
        int M = A.length;
        int N = A[0].length;

        //if ( LU_ == null || LU_.length != M || LU_[0].length != N)
            LU_ = new double[M][N];

        insert_copy(LU_, A);

        //if (pivot_.length != M)
            pivot_ = new int[M];

        factor(LU_, pivot_);
    }

    /**
        Solve a linear system, with pre-computed factorization.

        @param b (in) the right-hand side.
        @return solution vector.
    */
    public double[] solve(double b[])
    {
        double x[] = new_copy(b);

        solve(LU_, pivot_, x);
        return x;
    }
    

/**
    LU factorization (in place).

    @param A (in/out) On input, the matrix to be factored.
        On output, the compact LU factorization.

    @param pivit (out) The pivot vector records the
        reordering of the rows of A during factorization.
        
    @return 0, if OK, nozero value, othewise.
*/
public static int factor(double A[][],  int pivot[])
{
 


    int N = A.length;
    int M = A[0].length;

    int minMN = Math.min(M,N);

    for (int j=0; j t)
            {
                jp = i;
                t = ab;
            }
        }
        
        pivot[j] = jp;

        // jp now has the index of maximum element 
        // of column j, below the diagonal

        if ( A[jp][j] == 0 )                 
            return 1;       // factorization failed because of zero pivot


        if (jp != j)
        {
            // swap rows j and jp
            double tA[] = A[j];
            A[j] = A[jp];
            A[jp] = tA;
        }

        if (j=0; i--)
        {
            double sum = b[i];
            for (int j=i+1; j




© 2015 - 2024 Weber Informatics LLC | Privacy Policy