From 2d850dc64c7ca732467f14e5b7b411e83a563387 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Thu, 7 Dec 2023 23:53:37 -0600
Subject: [PATCH] Update rank-one tensor contractions
- Use IRankOneTensor instead of a specific implementation
---
.../DifferentialGeometry/DifGeo.cs | 44 +++++++++++--------
1 file changed, 26 insertions(+), 18 deletions(-)
diff --git a/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs b/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs
index 0698609c..719818cf 100644
--- a/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs
+++ b/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs
@@ -36,19 +36,23 @@ namespace Mathematics.NET.DifferentialGeometry;
public static class DifGeo
{
/// Contract two rank-one tensors: $ a_\mu b^\mu $
- /// The backing type of the tensors
- /// A type that implements
- /// A symbol
+ /// A rank-one tensor with a lower index
+ /// A rank-one tensor with an upper index
+ /// A backing type that implements
+ /// A type that implements
+ /// The name of the index to contract
/// A tensor with a lower index
/// A tensor with an upper index
/// A scalar
- public static U Contract(RankOneTensor> a, RankOneTensor> b)
- where T : IVector
- where U : IComplex
- where V : ISymbol
+ public static W Contract(IRankOneTensor> a, IRankOneTensor> b)
+ where T : IRankOneTensor>
+ where U : IRankOneTensor>
+ where V : IVector
+ where W : IComplex
+ where X : ISymbol
{
- U result = U.Zero;
- for (int i = 0; i < T.E1Components; i++)
+ var result = W.Zero;
+ for (int i = 0; i < V.E1Components; i++)
{
result += a[i] * b[i];
}
@@ -56,19 +60,23 @@ public static U Contract(RankOneTensor> a, RankOn
}
/// Contract two rank-one tensors: $ a^\mu b_\mu $
- /// The backing type of the tensors
- /// A type that implements
- /// A symbol
+ /// A rank-one tensor with an upper index
+ /// A rank-one tensor with a lower index
+ /// A backing type that implements
+ /// A type that implements
+ /// The name of the index to contract
/// A tensor with an upper index
/// A tensor with a lower index
/// A scalar
- public static U Contract(RankOneTensor> a, RankOneTensor> b)
- where T : IVector
- where U : IComplex
- where V : ISymbol
+ public static W Contract(IRankOneTensor> a, IRankOneTensor> b)
+ where T : IRankOneTensor>
+ where U : IRankOneTensor>
+ where V : IVector
+ where W : IComplex
+ where X : ISymbol
{
- U result = U.Zero;
- for (int i = 0; i < T.E1Components; i++)
+ var result = W.Zero;
+ for (int i = 0; i < V.E1Components; i++)
{
result += a[i] * b[i];
}