diff --git a/Skeleton.csproj b/Skeleton.csproj index f7ffdab..5788700 100644 --- a/Skeleton.csproj +++ b/Skeleton.csproj @@ -13,5 +13,7 @@ bin\Release\net6.0\Skeleton.xml - + + true + diff --git a/src/Algebra.zip b/src/Algebra.zip new file mode 100644 index 0000000..7eb0818 Binary files /dev/null and b/src/Algebra.zip differ diff --git a/src/Algebra/Matrices/FMatrix.cs b/src/Algebra/Matrices/FMatrix.cs index 8a4a885..4b31fbd 100644 --- a/src/Algebra/Matrices/FMatrix.cs +++ b/src/Algebra/Matrices/FMatrix.cs @@ -200,6 +200,7 @@ public partial class CategoryOf (c1, c2) = (c2, c1); } } + } } diff --git a/src/Algebra/Matrices/Matrix.cs b/src/Algebra/Matrices/Matrix.cs index 0bebf8d..76654a2 100644 --- a/src/Algebra/Matrices/Matrix.cs +++ b/src/Algebra/Matrices/Matrix.cs @@ -87,6 +87,7 @@ public abstract class Matrix< TMatrix> : Matrix internal abstract TMatrix Mul(TMatrix other); internal abstract void SelfMul(TMatrix other); internal abstract void SelfLMul(TMatrix other); + internal abstract void SelfAdd(TMatrix other); /// /// Add two matrix of the same dim over same field /// @@ -158,7 +159,9 @@ public abstract class Matrix< TMatrix> : Matrix /// /// transpose current matrix, modify on current matrix without return a new one /// - public abstract void SelfTranspose(); + internal abstract void SelfTranspose(); + + internal abstract void SelfHermitian(); /// /// Eigen decomposition of the matrix, M = JD inv(J)
@@ -442,13 +445,24 @@ public abstract class Matrix : Matrix - public override void SelfTranspose() + internal override void SelfTranspose() { for (int i = 1; i <= Dim; i++) for (int j = 1; j < i; j++) (this[i, j], this[j, i]) = (this[j, i], this[i, j]); } + internal override void SelfHermitian() + { + for(int i = 1; i <= Dim; i++) + for(int j = 1; j public override TMatrix Transpose() { @@ -610,6 +624,12 @@ public abstract class Matrix : Matrix : Matrix.OnField.FMatrix)! ) as TMatrix)!; if (this is CategoryOf.OnField.FMatrix self3) - return (ComplexMatrixExtension.FastMul( self3, (other as CategoryOf.OnField.FMatrix)! @@ -1248,11 +1267,6 @@ public abstract class Matrix : Matrix : Matrix where TValue : new() +{ + public Box(Func f) + { + Value = f(); + } + + public Box() + { + Value = new(); + } + + public TValue Value { get; set; } +} \ No newline at end of file diff --git a/src/Samples/C22Samples.cs b/src/Samples/C22Samples.cs index 486081c..db983e9 100644 --- a/src/Samples/C22Samples.cs +++ b/src/Samples/C22Samples.cs @@ -1,6 +1,7 @@ using System.Numerics; using Skeleton.Algebra.DimensionProviders; using Skeleton.Utils.Helpers; +using Skeleton.Utils.RandomEngines; namespace Skeleton.Samples; using C22 = Algebra.CategoryOf.OnField.FMatrix; @@ -35,5 +36,4 @@ public static class C22Samples if (m.Det().Magnitude > 0.2d) yield return m; } - } \ No newline at end of file diff --git a/src/Utils/Helpers/LinqHelper.cs b/src/Utils/Helpers/LinqHelper.cs index e7339ad..44d0a76 100644 --- a/src/Utils/Helpers/LinqHelper.cs +++ b/src/Utils/Helpers/LinqHelper.cs @@ -20,7 +20,7 @@ public static class LinqHelper ///
public static IEnumerable Shuffle(this IEnumerable a) { - return a.OrderBy(_ => RandomSource.Rnd.NextDouble()); + return a.OrderBy(_ => RandomSource.Get()); } /// @@ -62,7 +62,7 @@ public static class LinqHelper T[] ac = a.ToArray(); int len = ac.Length; for (int i = 0; i <= count; i++) - yield return ac[RandomSource.Rnd.NextInt64(0, len)]; + yield return ac[RandomSource.Rnd.Value.NextInt64(0, len)]; } /// @@ -70,7 +70,7 @@ public static class LinqHelper /// public static IEnumerable Sample(this IEnumerable a, double freq) { - return a.Where(x => RandomSource.Rnd.NextDouble() < freq); + return a.Where(x => RandomSource.Rnd.Value.NextDouble() < freq); } /// @@ -559,6 +559,12 @@ public static class LinqHelper public static CategoryOf.FSpecialLieUnitaryMatrix SpLieSum (this IEnumerable.FSpecialLieUnitaryMatrix> es) => new(es.LieSum()); + public static T WithSeed(this T a, int seed) + { + RandomSource.SetSeed(seed); + if (seed < 0) + RandomSource.Rnd.Value = new Random(); - + return a; + } } \ No newline at end of file diff --git a/src/Utils/RandomEngines/RandomSource.cs b/src/Utils/RandomEngines/RandomSource.cs index 853f332..fe116e3 100644 --- a/src/Utils/RandomEngines/RandomSource.cs +++ b/src/Utils/RandomEngines/RandomSource.cs @@ -1,3 +1,5 @@ +using Skeleton.DataStructure; + namespace Skeleton.Utils.RandomEngines; /// @@ -6,13 +8,21 @@ public static class RandomSource { /// /// - public static Random Rnd = new(); + public static ThreadLocal Rnd = new(() => new Random()); + + public static void SetSeed(int seed) + { + Rnd.Value = new Random(seed); + } /// /// /// public static double Get() { - return Rnd.NextDouble(); + return Rnd.Value.NextDouble(); } + + + } \ No newline at end of file