本文整理汇总了C#中System.Matrix.SetRow方法的典型用法代码示例。如果您正苦于以下问题:C# Matrix.SetRow方法的具体用法?C# Matrix.SetRow怎么用?C# Matrix.SetRow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Matrix
的用法示例。
在下文中一共展示了Matrix.SetRow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestMultiply
public void TestMultiply()
{
Matrix m = new Matrix(3, 3);
m.SetRow(0, -1.1F, 2.6F, -7.1F);
m.SetRow(1, 4.6F, -3.7F, 9.1F);
m.SetRow(2, 4.1F, -3.1F, 7.7F);
Matrix result = new Matrix(3, 3);
result.SetRow(0, -3.41F, 8.06F, -22.01F);
result.SetRow(1, 14.26F, -11.47F, 28.21F);
result.SetRow(2, 12.71F, -9.61F, 23.87F);
Assert.IsTrue(Matrix.AreEqual(m * 3.1F, result));
}
示例2: TestInc
public void TestInc()
{
var matrix = new Matrix<double>(5, 5);
double[] row = { 1, 2, 3, 4, 5 };
for (int i = 0; i < 5; i++)
matrix.SetRow(i, row);
matrix.Inc(3, 4, 2.5);
Assert.AreEqual(7.5, matrix[3, 4]);
var matrix1 = new Matrix<double>(5, 5);
for (int i = 0; i < 5; i++)
matrix1.SetRow(i, row);
var matrix2 = new Matrix<double>(5, 5);
for (int i = 0; i < 5; i++)
matrix2.SetRow(i, row);
double[] testrow = { 2, 4, 6, 8, 10 };
matrix1.Inc(matrix2);
Assert.AreEqual(testrow, matrix1.GetRow(2));
var matrix3 = new Matrix<double>(5, 5);
for (int i = 0; i < 5; i++)
matrix3.SetRow(i, row);
matrix3.Inc(1.0);
for (int j = 0; j < 5; j++)
Assert.AreEqual(row[j] + 1, matrix3[1, j]);
var matrix4 = new Matrix<int>(5, 5);
int[] int_row = { 1, 2, 3, 4, 5 };
for (int i = 0; i < 5; i++)
matrix4.SetRow(i, int_row);
Assert.AreEqual(matrix4[1, 2], 3);
matrix4.Inc(1, 2);
Assert.AreEqual(matrix4[1, 2], 4);
}
示例3: TestInc
public void TestInc()
{
var matrix = new Matrix<double>(5, 5);
double[] row = { 1, 2, 3, 4, 5 };
for (int i = 0; i < 5; i++)
matrix.SetRow(i, row);
MatrixUtils.Inc(matrix, 3, 4, 2.5);
Assert.AreEqual(7.5, matrix[3, 4]);
}
示例4: TestFrobeniusNorm
public void TestFrobeniusNorm()
{
var matrix = new Matrix<double>(5, 5);
double[] row = { 1, 2, 3, 4, 5 };
for (int i = 0; i < 5; i++)
matrix.SetRow(i, row);
double result =Math.Sqrt(275.0);
Assert.AreEqual(result,MatrixUtils.FrobeniusNorm(matrix));
}
示例5: TestColumnAverage
[Test()] public void TestColumnAverage()
{
var matrix = new Matrix<float>(5, 5);
float[] row = { 1, 2, 3, 4, 5 };
for (int i = 0; i < 5; i++)
matrix.SetRow(i, row);
Assert.AreEqual(2.0, matrix.ColumnAverage(1));
Assert.AreEqual(5.0, matrix.ColumnAverage(4));
}
示例6: TestGetSetRow
public void TestGetSetRow()
{
var matrix = new Matrix<int>(5, 5);
int[] row = { 1, 2, 3, 4, 5 };
matrix.SetRow(3, row);
Assert.AreEqual(row, matrix.GetRow(3));
Assert.AreEqual(0, matrix[0, 0]);
Assert.AreEqual(1, matrix[3, 0]);
}
示例7: TestColumnAverage
public void TestColumnAverage()
{
var matrix = new Matrix<double>(5, 5);
double[] row = { 1, 2, 3, 4, 5 };
for (int i = 0; i < 5; i++)
matrix.SetRow(i, row);
Assert.AreEqual(2.0, MatrixUtils.ColumnAverage(matrix, 1));
Assert.AreEqual(5.0, MatrixUtils.ColumnAverage(matrix, 4));
}
示例8: TestSetColumnToOneValue
public void TestSetColumnToOneValue()
{
var matrix = new Matrix<int>(5, 5);
int[] row = { 1, 2, 3, 4, 5 };
for (int i = 0; i < 5; i++)
matrix.SetRow(i, row);
matrix.SetColumnToOneValue(3, 10);
int[] testcolumn = { 10, 10, 10, 10, 10 };
Assert.AreEqual(testcolumn, matrix.GetColumn(3));
}
示例9: TestSubtract
public void TestSubtract()
{
Matrix m1 = new Matrix(3, 3);
m1.SetColumn(0, 2.2F, -6.1F, -7.6F);
m1.SetColumn(1, -3.4F, 7.2F, 8.7F);
m1.SetColumn(2, 1.6F, 5.5F, -9.8F);
Matrix m2 = new Matrix(3, 3);
m2.SetRow(0, -1.1F, 2.6F, -7.1F);
m2.SetRow(1, 4.6F, -3.7F, 9.1F);
m2.SetRow(2, 4.1F, -3.1F, 7.7F);
Matrix result = new Matrix(3, 3);
result.SetRow(0, 3.3F, -6F, 8.7F);
result.SetRow(1, -10.7F, 10.9F, -3.6F);
result.SetRow(2, -11.7F, 11.8F, -17.5F);
Assert.IsTrue(Matrix.AreEqual(m1 - m2, result));
}
示例10: TestMultiply
[Test()] public void TestMultiply()
{
var matrix = new Matrix<float>(5, 5);
float[] row = { 1, 2, 3, 4, 5 };
for (int i = 0; i < 5; i++)
matrix.SetRow(i, row);
matrix.Multiply(2.5f);
float[] testrow = { 2.5f, 5f, 7.5f, 10f, 12.5f };
Assert.AreEqual(testrow, matrix.GetRow(3));
}
示例11: TestAdd
public void TestAdd()
{
Matrix m1 = new Matrix(3, 3);
m1.SetColumn(0, 2.2F, -6.1F, -7.6F);
m1.SetColumn(1, -3.4F, 7.2F, 8.7F);
m1.SetColumn(2, 1.6F, 5.5F, -9.8F);
Matrix m2 = new Matrix(3, 3);
m2.SetRow(0, -1.1F, 2.6F, -7.1F);
m2.SetRow(1, 4.6F, -3.7F, 9.1F);
m2.SetRow(2, 4.1F, -3.1F, 7.7F);
Matrix result = new Matrix(3, 3);
result.SetRow(0, 1.1F, -0.8F, -5.5F);
result.SetRow(1, -1.5F, 3.5F, 14.6F);
result.SetRow(2, -3.5F, 5.6F, -2.1F);
Assert.IsTrue(Matrix.AreEqual(m1 + m2, result));
}
示例12: TestConstructor
public void TestConstructor()
{
var m = new Matrix(3, 3);
m.SetColumn(0, 0, 0, 0);
m.SetColumn(1, 0, 0, 0);
m.SetColumn(2, 0, 0, 0);
Assert.IsTrue(Matrix.AreEqual(m, new Matrix(3, 3)));
m.SetRow(0, 1, 2, 3);
m.SetRow(1, 4, 5, 6);
m.SetRow(2, 7, 8, 9);
Assert.IsTrue(Matrix.AreEqual(m, new Matrix(new float[,] {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}})));
Assert.IsTrue(Matrix.AreEqual(m, new Matrix(new Matrix(new float[,] {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}))));
try
{
new Matrix(0, 0);
Assert.Fail("Expected an exception");
}
catch (ArgumentException) {}
try
{
new Matrix(new Matrix(4, -5));
Assert.Fail("Expected an exception");
}
catch (ArgumentException) { }
try
{
new Matrix((Matrix) null);
Assert.Fail("Expected an exception");
}
catch (ArgumentNullException) {}
try
{
new Matrix((float[,]) null);
Assert.Fail("Expected an exception");
}
catch (ArgumentNullException) {}
}
示例13: TestInc2
public void TestInc2()
{
var matrix1 = new Matrix<double>(5, 5);
double[] row = { 1, 2, 3, 4, 5 };
for (int i = 0; i < 5; i++)
matrix1.SetRow(i, row);
var matrix2 = new Matrix<double>(5, 5);
for (int i = 0; i < 5; i++)
matrix2.SetRow(i, row);
double[] testrow = {2, 4, 6, 8, 10};
MatrixUtils.Inc(matrix1, matrix2);
Assert.AreEqual(testrow, matrix1.GetRow(2));
}
示例14: TestRowSetter
public void TestRowSetter()
{
Matrix m = new Matrix(1, 3);
m.SetRow(0, 1F, 2F, 3F);
try
{
//not enough.
m.SetRow(0, 1F, 2F);
Assert.Fail("Expected an exception");
}
catch (ArgumentException) {}
}
示例15: TestInverse4
public void TestInverse4()
{
// test identity inverse
var m = Matrix.GetIdentity(4);
Assert.IsTrue(Matrix.AreEqual(m.Invert(), new Matrix(new float[,] {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}})));
// test a known inverse
m = new Matrix(new[,]
{
{0.100f, 0.200f, 0.300f, 1.300f},
{-0.400f, 0.500f, 0.600f, 1.400f},
{0.700f, 0.800f, 0.900f, 1.500f},
{1.000f, 1.100f, 1.200f, -1.600f}
});
var r = new Matrix(new[,]
{
{0.62500f, -1.25000f, 0.62500f, 0.00000f},
{-18.12500f, 2.50000f, 9.37500f, -3.75000f},
{15.8854167f, -1.25000f, -8.4895833f, 3.854167f},
{-0.15625f, 0.00000f, 0.46875f, -0.31250f}
});
Assert.IsTrue(Matrix.AreEqual(m.Invert(), r, _tolerance));
// test inverse multiplied against original is the identity
m.SetRow(0, -1.1F, 2.6F, -7.1F, 2.2F);
m.SetRow(1, 4.6F, -3.7F, 9.1F, 6.9F);
m.SetRow(2, 4.1F, -3.1F, 7.7F, 7.1F);
m.SetRow(3, -9.9F, 0.2F, 4.3F, 5.5F);
Assert.IsTrue(Matrix.AreEqual(m*m.Invert(), Matrix.GetIdentity(4), _tolerance));
Assert.IsTrue(Matrix.AreEqual(m.Invert()*m, Matrix.GetIdentity(4), _tolerance));
// test non-invertible
m.SetRow(0, 1, 0, 0, 0);
m.SetRow(1, 0, 1, 0, 0);
m.SetRow(2, 0, 0, 1, 0);
m.SetRow(3, 0, 0, 5, 0);
try
{
m.Invert();
Assert.Fail("Expected an exception");
}
catch (ArgumentException) {}
}