80 lines
2.5 KiB
C#
80 lines
2.5 KiB
C#
using Skeleton.Algebra.FixableObjects;
|
|
using Skeleton.Algebra.ScalarFieldStructure;
|
|
|
|
namespace Skeleton.Algebra;
|
|
|
|
public partial class CategoryOf<TDimension>
|
|
{
|
|
public static partial class OnField<TScalar>
|
|
{
|
|
/// <inheritdoc />
|
|
public class FDiagonalMatrix : FNormalMatrix
|
|
{
|
|
/// <inheritdoc />
|
|
public FDiagonalMatrix()
|
|
{
|
|
U = One;
|
|
D = AsMatrix;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public FDiagonalMatrix(IEnumerable<FVector> es, bool row = true) : base(es, row) =>
|
|
this.PostConstructionFix();
|
|
|
|
/// <inheritdoc />
|
|
public FDiagonalMatrix(params TScalar[] es)
|
|
{
|
|
U = One;
|
|
if (es.Length == FDim)
|
|
for (int i = 1; i <= FDim; i++)
|
|
this[i, i] = es[i - 1];
|
|
else
|
|
for (int i = 1; i <= FDim; i++)
|
|
for (int j = 1; j <= FDim; j++)
|
|
this[i, j] = es[i - 1 + (j - 1) * FDim];
|
|
this.PostConstructionFix();
|
|
}
|
|
internal override bool NeedFix => base.NeedFix || !Property.IsDiagonal;
|
|
internal override void Fix()
|
|
{
|
|
for (int i = 1; i <= Dim; i++)
|
|
{
|
|
for (int j = i + 1; j <= Dim; j++)
|
|
{
|
|
this[i, j] = StaticAccess<TScalar>.AdditionUnit;
|
|
this[j, i] = StaticAccess<TScalar>.AdditionUnit;
|
|
}
|
|
}
|
|
base.Fix();
|
|
}
|
|
|
|
/// <summary>
|
|
/// log of the normal matrix
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public FDiagonalMatrix Log()
|
|
{
|
|
FDiagonalMatrix res = new();
|
|
for (int i = 1; i <= Dim; i++)
|
|
res[i, i] = FieldStructure.Log(this[i, i]);
|
|
return res;
|
|
}
|
|
|
|
/// <summary>
|
|
/// exp of the normal matrix
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public FDiagonalMatrix Exp()
|
|
{
|
|
FDiagonalMatrix res = new();
|
|
for (int i = 1; i <= Dim; i++)
|
|
res[i, i] = FieldStructure.Exp(this[i, i]);
|
|
return res;
|
|
}
|
|
|
|
internal override void UnitaryFix(FMatrix a) { }
|
|
|
|
}
|
|
}
|
|
}
|