本文整理汇总了C#中SparseCompressedRowMatrixStorage类的典型用法代码示例。如果您正苦于以下问题:C# SparseCompressedRowMatrixStorage类的具体用法?C# SparseCompressedRowMatrixStorage怎么用?C# SparseCompressedRowMatrixStorage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SparseCompressedRowMatrixStorage类属于命名空间,在下文中一共展示了SparseCompressedRowMatrixStorage类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SparseMatrix
/// <summary>
/// Create a new sparse matrix straight from an initialized matrix storage instance.
/// The storage is used directly without copying.
/// Intended for advanced scenarios where you're working directly with
/// storage for performance or interop reasons.
/// </summary>
public SparseMatrix(SparseCompressedRowMatrixStorage<float> storage)
: base(storage)
{
_storage = storage;
}
示例2: Transpose
/// <summary>
/// Returns the transpose of this matrix.
/// </summary>
/// <returns>The transpose of this matrix.</returns>
public override Matrix<float> Transpose()
{
var rowPointers = _storage.RowPointers;
var columnIndices = _storage.ColumnIndices;
var values = _storage.Values;
var ret = new SparseCompressedRowMatrixStorage<float>(ColumnCount, RowCount)
{
ColumnIndices = new int[_storage.ValueCount],
Values = new float[_storage.ValueCount]
};
// Do an 'inverse' CopyTo iterate over the rows
for (var i = 0; i < RowCount; i++)
{
// Get the begin / end index for the current row
var startIndex = rowPointers[i];
var endIndex = rowPointers[i + 1];
// Get the values for the current row
if (startIndex == endIndex)
{
// Begin and end are equal. There are no values in the row, Move to the next row
continue;
}
for (var j = startIndex; j < endIndex; j++)
{
ret.At(columnIndices[j], i, values[j]);
}
}
return new SparseMatrix(ret);
}
示例3: SparseMatrix
/// <summary>
/// Create a new sparse matrix straight from an initialized matrix storage instance.
/// The storage is used directly without copying.
/// Intended for advanced scenarios where you're working directly with
/// storage for performance or interop reasons.
/// </summary>
public SparseMatrix(SparseCompressedRowMatrixStorage<Complex32> storage)
: base(storage)
{
_storage = storage;
}
示例4: Transpose
/// <summary>
/// Returns the transpose of this matrix.
/// </summary>
/// <returns>The transpose of this matrix.</returns>
public override Matrix<Complex32> Transpose()
{
var rowPointers = _storage.RowPointers;
var columnIndices = _storage.ColumnIndices;
var values = _storage.Values;
var ret = new SparseCompressedRowMatrixStorage<Complex32>(ColumnCount, RowCount)
{
ColumnIndices = new int[_storage.ValueCount],
Values = new Complex32[_storage.ValueCount]
};
// Do an 'inverse' CopyTo iterate over the rows
for (var i = 0; i < RowCount; i++)
{
var startIndex = rowPointers[i];
var endIndex = rowPointers[i + 1];
if (startIndex == endIndex)
{
continue;
}
for (var j = startIndex; j < endIndex; j++)
{
ret.At(columnIndices[j], i, values[j]);
}
}
return new SparseMatrix(ret);
}
示例5: Identity
/// <summary>
/// Initializes a square <see cref="SparseMatrix"/> with all zero's except for ones on the diagonal.
/// </summary>
/// <param name="order">the size of the square matrix.</param>
/// <returns>Identity <c>SparseMatrix</c></returns>
/// <exception cref="ArgumentException">
/// If <paramref name="order"/> is less than one.
/// </exception>
public static SparseMatrix Identity(int order)
{
var mStorage = new SparseCompressedRowMatrixStorage<float>(order, order, 0f)
{
ValueCount = order,
Values = new float[order],
ColumnIndices = new int[order]
};
for (var i = 0; i < order; i++)
{
mStorage.Values[i] = 1f;
mStorage.ColumnIndices[i] = i;
mStorage.RowPointers[i] = i;
}
return new SparseMatrix(mStorage);
}
示例6: Identity
/// <summary>
/// Initializes a square <see cref="SparseMatrix"/> with all zero's except for ones on the diagonal.
/// </summary>
/// <param name="order">the size of the square matrix.</param>
/// <returns>Identity <c>SparseMatrix</c></returns>
/// <exception cref="ArgumentException">
/// If <paramref name="order"/> is less than one.
/// </exception>
public static SparseMatrix Identity(int order)
{
var m = new SparseCompressedRowMatrixStorage<double>(order, order, 0d)
{
ValueCount = order,
Values = new double[order],
ColumnIndices = new int[order]
};
for (var i = 0; i < order; i++)
{
m.Values[i] = 1d;
m.ColumnIndices[i] = i;
m.RowPointers[i] = i;
}
return new SparseMatrix(m);
}
示例7: SparseMatrix
internal SparseMatrix(SparseCompressedRowMatrixStorage<double> storage)
: base(storage)
{
_storage = storage;
}
示例8: SubMatrix
/// <summary>
/// Creates a matrix that contains the values from the requested sub-matrix.
/// </summary>
/// <param name="rowIndex">The row to start copying from.</param>
/// <param name="rowCount">The number of rows to copy. Must be positive.</param>
/// <param name="columnIndex">The column to start copying from.</param>
/// <param name="columnCount">The number of columns to copy. Must be positive.</param>
/// <returns>The requested sub-matrix.</returns>
/// <exception cref="ArgumentOutOfRangeException">If: <list><item><paramref name="rowIndex"/> is
/// negative, or greater than or equal to the number of rows.</item>
/// <item><paramref name="columnIndex"/> is negative, or greater than or equal to the number
/// of columns.</item>
/// <item><c>(columnIndex + columnLength) >= Columns</c></item>
/// <item><c>(rowIndex + rowLength) >= Rows</c></item></list></exception>
/// <exception cref="ArgumentException">If <paramref name="rowCount"/> or <paramref name="columnCount"/>
/// is not positive.</exception>
public override Matrix<float> SubMatrix(int rowIndex, int rowCount, int columnIndex, int columnCount)
{
// TODO: if rowIndex == columnIndex, use a diagonal matrix instead of a sparse one
var storage = new SparseCompressedRowMatrixStorage<float>(rowCount, columnCount, 0f);
_storage.CopySubMatrixTo(storage, rowIndex, 0, rowCount, columnIndex, 0, columnCount, true);
return new SparseMatrix(storage);
}
示例9: Identity
/// <summary>
/// Initializes a square <see cref="SparseMatrix"/> with all zero's except for ones on the diagonal.
/// </summary>
/// <param name="order">the size of the square matrix.</param>
/// <returns>Identity <c>SparseMatrix</c></returns>
/// <exception cref="ArgumentException">
/// If <paramref name="order"/> is less than one.
/// </exception>
public static SparseMatrix Identity(int order)
{
var storage = new SparseCompressedRowMatrixStorage<Complex32>(order, order)
{
Values = new Complex32[order],
ColumnIndices = new int[order]
};
for (var i = 0; i < order; i++)
{
storage.Values[i] = 1f;
storage.ColumnIndices[i] = i;
storage.RowPointers[i] = i;
}
storage.RowPointers[order] = order;
return new SparseMatrix(storage);
}