/// <summary> /// Creates matrix object with data from nested lists /// </summary> /// <param name="matrix"></param> /// <exception cref="ArgumentException">when matrix list is empty</exception> /// <exception cref="ArgumentNullException">when matrix is null</exception> /// <exception cref="ArgumentException">when matrix's is containing data of different types</exception> public Matrix(IMatrixData[][] matrix) { if (matrix == null) { throw new ArgumentNullException(nameof(matrix)); } if (matrix.GetLength(0) == 0) { throw new ArgumentException("Value cannot be an empty collection.", nameof(matrix)); } this.matrixDataType = matrix[0][0].GetType(); this.defaultMatrixData = (IMatrixData)Activator.CreateInstance(matrixDataType); this.arithmeticsController = defaultMatrixData.GetArithmeticsController(); if (matrix.SelectMany(matrixData => matrixData) .Any(matrixDataType => matrixDataType.GetType() != this.matrixDataType)) { throw new ArgumentException("Inconsistent MatrixData type. all IMatrixData must be of same type"); } this.Width = matrix[0].GetLength(0); this.Height = matrix.GetLength(0); this.matrix = matrix; }