diff --git a/src/Numerics/LinearAlgebra/Builder.cs b/src/Numerics/LinearAlgebra/Builder.cs index 0a8907e0..e668e7e3 100644 --- a/src/Numerics/LinearAlgebra/Builder.cs +++ b/src/Numerics/LinearAlgebra/Builder.cs @@ -1101,6 +1101,60 @@ namespace MathNet.Numerics.LinearAlgebra /// public abstract Matrix Diagonal(DiagonalMatrixStorage storage); + /// + /// Create a new diagonal matrix with the given number of rows and columns. + /// All cells of the matrix will be initialized to zero. + /// Zero-length matrices are not supported. + /// + public Matrix Diagonal(int rows, int columns) + { + return Diagonal(new DiagonalMatrixStorage(rows, columns)); + } + + /// + /// Create a new diagonal matrix with the given number of rows and columns directly binding to a raw array. + /// The array is assumed to represent the diagonal values and is used directly without copying. + /// Very efficient, but changes to the array and the matrix will affect each other. + /// + /// + public Matrix Diagonal(int rows, int columns, T[] storage) + { + return Diagonal(new DiagonalMatrixStorage(rows, columns, storage)); + } + + /// + /// Create a new diagonal matrix and initialize each diagonal value to the same provided value. + /// + public Matrix Diagonal(int rows, int columns, T value) + { + if (Zero.Equals(value)) return Diagonal(rows, columns); + return Diagonal(DiagonalMatrixStorage.OfInit(rows, columns, i => value)); + } + + /// + /// Create a new diagonal matrix and initialize each diagonal value using the provided init function. + /// + public Matrix Diagonal(int rows, int columns, Func init) + { + return Diagonal(DiagonalMatrixStorage.OfInit(rows, columns, init)); + } + + /// + /// Create a new diagonal identity matrix with a one-diagonal. + /// + public Matrix DiagonalIdentity(int rows, int columns) + { + return Diagonal(DiagonalMatrixStorage.OfInit(rows, columns, i => One)); + } + + /// + /// Create a new diagonal identity matrix with a one-diagonal. + /// + public Matrix DiagonalIdentity(int order) + { + return Diagonal(DiagonalMatrixStorage.OfInit(order, order, i => One)); + } + public abstract IIterationStopCriterium[] IterativeSolverStopCriteria(int maxIterations = 1000); }