public void Setup() { _matrix = BuildMatrix.RandomInt(1024, 1024, 0, 20); _matrixByte = BuildMatrix.RandomByte(1024, 1024, 0, 20); _matrixFloat = BuildMatrix.RandomFloat(1024, 1024, 0, 20); _matrixDouble = BuildMatrix.RandomDouble(1024, 1024, 0, 20); }
public static void Run() { // initialize matrix with random values. Matrix <double> matrix = BuildMatrix.RandomDouble(3, 3, -10, 10); // display matrix. matrix.Pretty(); // LU decomposition. matrix.GetLowerUpperPermutation(out var lower, out var upper, out var perm); // Gets permutation matrix and C = L + U - E. matrix.GetLowerUpperPermutation(out var matrixC, out var matrixP); // display lower-triangular matrix. Console.WriteLine("lower-triangular matrix"); lower.Pretty(); // display upper-triangular matrix. Console.WriteLine("upper-triangular matrix"); upper.Pretty(); // display permutation matrix. Console.WriteLine("permutation matrix"); perm.Pretty(); // display matrix C Console.WriteLine("matrix C = L + U - E"); matrixC.Pretty(); }
public static string Run() { StringBuilder builder = new StringBuilder(); // initialize random matrix. Matrix <int> matrix = BuildMatrix.RandomInt(4, 4, -10, 10); // gets vector of matrix by row index. Vector <int> arr1 = matrix[0, State.Row]; builder.AppendLine("gets vector by row index: " + arr1); // gets vector of matrix by column index Vector <int> arr2 = matrix[0, State.Column]; builder.AppendLine("gets vector by column index: " + arr2); // gets vector via method Vector <int> arr3 = matrix.GetColumn(1); Vector <int> arr4 = matrix.GetRow(2); builder.AppendLine("gets vector by column index via method: " + arr3); builder.AppendLine("gets vector by row index via method: " + arr4); // assign vector to matrix by column and row. matrix[0, State.Column] = arr3.Array; matrix[1, State.Row] = arr4.Array; builder.AppendLine("matrix after conversion: "); builder.AppendLine(matrix.ToString()); return(builder.ToString()); }
private void btnBuildNetwork_Click(object sender, EventArgs e) { Int16 x = 500, y = 500, z = 500, t = 5; // matrix = new Network.Matrix(y, x, z, t); // Utilities ut = new Utilities(); BuildMatrix bm = new BuildMatrix(); bm.Build_New_Matrix(y, x, z, t, 8, 2);
public async void BinaryReadThrowsUnsupportedTypeException() { var matrix = BuildMatrix.BuildRandom <byte>(15, 12); var html = new TemplateHtml("test"); await html.BinarySaveAsync(matrix); await Assert.ThrowsAsync <NotSupportedTypeException>(() => html.BinaryOpenAsync <char>()); }
public async void BinaryWriteReadByte() { var matrix = BuildMatrix.BuildRandom <byte>(15, 12); var html = new TemplateHtml("test"); await html.BinarySaveAsync(matrix); var resultMatrix = await html.BinaryOpenAsync <byte>(); Assert.Equal(matrix, resultMatrix); }
public void StrassenTest_AssertMustBeEqual() { // Arrange Matrix <int> matrixA = BuildMatrix.RandomInt(1024, 1024, 1, 2); Matrix <int> matrixB = BuildMatrix.RandomInt(1024, 1024, 1, 2); Matrix <int> expected = matrixA * matrixB; // Act var actual = Optimization.MultiplyStrassen(matrixA, matrixB); // Assert Assert.Equal(expected, actual); }
public async Task StrassenParallelTest_AssertMustBeEqual() { // Arrange Matrix <int> matrixA = BuildMatrix.RandomInt(1024, 1024, 1, 2); Matrix <int> matrixB = BuildMatrix.RandomInt(1024, 1024, 1, 2); Matrix <int> expected = matrixA * matrixB; // Act var actual = await Optimization.MultiplyStrassenAsync(matrixA, matrixB); // Assert Assert.Equal(expected, actual); }
public void ReverseSByteTest_CheckMask_AssertMustBeEqual(int m, int n) { // Arrange Matrix <sbyte> actual = BuildMatrix.RandomSByte(m, n); Matrix <sbyte> matrixB = (Matrix <sbyte>)actual.Clone(); var expected = matrixB.GetArray().Reverse(); // Act MatrixConverter.Reverse(actual.GetArray()); // Assert Assert.Equal(expected, actual); }
// Below you can see all ways how to execute routine operations with vector. public static string Run() { StringBuilder builder = new StringBuilder(); // init vector va with fill three value. Vector <int> va = new Vector <int>(5, 3); builder.AppendLine("va = " + va); // init vector vb. Vector <int> vb = new[] { 1, 2, 3, 4, 5 }; builder.AppendLine("vb = " + vb); // add of two vectors. var vc = vb + va; builder.AppendLine("vc = " + vc); // multiply vectors on constant. var vk = 5 * vc; builder.AppendLine("vk = " + vk); // subtract of two vectors. var vd = vk - vc; builder.AppendLine("vd = " + vd); // subtract of two vectors. var ve = vd - vk; builder.AppendLine("ve = " + ve); // multiply vectors on constant. var vg = ve * vc; builder.AppendLine("vg = " + vg); // multiply vector on matrix and vice versa Matrix <int> ma = BuildMatrix.RandomInt(5, 5, -10, 10); var vq = ma * ve; var vt = ve * ma; builder.AppendLine("vq = " + vq); builder.AppendLine("vt = " + vt); return(builder.ToString()); }
public void BuildTest_CreateMatrixByExpressionXMulXPlusY_AssertMustBeEqual() { // Arrange int[] arr = { 1, 2, 3, 4 }; Matrix <int> expected = new[, ] { { 1, 4, 9, 16 }, }; // Act var actual = BuildMatrix.Build(1, 4, (x, y) => x * x, arr); // Assert Assert.Equal(expected, actual); }
/// <summary> /// Gets lower upper permutation with matrix C which calculate by formula: /// <c>C=L+U-E</c> /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public static void GetLowerUpperPermutation <T>(this Matrix <T> matrix, out Matrix <T> matrixC, out Matrix <T> matrixP) where T : unmanaged { int n = matrix.Rows; matrixC = matrix.Clone() as Matrix <T>; if (matrixC is null) { throw new NullReferenceException(); } // load to P identity matrix. matrixP = BuildMatrix.CreateIdentityMatrix <T>(matrix.Rows, matrix.Columns); var comparer = Comparer <T> .Default; for (int i = 0; i < n; i++) { T pivotValue = default; int pivot = -1; for (int j = i; j < n; j++) { if (comparer.Compare(MathGeneric <T> .Abs(matrixC[j, i]), pivotValue) > 0) { pivotValue = MathGeneric <T> .Abs(matrixC[j, i]); pivot = j; } } if (pivot != 0) { matrixP.SwapRows(pivot, i); matrixC.SwapRows(pivot, i); for (int j = i + 1; j < n; j++) { matrixC[j, i] = MathGeneric <T> .Divide(matrixC[j, i], matrixC[i, i]); for (int k = i + 1; k < n; k++) { matrixC[j, k] = MathUnsafe <T> .Sub(matrixC[j, k], MathUnsafe <T> .Mul(matrixC[j, i], matrix[i, k])); } } } } }
/// <summary> /// Raises a matrix to a power. /// </summary> /// <param name="matrix">the matrix</param> /// <param name="degree">the degree</param> /// <typeparam name="T">unmanaged type</typeparam> /// <returns>Pow</returns> /// <exception cref="MatrixDotNetException"></exception> public static Matrix <T> Pow <T>(this Matrix <T> matrix, uint degree) where T : unmanaged { if (degree == 0) { return(BuildMatrix.CreateIdentityMatrix <T>(matrix.Rows, matrix.Columns)); } if ((degree & 1) == 1) { return(matrix.Pow(degree - 1) * matrix); } var t = matrix.Pow(degree >> 1); return(t * t); }
public static string Run() { StringBuilder builder = new StringBuilder(); // initialize matrix with random values. Matrix <double> matrix = BuildMatrix.RandomDouble(5, 5, -10, 10); builder.AppendLine(matrix.ToString()); // LU decomposition. matrix.GetLowerUpper(out var lower, out var upper); Console.WriteLine("lower-triangular matrix"); lower.Pretty(); Console.WriteLine("upper-triangular matrix"); upper.Pretty(); Console.WriteLine("A = LU"); Console.WriteLine(lower * upper); return(builder.ToString()); }
public void Setup() { _matrix1 = BuildMatrix.RandomInt(1024, 1024, 1, 123); }
public IEnumerator <object[]> GetEnumerator() { yield return(new object[] { BuildMatrix.RandomInt(4, 4), new[] { 1, 2, 3, 4, 5 } }); yield return(new object[] { BuildMatrix.RandomInt(4, 4), new[] { 1, 2, 3 } }); }
public void Setup() { _matrix1 = BuildMatrix.RandomDouble(Size, Size, 1, 123); _matrix2 = BuildMatrix.RandomDouble(Size, Size, 1, 123); }
public Matrix <int> RandomGeneric() { return(BuildMatrix.BuildRandom <int>(N, N)); }
public Matrix <int> RandomInt() { return(BuildMatrix.RandomInt(N, N)); }
public void Setup() { _matrix1 = BuildMatrix.RandomInt(1024, 1024, 1, 123); _matrix2 = _matrix1.Clone() as Matrix <int>; }
public void Setup() { _matrix = BuildMatrix.RandomInt(4096, 4096, 1, 123); }
public void Setup() { _matrixShort = BuildMatrix.RandomShort(1024, 1024, 0, 20); _matrixInt = BuildMatrix.RandomInt(1024, 1024, 0, 20); _matrixSByte = BuildMatrix.RandomSByte(1024, 1024, 0, 20); }
public void Setup() { _matrix1 = BuildMatrix.RandomByte(Size, Size, 0, 100); _matrix2 = BuildMatrix.RandomByte(Size, Size, 0, 100); }
public void Setup() { _matrix = BuildMatrix.RandomInt(Size, Size); }
public void Setup() { _matrix = BuildMatrix.RandomByte(1024, 1024); _matrix2 = _matrix.Clone() as Matrix <byte>; }
public void Setup() { _matrixFloat = BuildMatrix.RandomFloat(8, 8, 0, 20); }