public virtual double[] solve(double[] b) { double[] b1 = LU.new_copy(b); LU.solve(this.m_LU, this.m_pivot, b1); return(b1); }
public LU(double[][] A) { this.m_LU = LU.new_copy(A); this.m_pivot = new int[A.Length]; LU.factor(this.m_LU, this.m_pivot); }
public static double measureLU(int N, double min_time, Random R) { // compute approx Mlfops, or O if LU yields large errors double[][] A = RandomMatrix(N, N, R); double[][] lu = new double[N][]; for (int i = 0; i < N; i++) { lu[i] = new double[N]; } int[] pivot = new int[N]; Stopwatch clock = new Stopwatch(); Stopwatch watch = new Stopwatch(); int cycles = 1; long copyTime = 0; long factorTime = 0; while (true) { clock.Start(); for (int i = 0; i < cycles; i++) { watch.Start(); CopyMatrix(lu, A); watch.Stop(); copyTime += watch.ElapsedMilliseconds; watch.Reset(); watch.Start(); LU.factor(lu, pivot); watch.Stop(); factorTime += watch.ElapsedMilliseconds; watch.Reset(); } clock.Stop(); if (clock.Elapsed.TotalSeconds >= min_time) { break; } cycles *= 2; } Console.WriteLine("Time spent in measureLU:\nCopyMatrix: {0} ms\nLU.factor: {1} ms\ncycles: {2}", copyTime, factorTime, cycles); // verify that LU is correct double[] b = RandomVector(N, R); double[] x = NewVectorCopy(b); LU.solve(lu, pivot, x); const double EPS = 1.0e-12; if (normabs(b, matvec(A, x)) / N > EPS) { return(0.0); } // else return approx Mflops // return(LU.num_flops(N) * cycles / clock.Elapsed.TotalMilliseconds * 1.0e-3); }