/// /// This file is part of ILNumerics Community Edition. /// /// ILNumerics Community Edition - high performance computing for applications. /// Copyright (C) 2006 - 2012 Haymo Kutschbach, http://ilnumerics.net /// /// ILNumerics Community Edition is free software: you can redistribute it and/or modify /// it under the terms of the GNU General Public License version 3 as published by /// the Free Software Foundation. /// /// ILNumerics Community Edition is distributed in the hope that it will be useful, /// but WITHOUT ANY WARRANTY; without even the implied warranty of /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /// GNU General Public License for more details. /// /// You should have received a copy of the GNU General Public License /// along with ILNumerics Community Edition. See the file License.txt in the root /// of your distribution package. If not, see . /// /// In addition this software uses the following components and/or licenses: /// /// ================================================================================= /// The Open Toolkit Library License /// /// Copyright (c) 2006 - 2009 the Open Toolkit library. /// /// Permission is hereby granted, free of charge, to any person obtaining a copy /// of this software and associated documentation files (the "Software"), to deal /// in the Software without restriction, including without limitation the rights to /// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of /// the Software, and to permit persons to whom the Software is furnished to do /// so, subject to the following conditions: /// /// The above copyright notice and this permission notice shall be included in all /// copies or substantial portions of the Software. /// /// ================================================================================= /// using System; using System.Collections.Generic; using System.Text; using ILNumerics.Storage; using ILNumerics.Misc; using ILNumerics.Exceptions; namespace ILNumerics { public partial class ILMath { /// /// Vector or matrix norm /// /// Input matrix/ vector /// [Optional] Degree of norm (default = 2). For vectors this must be one of: /// /// arbitrary double value : returns sum(pow(abs(A),degree))^(1/degree) /// System.double.PositiveInfinity: return Max(abs(A)) /// System.double.NegativeInfinity: return Min(abs(A)) /// /// For matrices this must be one out of: /// /// 0: returns Frobenius norm: sqrt(sum(diag(multiply(A, A[1])))) /// 1: returns 1-norm, max(sum(abs(A))) /// 2: returns the largest singular value of A, max(svd(A)) /// PositiveInfinity: returns max(sum(abs(A), 2)), the largest value of the sums along the rows /// /// /// Array of same type as input array A public static ILRetArray< double > norm(ILInArray< double > A, double degree = 2) { using (ILScope.Enter(A)) { if (Object.Equals(A, null) || !A.IsMatrix) throw new ILArgumentSizeException("input array must be matrix or vector."); if (A.IsEmpty) return new ILRetArray< double>(ILSize.Scalar1_1); else if (A.IsVector) { if (degree == Double.PositiveInfinity) { return max(abs(A)); } else if (degree == Double.NegativeInfinity) { return min(abs(A)); } else { if (degree == 0.0) return array< double>( ( double)Double.PositiveInfinity , 1, 1); return pow(sum(pow(abs(A), ( double)degree)), ( double)(1.0 / degree)); } } else { if (degree == 1.0) { return max(sum(abs(A))); } else if (degree == 2.0) { return max(svd(A)); } else if (degree == Double.PositiveInfinity) { return max(sum(abs(A), 2)); } else if (degree == 0.0) { return sqrt(sum(diag (multiply(A, A[1])))); } else { throw new ILArgumentException("invalid argument 'degree' supplied. valid for matrices: 0,1,2,Double.PositiveInfinity"); } } } } #region HYCALPER AUTO GENERATED CODE /// /// Vector or matrix norm /// /// Input matrix/ vector /// [Optional] Degree of norm (default = 2). For vectors this must be one of: /// /// arbitrary double value : returns sum(pow(abs(A),degree))^(1/degree) /// System.double.PositiveInfinity: return Max(abs(A)) /// System.double.NegativeInfinity: return Min(abs(A)) /// /// For matrices this must be one out of: /// /// 0: returns Frobenius norm: sqrt(sum(diag(multiply(A, A[1])))) /// 1: returns 1-norm, max(sum(abs(A))) /// 2: returns the largest singular value of A, max(svd(A)) /// PositiveInfinity: returns max(sum(abs(A), 2)), the largest value of the sums along the rows /// /// /// Array of same type as input array A public static ILRetArray< float > norm(ILInArray< fcomplex > A, double degree = 2) { using (ILScope.Enter(A)) { if (Object.Equals(A, null) || !A.IsMatrix) throw new ILArgumentSizeException("input array must be matrix or vector."); if (A.IsEmpty) return new ILRetArray< float>(ILSize.Scalar1_1); else if (A.IsVector) { if (degree == Double.PositiveInfinity) { return max(abs(A)); } else if (degree == Double.NegativeInfinity) { return min(abs(A)); } else { if (degree == 0.0) return array< float>( ( float)Double.PositiveInfinity , 1, 1); return pow(sum(pow(abs(A), ( float)degree)), ( float)(1.0 / degree)); } } else { if (degree == 1.0) { return max(sum(abs(A))); } else if (degree == 2.0) { return max(svd(A)); } else if (degree == Double.PositiveInfinity) { return max(sum(abs(A), 2)); } else if (degree == 0.0) { return sqrt(sum(real(diag(multiply(A, A[1]))))); } else { throw new ILArgumentException("invalid argument 'degree' supplied. valid for matrices: 0,1,2,Double.PositiveInfinity"); } } } } /// /// Vector or matrix norm /// /// Input matrix/ vector /// [Optional] Degree of norm (default = 2). For vectors this must be one of: /// /// arbitrary double value : returns sum(pow(abs(A),degree))^(1/degree) /// System.double.PositiveInfinity: return Max(abs(A)) /// System.double.NegativeInfinity: return Min(abs(A)) /// /// For matrices this must be one out of: /// /// 0: returns Frobenius norm: sqrt(sum(diag(multiply(A, A[1])))) /// 1: returns 1-norm, max(sum(abs(A))) /// 2: returns the largest singular value of A, max(svd(A)) /// PositiveInfinity: returns max(sum(abs(A), 2)), the largest value of the sums along the rows /// /// /// Array of same type as input array A public static ILRetArray< float > norm(ILInArray< float > A, double degree = 2) { using (ILScope.Enter(A)) { if (Object.Equals(A, null) || !A.IsMatrix) throw new ILArgumentSizeException("input array must be matrix or vector."); if (A.IsEmpty) return new ILRetArray< float>(ILSize.Scalar1_1); else if (A.IsVector) { if (degree == Double.PositiveInfinity) { return max(abs(A)); } else if (degree == Double.NegativeInfinity) { return min(abs(A)); } else { if (degree == 0.0) return array< float>( ( float)Double.PositiveInfinity , 1, 1); return pow(sum(pow(abs(A), ( float)degree)), ( float)(1.0 / degree)); } } else { if (degree == 1.0) { return max(sum(abs(A))); } else if (degree == 2.0) { return max(svd(A)); } else if (degree == Double.PositiveInfinity) { return max(sum(abs(A), 2)); } else if (degree == 0.0) { return sqrt(sum(diag(multiply(A, A[1])))); } else { throw new ILArgumentException("invalid argument 'degree' supplied. valid for matrices: 0,1,2,Double.PositiveInfinity"); } } } } /// /// Vector or matrix norm /// /// Input matrix/ vector /// [Optional] Degree of norm (default = 2). For vectors this must be one of: /// /// arbitrary double value : returns sum(pow(abs(A),degree))^(1/degree) /// System.double.PositiveInfinity: return Max(abs(A)) /// System.double.NegativeInfinity: return Min(abs(A)) /// /// For matrices this must be one out of: /// /// 0: returns Frobenius norm: sqrt(sum(diag(multiply(A, A[1])))) /// 1: returns 1-norm, max(sum(abs(A))) /// 2: returns the largest singular value of A, max(svd(A)) /// PositiveInfinity: returns max(sum(abs(A), 2)), the largest value of the sums along the rows /// /// /// Array of same type as input array A public static ILRetArray< double > norm(ILInArray< complex > A, double degree = 2) { using (ILScope.Enter(A)) { if (Object.Equals(A, null) || !A.IsMatrix) throw new ILArgumentSizeException("input array must be matrix or vector."); if (A.IsEmpty) return new ILRetArray< double>(ILSize.Scalar1_1); else if (A.IsVector) { if (degree == Double.PositiveInfinity) { return max(abs(A)); } else if (degree == Double.NegativeInfinity) { return min(abs(A)); } else { if (degree == 0.0) return array< double>( ( double)Double.PositiveInfinity , 1, 1); return pow(sum(pow(abs(A), ( double)degree)), ( double)(1.0 / degree)); } } else { if (degree == 1.0) { return max(sum(abs(A))); } else if (degree == 2.0) { return max(svd(A)); } else if (degree == Double.PositiveInfinity) { return max(sum(abs(A), 2)); } else if (degree == 0.0) { return sqrt(sum(real(diag(multiply(A, A[1]))))); } else { throw new ILArgumentException("invalid argument 'degree' supplied. valid for matrices: 0,1,2,Double.PositiveInfinity"); } } } } #endregion HYCALPER AUTO GENERATED CODE } }