numl.Math.LinearAlgebra.Matrix.this C# (CSharp) Method

this() public method

returns col/row vector at index j.
public this ( int i, VectorType t ) : Vector
i int Col/Row.
t VectorType Row or Column.
return Vector
        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];
                }
            }
        }

Same methods

Matrix::this ( bool>.Func f, VectorType t ) : Matrix
Matrix::this ( int i ) : Vector
Matrix::this ( bool>.Func f ) : double
Matrix::this ( IEnumerable slice ) : double
Matrix::this ( int i, int j ) : double