Exemple #1
0
        public void WriteFractionMatrixToFile(MyMatrix <Fraction> matrix, string fileName)
        {
            var formattedMatrix = MyMatrixFormatter.GetFormattedFractionMatrix(matrix);

            WriteToFile(fileName, formattedMatrix, matrix.Rows);
        }
Exemple #2
0
        public void WriteFractionVectorToFile(Fraction[] vector, string fileName)
        {
            var formattedMatrix = MyMatrixFormatter.GetFormattedFractionVector(vector);

            WriteToFile(fileName, formattedMatrix, vector.Length);
        }
Exemple #3
0
        public void WriteVectorToFile <T>(T[] vector, string fileName) where T : new()
        {
            var formattedMatrix = MyMatrixFormatter.GetFormattedVector(vector);

            WriteToFile(fileName, formattedMatrix, vector.Length);
        }
Exemple #4
0
        public void WriteMatrixToFile <T>(MyMatrix <T> matrix, string fileName) where T : new()
        {
            var formattedMatrix = MyMatrixFormatter.GetFormattedMatrix(matrix);

            WriteToFile(fileName, formattedMatrix, matrix.Rows);
        }
        public void MatrixMulMatrixTest(int testCount)
        {
            // ---------------------------------------------------------
            // fraction
            // ---------------------------------------------------------
            _time = new TimeSpan();
            var frResult = new MyMatrix <Fraction>(1, 1);

            for (var i = 0; i < testCount; i++)
            {
                var frA = new MyMatrix <Fraction>(SfrA);
                var frB = new MyMatrix <Fraction>(SfrB);
                var frC = new MyMatrix <Fraction>(SfrC);

                _stopwatch.Reset();
                _stopwatch.Start();
                frResult = frA * (frB * frC);
                _stopwatch.Stop();
                _time += _stopwatch.Elapsed;
            }

            _handler.WriteToFileWithTimespan(
                IO.PrefixFraction + IO.ResultAbc,
                MyMatrixFormatter.GetFormattedMatrix(frResult),
                CurrentMatrixSize,
                _time.TotalMilliseconds / testCount);


            // ---------------------------------------------------------
            // float
            // ---------------------------------------------------------
            _time = new TimeSpan();
            var fResult = new MyMatrix <float>(0, 0);

            for (var i = 0; i < testCount; i++)
            {
                var fA = new MyMatrix <float>(SfA);
                var fB = new MyMatrix <float>(SfB);
                var fC = new MyMatrix <float>(SfC);

                _stopwatch.Reset();
                _stopwatch.Start();
                fResult = fA * (fB * fC);
                _stopwatch.Stop();
                _time += _stopwatch.Elapsed;
            }

            _handler.WriteToFileWithTimespan(
                IO.PrefixFloat + IO.ResultAbc,
                MyMatrixFormatter.GetFormattedMatrix(fResult),
                CurrentMatrixSize,
                _time.TotalMilliseconds / testCount);

            // ---------------------------------------------------------
            // double
            // ---------------------------------------------------------
            _time = new TimeSpan();
            var dResult = new MyMatrix <double>(0, 0);

            for (var i = 0; i < testCount; i++)
            {
                var dA = new MyMatrix <double>(SdA);
                var dB = new MyMatrix <double>(SdB);
                var dC = new MyMatrix <double>(SdC);

                _stopwatch.Reset();
                _stopwatch.Start();
                dResult = dA * (dB * dC);
                _stopwatch.Stop();
                _time += _stopwatch.Elapsed;
            }

            _handler.WriteToFileWithTimespan(
                IO.PrefixDouble + IO.ResultAbc,
                MyMatrixFormatter.GetFormattedMatrix(dResult),
                CurrentMatrixSize,
                _time.TotalMilliseconds / testCount);
        }
        public void MatrixAddMatrixMulVectorTest(int testCount)
        {
            // ---------------------------------------------------------
            // fraction
            // ---------------------------------------------------------
            _time = new TimeSpan();
            var frResult = new Fraction[0];

            for (var i = 0; i < testCount; i++)
            {
                var frA = new MyMatrix <Fraction>(SfrA);
                var frB = new MyMatrix <Fraction>(SfrB);
                var frC = new MyMatrix <Fraction>(SfrC);
                var frX = SfrX;

                _stopwatch.Reset();
                _stopwatch.Start();
                frResult = (frA + frB + frC) * frX;
                _stopwatch.Stop();
                _time += _stopwatch.Elapsed;
            }

            _handler.WriteToFileWithTimespan(
                IO.PrefixFraction + IO.ResultAbcx,
                MyMatrixFormatter.GetFormattedVector(frResult),
                CurrentMatrixSize,
                _time.TotalMilliseconds / testCount);


            // ---------------------------------------------------------
            // float
            // ---------------------------------------------------------
            _time = new TimeSpan();
            var fResult = new float[0];

            for (var i = 0; i < testCount; i++)
            {
                var fA = new MyMatrix <float>(SfA);
                var fB = new MyMatrix <float>(SfB);
                var fC = new MyMatrix <float>(SfC);
                var fX = SfX;

                _stopwatch.Reset();
                _stopwatch.Start();
                fResult = (fA + fB + fC) * fX;
                _stopwatch.Stop();
                _time += _stopwatch.Elapsed;
            }

            _handler.WriteToFileWithTimespan(
                IO.PrefixFloat + IO.ResultAbcx,
                MyMatrixFormatter.GetFormattedVector(fResult),
                CurrentMatrixSize,
                _time.TotalMilliseconds / testCount);


            // ---------------------------------------------------------
            // double
            // ---------------------------------------------------------
            _time = new TimeSpan();
            var dResult = new double[0];

            for (var i = 0; i < testCount; i++)
            {
                var dA = new MyMatrix <double>(SdA);
                var dB = new MyMatrix <double>(SdB);
                var dC = new MyMatrix <double>(SdC);
                var dX = SdX;

                _stopwatch.Reset();
                _stopwatch.Start();
                dResult = (dA + dB + dC) * dX;
                _stopwatch.Stop();
                _time += _stopwatch.Elapsed;
            }

            _handler.WriteToFileWithTimespan(
                IO.PrefixDouble + IO.ResultAbcx,
                MyMatrixFormatter.GetFormattedVector(dResult),
                CurrentMatrixSize,
                _time.TotalMilliseconds / testCount);
        }
        public void MatrixGaussianReductionFullPivotTest(int testCount)
        {
            // ---------------------------------------------------------
            // fraction
            // ---------------------------------------------------------
            _time = new TimeSpan();
            var frX = SfrX;

            for (var i = 0; i < testCount; i++)
            {
                var frA = new MyMatrix <Fraction>(SfrA);
                frX = SfrX;

                _stopwatch.Reset();
                _stopwatch.Start();
                frA.GaussianReductionFullPivot(frX);
                _stopwatch.Stop();
                _time += _stopwatch.Elapsed;
            }

            _handler.WriteToFileWithTimespan(
                IO.PrefixFraction + IO.ResultFullPivot,
                MyMatrixFormatter.GetFormattedVector(frX),
                CurrentMatrixSize,
                _time.TotalMilliseconds / testCount);


            // ---------------------------------------------------------
            // float
            // ---------------------------------------------------------
            _time = new TimeSpan();
            var fX = SfX;

            for (var i = 0; i < testCount; i++)
            {
                var fA = new MyMatrix <float>(SfA);
                fX = SfX;

                _stopwatch.Reset();
                _stopwatch.Start();
                fA.GaussianReductionFullPivot(fX);
                _stopwatch.Stop();
                _time += _stopwatch.Elapsed;
            }

            _handler.WriteToFileWithTimespan(
                IO.PrefixFloat + IO.ResultFullPivot,
                MyMatrixFormatter.GetFormattedVector(fX),
                CurrentMatrixSize,
                _time.TotalMilliseconds / testCount);


            // ---------------------------------------------------------
            // double
            // ---------------------------------------------------------
            _time = new TimeSpan();
            var dX = SdX;

            for (var i = 0; i < testCount; i++)
            {
                var dA = new MyMatrix <double>(SdA);
                dX = SdX;

                _stopwatch.Reset();
                _stopwatch.Start();
                dA.GaussianReductionFullPivot(dX);
                _stopwatch.Stop();
                _time += _stopwatch.Elapsed;
            }

            _handler.WriteToFileWithTimespan(
                IO.PrefixDouble + IO.ResultFullPivot,
                MyMatrixFormatter.GetFormattedVector(dX),
                CurrentMatrixSize,
                _time.TotalMilliseconds / testCount);
        }