20 private ICollection<IElement> elements;
21 private string[] columnNames =
null;
22 private readonly
int rows;
23 private readonly
int columns;
33 this.rows =
Values.GetLength(0);
34 this.columns =
Values.GetLength(1);
46 for (i = 0; i < c; i++)
48 for (j = 0; j < d; j++)
52 this.values = Values2;
54 this.rows =
Values.GetLength(0);
55 this.columns =
Values.GetLength(1);
79 if (this.values is
null)
90 while (!(Loop is
null))
92 for (i = Loop.
Start, c = Loop.
Pos; i < c; i++)
95 if (x >= this.columns)
110 if (x >= this.columns)
137 if (this.elements is
null)
142 for (y = 0; y < this.rows; y++)
144 for (x = 0; x < this.columns; x++)
145 v[i++] = this.values[y, x];
151 return this.elements;
170 get => this.columnNames;
173 if (!(value is
null) && value.Length !=
this.columns)
174 throw new ArgumentException(
"Number of columns does not match actual number of columns.", nameof(value));
176 this.columnNames = value;
195 if (!(this.columnNames is
null))
197 int i, c = this.columnNames.Length;
199 for (i = 0; i < c; i++)
201 if (
string.Compare(this.columnNames[i], ColumnName,
true) == 0)
206 throw new ArgumentException(
"No column named " + ColumnName +
" found.");
214 StringBuilder sb =
null;
218 for (y = 0; y < this.rows; y++)
221 sb =
new StringBuilder(
"[[");
223 sb.Append(
",\r\n [");
226 for (x = 0; x < this.columns; x++)
240 sb =
new StringBuilder(
"[[]]");
244 return sb.ToString();
254 if (this.associatedMatrixSpace is
null)
255 this.associatedMatrixSpace =
new ObjectMatrices(this.rows, this.columns);
257 return this.associatedMatrixSpace;
282 v =
new IElement[this.rows, this.columns];
284 for (y = 0; y < this.rows; y++)
286 for (x = 0; x < this.columns; x++)
294 if (Matrix.Columns !=
this.rows)
297 IElement[,] Values2 = Matrix.MatrixElements;
299 v =
new IElement[Matrix.Rows, this.columns];
301 for (y = 0; y < Matrix.Rows; y++)
303 for (x = 0; x < this.columns; x++)
307 for (z = 0; z < this.rows; z++)
313 n = Operators.Arithmetics.Add.EvaluateAddition(n,
342 v =
new IElement[this.rows, this.columns];
344 for (y = 0; y < this.rows; y++)
346 for (x = 0; x < this.columns; x++)
354 if (this.columns != Matrix.Rows)
357 IElement[,] Values2 = Matrix.MatrixElements;
359 v =
new IElement[this.rows, Matrix.Columns];
361 for (y = 0; y < this.rows; y++)
363 for (x = 0; x < Matrix.Columns; x++)
367 for (z = 0; z < this.columns; z++)
373 n = Operators.Arithmetics.Add.EvaluateAddition(n,
394 if (this.rows != this.columns)
398 int c2 = this.columns << 1;
403 for (y = 0; y < this.rows; y++)
405 for (x = 0; x < this.columns; x++)
407 v[y, x] = E =
Values[y, x];
411 v[y, x + this.columns] = (x == y ? E2.One : E2.Zero);
415 if (
Reduce(v,
true,
true, out
_) < 0)
420 for (y = 0; y < this.rows; y++)
422 for (x = 0; x < this.columns; x++)
423 v2[y, x] = v[y, x + this.columns];
443 Rank =
Reduce(M, Eliminate, BreakIfZero, out Factor);
461 int Rows = Matrix.GetLength(0);
462 int Columns = Matrix.GetLength(1);
471 for (x = 0; x < MinCount; x++)
477 if (a.Equals(a.
Zero))
480 for (y = x + 1; y <
Rows; y++)
486 if (!b.Equals(b.
Zero))
499 Matrix[x, u] = Matrix[z, u];
531 for (y = Eliminate ? 0 : x + 1; y <
Rows; y++)
539 if (!a.Equals(a.
Zero))
577 v =
new IElement[this.rows, this.columns];
579 for (y = 0; y < this.rows; y++)
581 for (x = 0; x < this.columns; x++)
582 v[y, x] = Operators.Arithmetics.Add.EvaluateAddition(
Element,
this.values[y, x],
null);
589 if (this.columns != Matrix.Columns ||
this.rows != Matrix.Rows)
592 IElement[,] Values2 = Matrix.MatrixElements;
594 v =
new IElement[this.rows, this.columns];
595 for (y = 0; y < this.rows; y++)
597 for (x = 0; x < this.columns; x++)
598 v[y, x] = Operators.Arithmetics.Add.EvaluateAddition(
Values[y, x], Values2[y, x],
null);
614 IElement[,] v =
new IElement[this.rows, this.columns];
617 for (y = 0; y < this.rows; y++)
619 for (x = 0; x < this.columns; x++)
620 v[y, x] = Operators.Arithmetics.Negate.EvaluateNegation(
Values[y, x]);
636 if (this.columns != Matrix.Columns ||
this.rows != Matrix.Rows)
640 IElement[,] V2 = Matrix.MatrixElements;
643 for (y = 0; y < this.rows; y++)
645 for (x = 0; x < this.columns; x++)
647 if (V1[y, x] != V2[y, x])
664 for (y = 0; y < this.rows; y++)
666 for (x = 0; x < this.columns; x++)
710 get {
throw new ScriptException(
"Zero element not defined for generic object matrices."); }
725 if (!(this.rowVectors is
null))
726 return this.rowVectors;
731 if (!(this.values is
null))
733 for (y = 0; y < this.rows; y++)
737 for (x = 0; x < this.columns; x++)
738 Row.
Add(
this.values[y, x]);
740 Rows.Add(Operators.Vectors.VectorDefinition.Encapsulate(Row,
false,
null));
755 if (x >= this.columns)
757 Rows.Add(Operators.Vectors.VectorDefinition.Encapsulate(Row,
false,
null));
764 Rows.Add(Operators.Vectors.VectorDefinition.Encapsulate(Row,
false,
null));
767 this.rowVectors =
Rows;
784 for (y = 0; y < this.rows; y++)
786 for (x = 0; x < this.columns; x++)
809 if (Index < 0 || Index >= this.rows)
813 IElement[] V =
new IElement[this.columns];
816 for (i = 0; i < this.columns; i++)
819 return Operators.Vectors.VectorDefinition.
Encapsulate(V,
false,
null);
829 if (Index < 0 || Index >= this.rows)
835 if (V.Dimension !=
this.columns)
839 this.elements =
null;
855 if (Column < 0 || Column >= this.columns || Row < 0 || Row >= this.rows)
858 return this.
Values[Row, Column];
869 if (Column < 0 || Column >= this.columns || Row < 0 || Row >= this.rows)
873 this.elements =
null;
875 M[Row, Column] = Value;
885 if (Row < 0 || Row >= this.rows)
889 IElement[] V =
new IElement[this.columns];
892 for (i = 0; i < this.columns; i++)
895 return Operators.Vectors.VectorDefinition.
Encapsulate(V,
false,
null);
905 if (Column < 0 || Column >= this.columns)
909 IElement[] V =
new IElement[this.rows];
912 for (i = 0; i < this.rows; i++)
915 return Operators.Vectors.VectorDefinition.
Encapsulate(V,
false,
null);
925 if (Row < 0 || Row >= this.rows)
929 throw new ScriptException(
"Vector dimension does not match number of columns");
932 this.elements =
null;
935 foreach (
IElement E
in Vector.VectorElements)
946 if (Column < 0 || Column >= this.columns)
950 throw new ScriptException(
"Vector dimension does not match number of rows");
953 this.elements =
null;
956 foreach (
IElement E
in Vector.VectorElements)
970 return this.
TryFind(Element, 0, 0, out Column, out Row);
998 public bool TryFind(
object Element,
int FromColumn,
int FromRow, out
int Column, out
int Row)
1003 while (FromRow < this.rows)
1005 while (FromColumn < this.columns)
1007 Item =
Values[FromRow, FromColumn];
1011 Column = FromColumn;
1040 return this.
TryFindLast(Element, this.columns - 1, this.rows - 1, out Column, out Row);
1073 while (FromRow >= 0)
1075 while (FromColumn >= 0)
1077 Item =
Values[FromRow, FromColumn];
1081 Column = FromColumn;
1090 FromColumn = this.columns - 1;
Node referencing a chunk in a ChunkedList<T>
ChunkNode< T > Next
Next chunk
int Pos
Index after the last element in chunk.
int Start
Index of first element in chunk.
A chunked list is a linked list of chunks of objects of type T .
void Add(T Item)
Adds an item to the collection.
Base class for all types of elements.
virtual bool IsScalar
If the element represents a scalar value.
Element()
Base class for all types of elements.
Base class for all types of ring elements.
Base class for script exceptions.
Class managing a script expression.
static IElement Encapsulate(object Value)
Encapsulates an object.
static string ToExpressionString(object Value)
Converts an object to a string, that can be parsed as part of an expression.
Base class for all nodes in a parsed script tree.
Pseudo-ring of Object-valued matrices.
bool TryFindLast(object Element, int FromColumn, int FromRow, out int Column, out int Row)
Tries to find the last element in the matrix, continuing search from a given position in the matrix....
IVector GetColumn(int Column)
Gets a column vector from the matrix.
override string ToString()
IElement GetElement(int Index)
Gets an element of the vector.
IMatrix ConjugateTranspose()
Returns a conjugate transposed matrix.
void SetElement(int Column, int Row, IElement Value)
Sets an element in the matrix.
override IRing AssociatedRing
Associated Ring.
override IRingElement MultiplyRight(IRingElement Element)
Tries to multiply an element to the current element, from the right.
bool HasColumnNames
If the matrix has column names defined.
ObjectMatrix(IElement[,] Values)
Object-valued matrix.
override IAbelianGroupElement Add(IAbelianGroupElement Element)
Tries to add an element to the current element.
override IElement Encapsulate(ICollection< IElement > Elements, ScriptNode Node)
Encapsulates a set of elements into a similar structure as that provided by the current element.
bool TryFind(object Element, int FromColumn, int FromRow, out int Column, out int Row)
Tries to find an element in the matrix, continuing search from a given position in the matrix....
IElement GetElement(int Column, int Row)
Gets an element of the matrix.
override object AssociatedObjectValue
Associated object value.
ICollection< IElement > Elements
Matrix elements.
void SetColumn(int Column, IVector Vector)
Gets a column vector from the matrix.
IMatrix Reduce(bool Eliminate, bool BreakIfZero, out int Rank, out ICommutativeRingWithIdentityElement Factor)
Reduces a matrix.
IVector GetRow(int Row)
Gets a row vector from the matrix.
static int Reduce(IElement[,] Matrix, bool Eliminate, bool BreakIfZero, out ICommutativeRingWithIdentityElement Factor)
Reduces a matrix.
ObjectMatrix(object[,] Values)
Object-valued matrix.
bool TryFindLast(IElement Element, out int Column, out int Row)
Tries to find the last element in the matrix. Search is done, right to left, bottom to top.
override IRingElement Invert()
Inverts the element, if possible.
IElement[,] MatrixElements
Matrix elements
override int GetHashCode()
Calculates a hash code of the element.
ObjectMatrix(int Rows, int Columns, ICollection< IElement > Elements)
Object-valued vector.
bool TryFindLast(IElement Element, int FromColumn, int FromRow, out int Column, out int Row)
Tries to find the last element in the matrix, continuing search from a given position in the matrix....
override IRingElement MultiplyLeft(IRingElement Element)
Tries to multiply an element to the current element, from the left.
override IElement Encapsulate(ChunkedList< IElement > Elements, ScriptNode Node)
Encapsulates a set of elements into a similar structure as that provided by the current element.
override IAbelianGroupElement Zero
Returns the zero element of the group.
int Columns
Number of columns.
void SetElement(int Index, IElement Value)
Sets an element in the vector.
bool TryFind(IElement Element, int FromColumn, int FromRow, out int Column, out int Row)
Tries to find an element in the matrix, continuing search from a given position in the matrix....
bool TryFind(IElement Element, out int Column, out int Row)
Tries to find an element in the matrix. Search is done, left to right, top to bottom.
IElement[,] Values
Matrix element values.
ICollection< IElement > VectorElements
Vector of row vectors.
override bool Equals(object obj)
Compares the element to another.
override ICollection< IElement > ChildElements
An enumeration of child elements. If the element is a scalar, this property will return null.
string[] ColumnNames
Contains optional column names.
override IGroupElement Negate()
Negates the element.
override bool IsScalar
If the element represents a scalar value.
int Dimension
Dimension of matrix, if seen as a vector of row vectors.
IMatrix Transpose()
Returns a transposed matrix.
void SetRow(int Row, IVector Vector)
Gets a row vector from the matrix.
static IElement EvaluateDivision(IElement Left, IElement Right, ScriptNode Node)
Divides the right operand from the left one.
static IElement EvaluateMultiplication(IElement Left, IElement Right, ScriptNode Node)
Multiplies two operands.
static IElement EvaluateSubtraction(IElement Left, IElement Right, ScriptNode Node)
Subtracts the right operand from the left one.
static IMatrix Encapsulate(ICollection< IElement > Rows, ScriptNode Node)
Encapsulates the elements of a matrix.
Basic interface for all types of abelian group elements.
IAbelianGroupElement Zero
Returns the zero element of the group.
Basic interface for all types of commutative ring with identity elements.
ICommutativeRingWithIdentityElement One
Returns the identity element of the commutative ring with identity.
Basic interface for all types of elements.
object AssociatedObjectValue
Associated object value.
ICollection< IElement > ChildElements
An enumeration of child elements. If the element is a scalar, this property will return null.
IElement Encapsulate(ChunkedList< IElement > Elements, ScriptNode Node)
Encapsulates a set of elements into a similar structure as that provided by the current element.
Basic interface for all types of group elements.
Basic interface for matrices.
Basic interface for all types of ring elements.
Basic interface for vectors.
int Dimension
Dimension of vector.
Basic interface for all types of rings.