本文整理汇总了C#中System.Matrix.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# Matrix.GetEnumerator方法的具体用法?C# Matrix.GetEnumerator怎么用?C# Matrix.GetEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Matrix
的用法示例。
在下文中一共展示了Matrix.GetEnumerator方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Product
public override sealed float Product(Matrix element1, Matrix element2)
{
if((element1.Columns!= element2.Columns) || (element1.Rows!=element2.Rows) )
{
throw new RankException("Matrix have different sizes");
}
double product = 0;
//(from item in element1.GetEnumerator()
// let row = item.A
// let col = item.B
// let val = item.C
// select val * element2[row, col]).Sum();
foreach (var item in element1.GetEnumerator())
{
int row = item.A;
int col = item.B;
double val = item.C;
product += val * element2[row, col];
}
//for (int i = 0; i <element1.Rows; i++)
//{
// product += (float) element1.GetRow(i).DotProduct(element2.GetRow(i));
//}
return (float) product;
}
示例2: Main
static void Main()
{
//var matrix=new Matrix(3,4);
//for (ulong i = 0; i < matrix.RowsCount; i++)
// for (ulong j = 0; j < matrix.ColumnsCount; j++)
// matrix[i, j] = new Random(Convert.ToInt32(i)).NextDouble();
//matrix.Transpose();
//var matrix = new Matrix(4, 4);
//matrix[0, 0] = 2.0;
//matrix[0, 1] = -1.0;
//matrix[0, 2] = 3.0;
//matrix[0, 3] = 2.0;
//matrix[1, 0] = 3.0;
//matrix[1, 1] = 1.0;
//matrix[1, 2] = 7.0;
//matrix[1, 3] = 0.0;
//matrix[2, 0] = -4.0;
//matrix[2, 1] = -1.0;
//matrix[2, 2] = 2.0;
//matrix[2, 3] = 1.0;
//matrix[3, 0] = -6.0;
//matrix[3, 1] = 7.0;
//matrix[3, 2] = 1.0;
//matrix[3, 3] = -1.0;
//var matrix = new Matrix(3, 3);
// //double[,] matrix =new double[3,3];
// matrix[0, 0] = 2.0;
// matrix[0, 1] = 0.0;
// matrix[0, 2] = 3.0;
// matrix[1, 0] = 2.0;
// matrix[1, 1] = 1.0;
// matrix[1, 2] = 5.0;
// matrix[2, 0] = 2.0;
// matrix[2, 1] = 1.0;
// matrix[2, 2] = 4.0;
//// double[,] matrix2=MatrixOld.INV(matrix);
// matrix.Invertible();
// return;
var matrix = new Matrix
(
new double[,]
{
{1,2,0,0},
{4,6,0,0},
{7,3,0,0}
}
);
IEnumerator elements = matrix.GetEnumerator();
double[] data = new double[matrix.RowsCount*matrix.ColumnsCount];
int i = 0;
while (elements.MoveNext())
{
data[i++] = (double)elements.Current;
}
//matrix[0, 0] = 4.0;
//matrix[0, 1] = 3.0;
//matrix[0, 2] = -4.0;
//matrix[0, 3] = 2.0;
//matrix[0, 4] = 2.0;
//matrix[1, 0] = 2.0;
//matrix[1, 1] = -1.0;
//matrix[1, 2] = -3.0;
//matrix[1, 3] = -4.0;
//matrix[1, 4] = 2.0;
//matrix[2, 0] = 3.0;
//matrix[2, 1] = 1.0;
//matrix[2, 2] = 1.0;
//matrix[2, 3] = 2.0;
//matrix[2, 4] = -1.0;
//matrix[3, 0] = 1.0;
//matrix[3, 1] = 2.0;
//matrix[3, 2] = 3.0;
//matrix[3, 3] = 4.0;
//matrix[3, 4] = -1.0;
//matrix[4, 0] = -1.0;
//matrix[4, 1] = 1.0;
//matrix[4, 2] = -1.0;
//matrix[4, 3] = -2.0;
//matrix[4, 4] = 3.0;
/* matrix[0, 0] = 1.0;
matrix[0, 1] = 2.0;
matrix[0, 2] = 0.0;
matrix[0, 3] = 0.0;
//.........这里部分代码省略.........
示例3: GetEnumeratorTest
public void GetEnumeratorTest()
{
IMatrix<int> matrix = new Matrix<int>(10, 10);
int number = 0;
for (int r = 0; r < matrix.Rows; r++)
{
for (int c = 0; c < matrix.Columns; c++)
{
matrix[r, c] = number++;
}
}
number = 0;
foreach (int i in matrix)
{
Assert.AreEqual(number++, i);
}
var en = matrix.GetEnumerator();
number = 0;
while (en.MoveNext())
{
Assert.AreEqual(number++, en.Current);
}
}