Math.NET Numerics
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

88 lines
2.7 KiB

using System;
using MathNet.Numerics.Properties;
namespace MathNet.Numerics.LinearAlgebra.Storage
{
// ReSharper disable UnusedParameter.Global
public partial class MatrixStorage<T>
{
protected void ValidateRange(int row, int column)
{
if (row < 0 || row >= RowCount)
{
throw new ArgumentOutOfRangeException("row");
}
if (column < 0 || column >= ColumnCount)
{
throw new ArgumentOutOfRangeException("column");
}
}
protected void ValidateSubMatrixRange(MatrixStorage<T> target,
int sourceRowIndex, int targetRowIndex, int rowCount,
int sourceColumnIndex, int targetColumnIndex, int columnCount)
{
if (rowCount < 1)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "rowCount");
}
if (columnCount < 1)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "columnCount");
}
// Verify Source
if (sourceRowIndex >= RowCount || sourceRowIndex < 0)
{
throw new ArgumentOutOfRangeException("sourceRowIndex");
}
if (sourceColumnIndex >= ColumnCount || sourceColumnIndex < 0)
{
throw new ArgumentOutOfRangeException("sourceColumnIndex");
}
var sourceRowMax = sourceRowIndex + rowCount;
var sourceColumnMax = sourceColumnIndex + columnCount;
if (sourceRowMax > RowCount)
{
throw new ArgumentOutOfRangeException("rowCount");
}
if (sourceColumnMax > ColumnCount)
{
throw new ArgumentOutOfRangeException("columnCount");
}
// Verify Target
if (targetRowIndex >= target.RowCount || targetRowIndex < 0)
{
throw new ArgumentOutOfRangeException("targetRowIndex");
}
if (targetColumnIndex >= target.ColumnCount || targetColumnIndex < 0)
{
throw new ArgumentOutOfRangeException("targetColumnIndex");
}
var targetRowMax = targetRowIndex + rowCount;
var targetColumnMax = targetColumnIndex + columnCount;
if (targetRowMax > target.RowCount)
{
throw new ArgumentOutOfRangeException("rowCount");
}
if (targetColumnMax > target.ColumnCount)
{
throw new ArgumentOutOfRangeException("columnCount");
}
}
}
// ReSharper restore UnusedParameter.Global
}