Пример #1
0
        public void zhetrd_TestCaseData_Benchmark()
        {
            int n = 4;

            var d   = new double[n];
            var e   = new double[n - 1];
            var tau = new Complex[n - 1];

            var native = new LapackNativeWrapper();
            int lwork  = native.EigenValues.Symmetric.zhetrdQuery(n);
            var a      = new Complex[] {
                -2.28, 1.78 + 2.03 * Complex.ImaginaryOne, 2.26 - 0.1 * Complex.ImaginaryOne, -0.12 - 2.53 * Complex.ImaginaryOne,
                1.78 - 2.03 * Complex.ImaginaryOne, -1.12, 0.01 - 0.43 * Complex.ImaginaryOne, -1.07 - 0.86 * Complex.ImaginaryOne,
                2.26 + 0.1 * Complex.ImaginaryOne, 0.01 + 0.43 * Complex.ImaginaryOne, -0.37, 2.31 + 0.92 * Complex.ImaginaryOne,
                -0.12 + 2.53 * Complex.ImaginaryOne, -1.07 + 0.86 * Complex.ImaginaryOne, 2.31 - 0.92 * Complex.ImaginaryOne, -0.73
            };


            var work = new Complex[lwork];

            native.EigenValues.Symmetric.zhetrd(n, a, d, e, tau, work, BLAS.TriangularMatrixType.LowerTriangularMatrix);

            var expectedDiagonal = new[] { -2.28, -0.1285, -0.1666, -1.9249 };

            Assert.That(d, Is.EqualTo(expectedDiagonal).AsCollection.Within(1E-3));

            var expectedOffDiagonal = new[] { -4.3385, -2.0226, -1.8023 };

            Assert.That(e, Is.EqualTo(expectedOffDiagonal).AsCollection.Within(1E-3));
        }
Пример #2
0
        /// <summary>Returns the value of the 1-norm, Frobenius norm, infinity-norm, or the largest absolute value of any element of general rectangular matrix.
        /// </summary>
        /// <param name="matrixNormType">The type of the matrix norm.</param>
        /// <param name="m">Th enumber of rows.</param>
        /// <param name="n">The number of columns.</param>
        /// <param name="a">The <paramref name="m"/>-by-<paramref name="n"/> dense matrix provided column-by-column.</param>
        /// <param name="work">A workspace array which is referenced in the case of infinity norm only. In this case the length must be at least <paramref name="m"/>.</param>
        /// <returns>The value of the specific matrix norm.</returns>
        public double dlange(MatrixNormType matrixNormType, int m, int n, double[] a, double[] work)
        {
            var norm = LapackNativeWrapper.GetMatrixNormType(matrixNormType);
            int lda  = Math.Max(1, m);

            return(_dlange(ref norm, ref m, ref n, a, ref lda, work));
        }
Пример #3
0
        /// <summary>Returns the value of the 1-norm, Frobenius norm, infinity-norm, or the largest absolute value of any element of symmetric matrix supplied in packed form.
        /// </summary>
        /// <param name="matrixNormType">The type of the matrix norm.</param>
        /// <param name="n">The order of the matrix.</param>
        /// <param name="ap">The specified symmetric matrix in packed form, i.e. either upper or lower triangle as specified in <paramref name="triangularMatrixType"/> with at least <paramref name="n"/> * (<paramref name="n"/> + 1) / 2 elements.</param>
        /// <param name="work">A workspace array which is referenced in the case of 1- or infinity-norm only. In this case the length must be at least <paramref name="n"/>.</param>
        /// <param name="triangularMatrixType">A value indicating whether the upper or lower triangular part of the symmetric input matrix is stored.</param>
        /// <returns>The value of the specific matrix norm.</returns>
        public double zlansp(MatrixNormType matrixNormType, int n, Complex[] ap, Complex[] work, BLAS.TriangularMatrixType triangularMatrixType = BLAS.TriangularMatrixType.LowerTriangularMatrix)
        {
            var norm = LapackNativeWrapper.GetMatrixNormType(matrixNormType);
            var uplo = LapackNativeWrapper.GetUplo(triangularMatrixType);

            return(_zlansp(ref norm, ref uplo, ref n, ap, work));
        }
Пример #4
0
        /// <summary>Returns the value of the 1-norm, Frobenius norm, infinity-norm, or the largest absolute value of any element of general band matrix.
        /// </summary>
        /// <param name="matrixNormType">The type of the matrix norm.</param>
        /// <param name="n">The order of the quadratic general band matrix.</param>
        /// <param name="kl">The number of sub-diagonals of the specific general band matrix.</param>
        /// <param name="ku">The number of super-diagonals of the specific general band matrix.</param>
        /// <param name="a">The general band matrix stored in general band matrix storage, i.e. column-by-column, where each column contains exactly <paramref name="kl" /> + <paramref name="ku" /> + 1 elements.</param>
        /// <param name="work">A workspace array which is referenced in the case of infinity norm only. In this case the length must be at least <paramref name="n" />.</param>
        /// <returns>The value of the specific matrix norm.</returns>
        public double zlangb(MatrixNormType matrixNormType, int n, int kl, int ku, Complex[] a, Complex[] work)
        {
            var norm = LapackNativeWrapper.GetMatrixNormType(matrixNormType);
            int ldab = kl + ku + 1;

            return(_zlangb(ref norm, ref n, ref kl, ref ku, a, ref ldab, work));
        }
        public void dgttrf_TestCaseData_BenchmarkResult()
        {
            int n = 5;
            var diagonalElements            = new[] { 3.0, 2.3, -5, -0.9, 7.1 };
            var subDiagonalElements         = new[] { 3.4, 3.6, 7.0, -6.0 };
            var superDiagonalElements       = new[] { 2.1, -1.0, 1.9, 8.0 };
            var secondSuperDiagonalElements = new double[n];
            var pivotIndices = new int[n];

            var native = new LapackNativeWrapper();

            native.LinearEquations.MatrixFactorization.dgttrf(n, subDiagonalElements, diagonalElements, superDiagonalElements, secondSuperDiagonalElements, pivotIndices);

            var expectedPivotIndices        = new[] { 2, 3, 4, 5, 5 };
            var expectedDiagonalElementsOfU = new[] { 3.4000, 3.6000, 7.0000, -6.0000, -1.0154 };
            var expectedMultipliers         = new[] { 0.8824, 0.0196, 0.1401, -0.0148 };

            Assert.That(pivotIndices, Is.EqualTo(expectedPivotIndices).AsCollection);
            Assert.That(diagonalElements, Is.EqualTo(expectedDiagonalElementsOfU).AsCollection.Within(1E-3));
            Assert.That(subDiagonalElements, Is.EqualTo(expectedMultipliers).AsCollection.Within(1E-3));
        }