public virtual Vector this[int i, VectorType t]
{
get
{
var dim = t == VectorType.Row ? Rows : Cols;
if (i >= dim || i < 0)
throw new IndexOutOfRangeException();
if (t == VectorType.Row)
{
if (_asTransposeRef)
return new Vector(_matrix, i);
else
return new Vector(_matrix[i].ToArray());
}
else
{
if (_asTransposeRef)
return new Vector(_matrix, i, true);
else
{
double[] cols = new double[Rows];
for (int j = 0; j < Rows; j++) cols[j] = _matrix[j][i];
return new Vector(cols);
};
}
}
set
{
if (_asTransposeRef)
throw new InvalidOperationException("Cannot modify matrix in read-only transpose mode!");
var dim1 = t == VectorType.Row ? Rows : Cols;
var dim2 = t == VectorType.Row ? Cols : Rows;
if (i >= dim1 || i < 0)
throw new IndexOutOfRangeException();
if (value.Length > dim2)
throw new InvalidOperationException(string.Format("Vector has lenght larger then {0}", dim2));
if (t == VectorType.Row)
{
for (int k = 0; k < Cols; k++)
_matrix[i][k] = value[k];
}
else
{
for (int k = 0; k < Rows; k++)
_matrix[k][i] = value[k];
}
}
}