AngouriMath
Public Member Functions | List of all members
AngouriMath.Core.MatrixBuilder Class Reference

Use this class for solvers and other places when a matrix needs to be built without recreating an instance multiple times. More...

Public Member Functions

 MatrixBuilder (int columnCount)
 Creates a builder with the given number of column and no rows. More...
 
 MatrixBuilder (List< List< Entity >>? alreadyHas, int columnCount)
 Creates a builder with the given number of column and no rows. More...
 
void Add (List< Entity > row)
 Adds a row to the builder. More...
 
void Add (IEnumerable< Entity > row)
 Adds a row to the builder. More...
 
Matrix ToMatrix ()
 Builds itself into a Matrix. More...
 

Detailed Description

Use this class for solvers and other places when a matrix needs to be built without recreating an instance multiple times.

It builds an instance of Matrix. It enables to build a tensor row-by-row.

using System;
var mb = new MatrixBuilder(3);
Console.WriteLine(mb.ToMatrix() is null);
Console.WriteLine("-------------------------");
mb.Add(new Entity[] { 1, 2, 3 } );
mb.Add(new Entity[] { "x", "sqrt(y)", 5 } );
Console.WriteLine(mb.ToMatrix().ToString(multilineFormat: true));
Console.WriteLine("-------------------------");
mb.Add(new Entity[] { 1 } ); // throws

Prints

<h2>True
</h2>
Matrix[2 x 3]
1 2 3
<h2>x sqrt(y) 5
</h2>

Constructor & Destructor Documentation

◆ MatrixBuilder() [1/2]

AngouriMath.Core.MatrixBuilder.MatrixBuilder ( int  columnCount)
inline

Creates a builder with the given number of column and no rows.

Parameters
columnCountThe number of columns the tensor will have (you cannot change it after creation).

◆ MatrixBuilder() [2/2]

AngouriMath.Core.MatrixBuilder.MatrixBuilder ( List< List< Entity >>?  alreadyHas,
int  columnCount 
)
inline

Creates a builder with the given number of column and no rows.

Parameters
alreadyHasThe list of rows to put in the builder. All lists in this list must have the same length as columnCount.
columnCountThe number of columns the tensor will have (you cannot change it after creation).

Member Function Documentation

◆ Add() [1/2]

void AngouriMath.Core.MatrixBuilder.Add ( List< Entity row)
inline

Adds a row to the builder.

Parameters
rowA row to add. Make sure it has the same length as columnCount.
Exceptions
InvalidMatrixOperationExceptionIs thrown if the given row has a wrong length.

◆ Add() [2/2]

void AngouriMath.Core.MatrixBuilder.Add ( IEnumerable< Entity row)

Adds a row to the builder.

Parameters
rowA row to add. Make sure it has the same length as columnCount.
Exceptions
InvalidMatrixOperationExceptionIs thrown if the given row has a wrong length.

◆ ToMatrix()

Matrix AngouriMath.Core.MatrixBuilder.ToMatrix ( )
inline

Builds itself into a Matrix.

Returns
An immutable Matrix if there exists at least one row. Null otherwise.

The documentation for this class was generated from the following file: