/// <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)); }
/// <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)); }
/// <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)); }
/// <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 dlansp(MatrixNormType matrixNormType, int n, double[] ap, double[] work, BLAS.TriangularMatrixType triangularMatrixType = BLAS.TriangularMatrixType.LowerTriangularMatrix) { var norm = LAPACK.GetMatrixNormType(matrixNormType); var uplo = LAPACK.GetUplo(triangularMatrixType); return(_dlansp(ref norm, ref uplo, ref n, ap, work)); }
/// <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 zlange(MatrixNormType matrixNormType, int m, int n, Complex[] a, Complex[] work) { var norm = LAPACK.GetMatrixNormType(matrixNormType); int lda = Math.Max(1, m); return(_zlange(ref norm, ref m, ref n, a, ref lda, work)); }
/// <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 dlangb(MatrixNormType matrixNormType, int n, int kl, int ku, double[] a, double[] work) { var norm = LAPACK.GetMatrixNormType(matrixNormType); int ldab = kl + ku + 1; return(_dlangb(ref norm, ref n, ref kl, ref ku, a, ref ldab, work)); }
private static void CalcNorm(MCJRMatrix matrix, MatrixNormType normType) { var lib = new MLapackLib(); double norm = lib.norm(Convert.ToSByte(normType), matrix); Console.WriteLine("norm = " + norm); }
/// <summary>Gets a specific norm of the current matrix object. /// </summary> /// <param name="normType">The type of the (matrix) norm.</param> /// <returns>The norm of the current instance with respect to the <paramref name="normType" />.</returns> public double GetNorm(MatrixNormType normType) { switch (normType) { case MatrixNormType.OneNorm: // for a diagonal matrix some matrix norms are identical case MatrixNormType.Infinity: case MatrixNormType.LargestAbsoluteValue: return(Data[BLAS.Level1.idamax(Dimension, Data)]); case MatrixNormType.Frobenius: return(BLAS.Level1.dnrm2(Dimension, Data)); default: throw new NotImplementedException(); } }
/// <summary>Gets a specific norm of the current matrix object. /// </summary> /// <param name="normType">The type of the (matrix) norm.</param> /// <returns>The norm of the current instance with respect to the <paramref name="normType"/>.</returns> public double GetNorm(MatrixNormType normType = MatrixNormType.Frobenius) { /* in the case of a transposed matrix: all norms are identical except 1- and Infinity matrix norm which have to be replaced by each other: */ MatrixNormType adjNormType = normType; if (m_TransposeState == BLAS.MatrixTransposeState.Transpose) { if (normType == MatrixNormType.Infinity) { adjNormType = MatrixNormType.OneNorm; } else if (normType == MatrixNormType.OneNorm) { adjNormType = MatrixNormType.Infinity; } } double[] work = (adjNormType != MatrixNormType.Infinity) ? null : new double[m_RowCount]; return(LAPACK.AuxiliaryRoutines.Matrix.dlange(adjNormType, m_RowCount, m_ColumnCount, m_Data, work)); }
/// <summary>Gets a specific norm of the current matrix object. /// </summary> /// <param name="normType">The type of the (matrix) norm.</param> /// <returns>The norm of the current instance with respect to the <paramref name="normType"/>.</returns> public double GetNorm(MatrixNormType normType) { if (IsQuadratic == true) // apply LAPACK function if available { /* in the case of a transposed matrix: all norms are identical except 1- and Infinity matrix norm which have to be replaced by each other: */ MatrixNormType adjNormType = normType; if (m_TransposeState == BLAS.MatrixTransposeState.Transpose) { if (normType == MatrixNormType.Infinity) { adjNormType = MatrixNormType.OneNorm; } else if (normType == MatrixNormType.OneNorm) { adjNormType = MatrixNormType.Infinity; } } double[] work = (adjNormType != MatrixNormType.Infinity) ? null : new double[m_RowCount]; return(LAPACK.AuxiliaryRoutines.Matrix.dlangb(adjNormType, m_RowCount, m_SubDiagonalCount, m_SuperDiagonalCount, m_Data, work)); } var norm = 0.0; int k = m_SubDiagonalCount + m_SuperDiagonalCount + 1; switch (normType) { case MatrixNormType.Frobenius: NormLoop(x => { norm += x * x; }); return(Math.Sqrt(norm)); case MatrixNormType.LargestAbsoluteValue: norm = Double.MinValue; NormLoop(x => { norm = ((Math.Abs(x) > norm) ? Math.Abs(x) : norm); }); return(norm); case MatrixNormType.Infinity: // max. row sum norm = Double.MinValue; if (m_TransposeState == BLAS.MatrixTransposeState.NoTranspose) { for (int i = 0; i < m_RowCount; i++) { double temp = 0.0; for (int j = Math.Max(0, i - SubDiagonalCount); j <= Math.Min(m_ColumnCount - 1, i + SuperDiagonalCount); j++) { temp += Math.Abs(m_Data[i - j + m_SuperDiagonalCount + j * k]); } norm = (temp > norm) ? temp : norm; } } else { for (int i = 0; i < m_ColumnCount; i++) { double temp = 0.0; for (int j = Math.Max(0, i - SubDiagonalCount); j <= Math.Min(m_RowCount - 1, i + SuperDiagonalCount); j++) { temp += Math.Abs(m_Data[j - i + m_SuperDiagonalCount + i * k]); } norm = (temp > norm) ? temp : norm; } } return(norm); case MatrixNormType.OneNorm: // max. column sum if (m_TransposeState == BLAS.MatrixTransposeState.NoTranspose) { for (int j = 0; j < m_ColumnCount; j++) { int iMin = j - m_SuperDiagonalCount; int iMax = j + m_SubDiagonalCount; var temp = 0.0; for (int i = Math.Max(0, iMin); i < Math.Min(m_RowCount, iMax); i++) { temp += Math.Abs(m_Data[i - j + m_SuperDiagonalCount + j * k]); } norm = (temp > norm) ? temp : norm; } } else { for (int j = 0; j < m_RowCount; j++) { int iMin = j - m_SubDiagonalCount; int iMax = j + m_SuperDiagonalCount; var temp = 0.0; for (int i = Math.Max(0, iMin); i < Math.Min(m_ColumnCount, iMax); i++) { temp += Math.Abs(m_Data[j - i + m_SuperDiagonalCount + i * k]); } norm = (temp > norm) ? temp : norm; } } return(norm); default: throw new NotImplementedException(); } }
public double zlansp(MatrixNormType matrixNormType, int n, Complex[] ap, Complex[] work, BLAS.TriangularMatrixType triangularMatrixType = BLAS.TriangularMatrixType.LowerTriangularMatrix) { throw new NotImplementedException(); }
public double zlange(MatrixNormType matrixNormType, int m, int n, Complex[] a, Complex[] work) { throw new NotImplementedException(); }
public double dlangb(MatrixNormType matrixNormType, int n, int kl, int ku, double[] a, double[] work) { throw new NotImplementedException(); }
/// <summary>Gets a specific norm of the current matrix object. /// </summary> /// <param name="normType">The type of the (matrix) norm.</param> /// <returns>The norm of the current instance with respect to the <paramref name="normType" />.</returns> public double GetNorm(MatrixNormType normType) { double[] work = (normType == MatrixNormType.Infinity) || (normType == MatrixNormType.OneNorm) ? new double[Dimension] : null; return(LAPACK.AuxiliaryRoutines.Matrix.dlansp(normType, Dimension, Data, work)); }
private static void CalcNorm(MCJRMatrix matrix, MatrixNormType normType) { var lib = new MLapackLib(); double norm = lib.norm(Convert.ToSByte(normType), matrix); Console.WriteLine("norm = " + norm); }