diff --git a/docs/guide/diagnostic_messages/difgeo/dg0001.md b/docs/guide/diagnostic_messages/difgeo/dg0001.md new file mode 100644 index 00000000..b6524507 --- /dev/null +++ b/docs/guide/diagnostic_messages/difgeo/dg0001.md @@ -0,0 +1,35 @@ +# DG0001: Invalid Index Name Declaration + +## Cause + +An index name was defined outside the scope of a namepace. + +## How to Fix Violations + +Place the index name in a namespace. + +## Example + +The following violates the rule: +```csharp +using Mathematics.NET.Core.Attributes; + +[IndexName] public partial struct Alpha; +``` +The following are valid: +```csharp +using Mathematics.NET.Core.Attributes; + +namespace DG0001; + +[IndexName] public partial struct Alpha; +``` +and +```csharp +using Mathematics.NET.Core.Attributes; + +namespace DG0001 +{ + [IndexName] public partial struct Alpha; +} +``` diff --git a/docs/guide/diagnostic_messages/symbols/sgs0001.md b/docs/guide/diagnostic_messages/symbols/sgs0001.md deleted file mode 100644 index 35bf580c..00000000 --- a/docs/guide/diagnostic_messages/symbols/sgs0001.md +++ /dev/null @@ -1,35 +0,0 @@ -# SGS0001: Invalid Symbol Declaration - -## Cause - -A symbol was defined outside the scope of a namepace. - -## How to Fix Violations - -Place the symbol in a namespace. - -## Example - -The following violates the rule: -```csharp -using Mathematics.NET.Core.Attributes; - -[Symbol] public partial struct Alpha; -``` -The following are valid: -```csharp -using Mathematics.NET.Core.Attributes; - -namespace SGS0001; - -[Symbol] public partial struct Alpha; -``` -and -```csharp -using Mathematics.NET.Core.Attributes; - -namespace SGS0001 -{ - [Symbol] public partial struct Alpha; -} -``` diff --git a/docs/guide/toc.yml b/docs/guide/toc.yml index fda23722..00cbb74a 100644 --- a/docs/guide/toc.yml +++ b/docs/guide/toc.yml @@ -22,7 +22,7 @@ items: - name: Mathematics.NET Diagnostic Messages href: diagnostic_messages/diagnostic-messages.md - - name: Symbols Diagnostic Messages + - name: Differential Geometry items: - - name: SGS0001 - href: diagnostic_messages/symbols/sgs0001.md + - name: DG0001 + href: diagnostic_messages/difgeo/dg0001.md diff --git a/docs/template/public/main.css b/docs/template/public/main.css index cfc54b2a..15400ce8 100644 --- a/docs/template/public/main.css +++ b/docs/template/public/main.css @@ -52,6 +52,8 @@ code { #interactive-card > .flare, #overlay { position: absolute; + transition: ease-out; + transition-duration: 250ms; opacity: 0; pointer-events: none; } diff --git a/src/Mathematics.NET.SourceGenerators.Public/DiagnosticMessage.cs b/src/Mathematics.NET.SourceGenerators.Public/DiagnosticMessages.cs similarity index 78% rename from src/Mathematics.NET.SourceGenerators.Public/DiagnosticMessage.cs rename to src/Mathematics.NET.SourceGenerators.Public/DiagnosticMessages.cs index 677407f7..32a142d7 100644 --- a/src/Mathematics.NET.SourceGenerators.Public/DiagnosticMessage.cs +++ b/src/Mathematics.NET.SourceGenerators.Public/DiagnosticMessages.cs @@ -1,4 +1,4 @@ -// +// // Mathematics.NET // https://github.com/HamletTanyavong/Mathematics.NET // @@ -28,17 +28,17 @@ namespace Mathematics.NET.SourceGenerators.Public; /// A class for creating diagnostic messages for use in Mathematics.NET source generators. -internal static class DiagnosticMessage +internal static class DiagnosticMessages { - public static DiagnosticDescriptor CreateInvalidSymbolDeclarationDiagnosticDescriptor() + public static DiagnosticDescriptor CreateInvalidIndexNameDeclarationDiagnosticDescriptor() { return new DiagnosticDescriptor( - id: "SGS0001", - title: "Invalid symbol declaration", - messageFormat: "Symbols must be declared in namespaces.", - category: "Symbols", + id: "DG0001", + title: "Invalid index name declaration.", + messageFormat: "Index names must be declared in namespaces.", + category: "DifGeo", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, - helpLinkUri: "https://mathematics.hamlettanyavong.com/guide/diagnostic_messages/symbols/sgs0001.html"); + helpLinkUri: "https://mathematics.hamlettanyavong.com/guide/diagnostic_messages/difgeo/dg0001.html"); } } diff --git a/src/Mathematics.NET.SourceGenerators.Public/Extensions.cs b/src/Mathematics.NET.SourceGenerators.Public/Extensions.cs index f251e54e..fb054a5b 100644 --- a/src/Mathematics.NET.SourceGenerators.Public/Extensions.cs +++ b/src/Mathematics.NET.SourceGenerators.Public/Extensions.cs @@ -75,14 +75,10 @@ public static NameSyntax CreateNameSyntaxFromNamespace(this string namespaceName public static NameSyntax? GetNamespaceNameSyntaxFromStructOrDefault(this StructDeclarationSyntax structDeclaration) { if (structDeclaration.Parent is FileScopedNamespaceDeclarationSyntax fileScopedNamespaceDeclaration) - { return fileScopedNamespaceDeclaration.Name; - } if (structDeclaration.Parent is NamespaceDeclarationSyntax namespaceDeclaration) - { return namespaceDeclaration.Name.WithoutTrailingTrivia(); - } return default; } @@ -93,14 +89,10 @@ public static NameSyntax CreateNameSyntaxFromNamespace(this string namespaceName public static string? GetNameValueOrDefault(this NameSyntax? name) { if (name is null) - { return default; - } if (name is SimpleNameSyntax simpleName) - { return simpleName.Identifier.Text; - } if (name is QualifiedNameSyntax qualifiedName) { diff --git a/src/Mathematics.NET.SourceGenerators.Public/Symbols/SymbolBuilder.cs b/src/Mathematics.NET.SourceGenerators.Public/IndexNames/IndexNameBuilder.cs similarity index 88% rename from src/Mathematics.NET.SourceGenerators.Public/Symbols/SymbolBuilder.cs rename to src/Mathematics.NET.SourceGenerators.Public/IndexNames/IndexNameBuilder.cs index 93e906ef..9d30373b 100644 --- a/src/Mathematics.NET.SourceGenerators.Public/Symbols/SymbolBuilder.cs +++ b/src/Mathematics.NET.SourceGenerators.Public/IndexNames/IndexNameBuilder.cs @@ -1,4 +1,4 @@ -// +// // Mathematics.NET // https://github.com/HamletTanyavong/Mathematics.NET // @@ -30,19 +30,17 @@ using Microsoft.CodeAnalysis.CSharp; using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; -namespace Mathematics.NET.SourceGenerators.Public.Symbols; +namespace Mathematics.NET.SourceGenerators.Public.IndexNames; -/// Symbols builder. -internal sealed class SymbolBuilder +/// Index name builder. +internal sealed class IndexNameBuilder { private readonly NameSyntax _namespaceNameSyntax; - private readonly SourceProductionContext _context; private readonly ImmutableArray _structInformationArray; - public SymbolBuilder(NameSyntax namespaceNameSyntax, SourceProductionContext context, ImmutableArray structInformationArray) + public IndexNameBuilder(NameSyntax namespaceNameSyntax, ImmutableArray structInformationArray) { _namespaceNameSyntax = namespaceNameSyntax; - _context = context; _structInformationArray = structInformationArray; } @@ -61,7 +59,7 @@ private CompilationUnitSyntax CreateCompilationUnit(ImmutableArray GenerateMembers() List members = []; for (int i = 0; i < _structInformationArray.Length; i++) { - members.Add(GenerateSymbol(_structInformationArray[i].StructDeclarationSyntax, i == _structInformationArray.Length - 1)); + members.Add(GenerateIndexName(_structInformationArray[i].StructDeclarationSyntax, i == _structInformationArray.Length - 1)); } return members.ToImmutableArray(); } @@ -110,13 +108,13 @@ private ImmutableArray GenerateMembers() // Helpers // - private StructDeclarationSyntax GenerateSymbol(StructDeclarationSyntax structDeclaration, bool isLastSymbol) + private StructDeclarationSyntax GenerateIndexName(StructDeclarationSyntax structDeclaration, bool isLastIndex) { - var symbolName = structDeclaration.Identifier.Text; + var indexName = structDeclaration.Identifier.Text; return StructDeclaration( Identifier( TriviaList(), - symbolName, + indexName, TriviaList(Space))) .WithKeyword( Token( @@ -144,21 +142,21 @@ private StructDeclarationSyntax GenerateSymbol(StructDeclarationSyntax structDec IdentifierName( Identifier( TriviaList(), - "ISymbol", + "IIndexName", TriviaList(CarriageReturnLineFeed)))))) .WithColonToken( Token( TriviaList(), SyntaxKind.ColonToken, TriviaList(Space)))) - .WithOpenAndCloseBraceTokens(string.Empty, !isLastSymbol) + .WithOpenAndCloseBraceTokens(string.Empty, !isLastIndex) .WithMembers( List(new MemberDeclarationSyntax[] { - GenerateDisplayStringField(symbolName), + GenerateDisplayStringField(indexName), GenerateDisplayStringProperty() })); } - private FieldDeclarationSyntax GenerateDisplayStringField(string symbolName) + private FieldDeclarationSyntax GenerateDisplayStringField(string indexName) { return FieldDeclaration( VariableDeclaration( @@ -178,7 +176,7 @@ private FieldDeclarationSyntax GenerateDisplayStringField(string symbolName) EqualsValueClause( LiteralExpression( SyntaxKind.StringLiteralExpression, - Literal(symbolName))) + Literal(indexName))) .WithEqualsToken( Token( TriviaList(), @@ -202,7 +200,6 @@ private FieldDeclarationSyntax GenerateDisplayStringField(string symbolName) TriviaList(), SyntaxKind.SemicolonToken, TriviaList( - CarriageReturnLineFeed, CarriageReturnLineFeed))); } @@ -227,7 +224,7 @@ private PropertyDeclarationSyntax GenerateDisplayStringProperty() TriviaList(Space)))) .WithExplicitInterfaceSpecifier( ExplicitInterfaceSpecifier( - IdentifierName("ISymbol"))) + IdentifierName("IIndexName"))) .WithExpressionBody( ArrowExpressionClause( IdentifierName("DisplayString")) @@ -265,7 +262,7 @@ private DocumentationCommentTriviaSyntax GenerateDocumentationComment() SingletonList( XmlCrefAttribute( QualifiedCref( - IdentifierName("ISymbol"), + IdentifierName("IIndexName"), NameMemberCref( IdentifierName("DisplayString")))))), XmlText() diff --git a/src/Mathematics.NET.SourceGenerators.Public/Symbols/SymbolGenerator.cs b/src/Mathematics.NET.SourceGenerators.Public/IndexNames/IndexNameGenerator.cs similarity index 78% rename from src/Mathematics.NET.SourceGenerators.Public/Symbols/SymbolGenerator.cs rename to src/Mathematics.NET.SourceGenerators.Public/IndexNames/IndexNameGenerator.cs index 7c0552d3..ed64fc1d 100644 --- a/src/Mathematics.NET.SourceGenerators.Public/Symbols/SymbolGenerator.cs +++ b/src/Mathematics.NET.SourceGenerators.Public/IndexNames/IndexNameGenerator.cs @@ -1,4 +1,4 @@ -// +// // Mathematics.NET // https://github.com/HamletTanyavong/Mathematics.NET // @@ -29,23 +29,23 @@ using System.Text; using Mathematics.NET.SourceGenerators.Public.Models; -namespace Mathematics.NET.SourceGenerators.Public.Symbols; +namespace Mathematics.NET.SourceGenerators.Public.IndexNames; -/// A generator for mathematical symbols. +/// A generator for index names. [Generator] -public sealed class SymbolGenerator : IIncrementalGenerator +public sealed class IndexNameGenerator : IIncrementalGenerator { public void Initialize(IncrementalGeneratorInitializationContext context) { var provider = context.SyntaxProvider - .CreateSyntaxProvider(CouldBeSymbolAttribute, GetStructInformationOrNull) + .CreateSyntaxProvider(CouldBeIndexNameAttribute, GetStructInformationOrNull) .Where(x => x is not null); var compilation = context.CompilationProvider.Combine(provider.Collect()); context.RegisterSourceOutput(compilation, (context, source) => GenerateCode(context, source.Right)); } - private static bool CouldBeSymbolAttribute(SyntaxNode syntaxNode, CancellationToken token) - => syntaxNode is AttributeSyntax attributeSyntax && attributeSyntax.Name.GetLastIdentifierNameValueOrDefault() is "Symbol" or "SymbolAttribute"; + private static bool CouldBeIndexNameAttribute(SyntaxNode syntaxNode, CancellationToken token) + => syntaxNode is AttributeSyntax attributeSyntax && attributeSyntax.Name.GetLastIdentifierNameValueOrDefault() is "IndexName" or "IndexNameAttribute"; private static StructInformation GetStructInformationOrNull(GeneratorSyntaxContext context, CancellationToken token) { @@ -70,13 +70,13 @@ private void GenerateCode(SourceProductionContext context, ImmutableArray - - True - \ - - - True - \ - - - True - \ - + + + @@ -44,7 +35,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/src/Mathematics.NET.SourceGenerators.Public/Models/StructInformation.cs b/src/Mathematics.NET.SourceGenerators.Public/Models/StructInformation.cs index 3c62145e..768a0cb5 100644 --- a/src/Mathematics.NET.SourceGenerators.Public/Models/StructInformation.cs +++ b/src/Mathematics.NET.SourceGenerators.Public/Models/StructInformation.cs @@ -27,7 +27,7 @@ namespace Mathematics.NET.SourceGenerators.Public.Models; -/// A class containing information about a symbol struct. +/// A class containing information about an index name struct. internal sealed class StructInformation { public StructInformation(NameSyntax? namespaceNameSyntax, AttributeSyntax attributeSyntax, StructDeclarationSyntax structDeclarationSyntax) diff --git a/src/Mathematics.NET.SourceGenerators.Public/NameSyntaxComparer.cs b/src/Mathematics.NET.SourceGenerators.Public/NameSyntaxComparer.cs index c97ba474..a1f571a8 100644 --- a/src/Mathematics.NET.SourceGenerators.Public/NameSyntaxComparer.cs +++ b/src/Mathematics.NET.SourceGenerators.Public/NameSyntaxComparer.cs @@ -32,9 +32,7 @@ internal sealed class NameSyntaxComparer : IEqualityComparer public bool Equals(NameSyntax? x, NameSyntax? y) { if (x is not null && y is not null) - { return x.GetNameValueOrDefault() == y.GetNameValueOrDefault(); - } return x == y; } diff --git a/src/Mathematics.NET.SourceGenerators/DiagnosticMessage.cs b/src/Mathematics.NET.SourceGenerators/DiagnosticMessages.cs similarity index 97% rename from src/Mathematics.NET.SourceGenerators/DiagnosticMessage.cs rename to src/Mathematics.NET.SourceGenerators/DiagnosticMessages.cs index a4e9e605..204ddc74 100644 --- a/src/Mathematics.NET.SourceGenerators/DiagnosticMessage.cs +++ b/src/Mathematics.NET.SourceGenerators/DiagnosticMessages.cs @@ -1,4 +1,4 @@ -// +// // Mathematics.NET // https://github.com/HamletTanyavong/Mathematics.NET // @@ -29,7 +29,7 @@ namespace Mathematics.NET.SourceGenerators; -internal static class DiagnosticMessage +internal static class DiagnosticMessages { // // Differential Geometry diff --git a/src/Mathematics.NET.SourceGenerators/DifferentialGeometry/BracketedArgumentIndexSwapRewriter.cs b/src/Mathematics.NET.SourceGenerators/DifferentialGeometry/BracketedArgumentIndexSwapRewriter.cs index 2534c053..e1b5c118 100644 --- a/src/Mathematics.NET.SourceGenerators/DifferentialGeometry/BracketedArgumentIndexSwapRewriter.cs +++ b/src/Mathematics.NET.SourceGenerators/DifferentialGeometry/BracketedArgumentIndexSwapRewriter.cs @@ -50,13 +50,9 @@ private ArgumentSyntax GetIndexToSwap(BracketedArgumentListSyntax bracketedArgum public override SyntaxNode? VisitArgument(ArgumentSyntax node) { if (node == _indexToContract) - { return _indexToSwap; - } else if (node == _indexToSwap) - { return _indexToContract; - } return node; } } diff --git a/src/Mathematics.NET.SourceGenerators/DifferentialGeometry/FlipIndexPositionRewriter.cs b/src/Mathematics.NET.SourceGenerators/DifferentialGeometry/FlipIndexPositionRewriter.cs index e4e5a89d..e4d7b954 100644 --- a/src/Mathematics.NET.SourceGenerators/DifferentialGeometry/FlipIndexPositionRewriter.cs +++ b/src/Mathematics.NET.SourceGenerators/DifferentialGeometry/FlipIndexPositionRewriter.cs @@ -38,13 +38,9 @@ internal sealed class FlipIndexPositionRewriter : CSharpSyntaxRewriter public override SyntaxNode VisitIdentifierName(IdentifierNameSyntax node) { if (node.Identifier.Text == "Lower") - { return s_upper; - } else if (node.Identifier.Text == "Upper") - { return s_lower; - } return node; } } diff --git a/src/Mathematics.NET.SourceGenerators/DifferentialGeometry/TensorContractionBuilder.cs b/src/Mathematics.NET.SourceGenerators/DifferentialGeometry/TensorContractionBuilder.cs index ddcacb16..fac17eb3 100644 --- a/src/Mathematics.NET.SourceGenerators/DifferentialGeometry/TensorContractionBuilder.cs +++ b/src/Mathematics.NET.SourceGenerators/DifferentialGeometry/TensorContractionBuilder.cs @@ -26,7 +26,6 @@ // using System.Collections.Immutable; -using Mathematics.NET.SourceGenerators.DifferentialGeometry.Models; using Microsoft.CodeAnalysis.CSharp; using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; @@ -76,8 +75,7 @@ private CompilationUnitSyntax CreateCompilationUnit(ImmutableArray( FileScopedNamespaceDeclaration( @@ -92,7 +90,8 @@ private CompilationUnitSyntax CreateCompilationUnit(ImmutableArray GenerateMembers() @@ -104,9 +103,7 @@ private ImmutableArray GenerateMembers() // Validate seed contraction. if (!IsValidSeedContraction(method) || !HasSummationComponents(method)) - { continue; - } method = method.RemoveAttribute("GenerateTensorContractions"); @@ -155,9 +152,9 @@ private bool HasSummationComponents(MethodDeclarationSyntax methodDeclaration) .OfType() .FirstOrDefault(x => x.IsKind(SyntaxKind.MultiplyExpression)); if (multiplyExpression is null || - multiplyExpression.Parent?.Parent?.Parent?.Parent is null) // Check for for loop + multiplyExpression.Parent?.Parent?.Parent?.Parent is null) // Check for for loop. { - var descriptor = DiagnosticMessage.CreateMissingSummationComponentsDiagnosticDescriptor(); + var descriptor = DiagnosticMessages.CreateMissingSummationComponentsDiagnosticDescriptor(); _context.ReportDiagnostic(Diagnostic.Create(descriptor, methodDeclaration.Identifier.GetLocation())); return false; } @@ -166,27 +163,21 @@ private bool HasSummationComponents(MethodDeclarationSyntax methodDeclaration) private bool IsValidSeedContraction(MethodDeclarationSyntax methodDeclaration) { - // Validate method name + // Validate method name. if (!IsValidMethodName(methodDeclaration)) - { return false; - } var paramList = methodDeclaration.ParameterList()!; - // Validate left tensor + // Validate left tensor. var leftArgs = paramList.Parameters[(int)IndexPosition.Left].TypeArgumentList()!; if (!IsValidIndexPositionAndName(IndexLocation.First, leftArgs, "Lower")) - { return false; - } - // Validate right tensor + // Validate right tensor. var rightArgs = paramList.Parameters[(int)IndexPosition.Right].TypeArgumentList()!; if (!IsValidIndexPositionAndName(IndexLocation.First, rightArgs, "Upper")) - { return false; - } return true; } diff --git a/src/Mathematics.NET.SourceGenerators/DifferentialGeometry/TensorContractionBuilderBase.cs b/src/Mathematics.NET.SourceGenerators/DifferentialGeometry/TensorContractionBuilderBase.cs index f64abd79..c7a983e4 100644 --- a/src/Mathematics.NET.SourceGenerators/DifferentialGeometry/TensorContractionBuilderBase.cs +++ b/src/Mathematics.NET.SourceGenerators/DifferentialGeometry/TensorContractionBuilderBase.cs @@ -68,7 +68,7 @@ private protected bool IsValidIndexPositionAndName(IndexLocation location, TypeA var actualPosition = (IdentifierNameSyntax)name.TypeArgumentList.Arguments[0]; if (actualPosition.Identifier.Text != indexPosition) { - var descriptor = DiagnosticMessage.CreateIncorrectIndexPositionDiagnosticDescriptor(indexPosition); + var descriptor = DiagnosticMessages.CreateIncorrectIndexPositionDiagnosticDescriptor(indexPosition); _context.ReportDiagnostic(Diagnostic.Create(descriptor, actualPosition.Identifier.GetLocation())); return false; } @@ -76,14 +76,14 @@ private protected bool IsValidIndexPositionAndName(IndexLocation location, TypeA var typeParameterName = (IdentifierNameSyntax)name.TypeArgumentList.Arguments[1]; if (typeParameterName.Identifier.Text != "TCI") { - var descriptor = DiagnosticMessage.CreateIncorrectTypeParameterNameDiagnosticDescriptor(); + var descriptor = DiagnosticMessages.CreateIncorrectTypeParameterNameDiagnosticDescriptor(); _context.ReportDiagnostic(Diagnostic.Create(descriptor, typeParameterName.Identifier.GetLocation())); return false; } } else { - var descriptor = DiagnosticMessage.CreateIncorrectIndexToContractDiagnosticDescriptor(location); + var descriptor = DiagnosticMessages.CreateIncorrectIndexToContractDiagnosticDescriptor(location); _context.ReportDiagnostic(Diagnostic.Create(descriptor, typeArgumentList.Arguments[(int)location].GetLocation())); return false; } @@ -95,7 +95,7 @@ private protected bool IsValidMethodName(MethodDeclarationSyntax methodDeclarati { if (methodDeclaration.Identifier.Text != "Contract") { - var descriptor = DiagnosticMessage.CreateInvalidMethodNameDiagnosticDescriptor(); + var descriptor = DiagnosticMessages.CreateInvalidMethodNameDiagnosticDescriptor(); _context.ReportDiagnostic(Diagnostic.Create(descriptor, methodDeclaration.Identifier.GetLocation())); } return true; diff --git a/src/Mathematics.NET.SourceGenerators/DifferentialGeometry/Models/TensorRankInformation.cs b/src/Mathematics.NET.SourceGenerators/DifferentialGeometry/TensorRankInformation.cs similarity index 95% rename from src/Mathematics.NET.SourceGenerators/DifferentialGeometry/Models/TensorRankInformation.cs rename to src/Mathematics.NET.SourceGenerators/DifferentialGeometry/TensorRankInformation.cs index 3c160e35..ccbf41ac 100644 --- a/src/Mathematics.NET.SourceGenerators/DifferentialGeometry/Models/TensorRankInformation.cs +++ b/src/Mathematics.NET.SourceGenerators/DifferentialGeometry/TensorRankInformation.cs @@ -25,7 +25,7 @@ // SOFTWARE. // -namespace Mathematics.NET.SourceGenerators.DifferentialGeometry.Models; +namespace Mathematics.NET.SourceGenerators.DifferentialGeometry; /// Holds information about a particular tensor contraction. internal readonly record struct TensorRankInformation diff --git a/src/Mathematics.NET.SourceGenerators/DifferentialGeometry/TensorSelfContractionBuilder.cs b/src/Mathematics.NET.SourceGenerators/DifferentialGeometry/TensorSelfContractionBuilder.cs index d4c521b9..20439085 100644 --- a/src/Mathematics.NET.SourceGenerators/DifferentialGeometry/TensorSelfContractionBuilder.cs +++ b/src/Mathematics.NET.SourceGenerators/DifferentialGeometry/TensorSelfContractionBuilder.cs @@ -60,8 +60,7 @@ private CompilationUnitSyntax CreateCompilationUnit(ImmutableArray( FileScopedNamespaceDeclaration( @@ -76,7 +75,8 @@ private CompilationUnitSyntax CreateCompilationUnit(ImmutableArray GenerateMembers() @@ -88,9 +88,7 @@ private ImmutableArray GenerateMembers() // Validate seed contraction. if (!IsValidSeedContraction(method) || !HasSummationComponents(method)) - { continue; - } method = method.RemoveAttribute("GenerateTensorSelfContractions"); @@ -137,9 +135,9 @@ private bool HasSummationComponents(MethodDeclarationSyntax methodDeclaration) .OfType() .FirstOrDefault(x => x.IsKind(SyntaxKind.AddAssignmentExpression)); if (addAssignmentExpression is null || - addAssignmentExpression.Parent?.Parent?.Parent is null) // Check for for loop + addAssignmentExpression.Parent?.Parent?.Parent is null) // Check for for loop. { - var descriptor = DiagnosticMessage.CreateMissingSummationComponentsDiagnosticDescriptor(); + var descriptor = DiagnosticMessages.CreateMissingSummationComponentsDiagnosticDescriptor(); _context.ReportDiagnostic(Diagnostic.Create(descriptor, methodDeclaration.Identifier.GetLocation())); return false; } @@ -148,20 +146,16 @@ private bool HasSummationComponents(MethodDeclarationSyntax methodDeclaration) private bool IsValidSeedContraction(MethodDeclarationSyntax methodDeclaration) { - // Validate method name + // Validate method name. if (!IsValidMethodName(methodDeclaration)) - { return false; - } var paramList = methodDeclaration.ParameterList()!; - // Validate tensor + // Validate tensor. var args = paramList.Parameters[0].TypeArgumentList()!; if (!IsValidIndexPositionAndName(IndexLocation.First, args, "Lower") || !IsValidIndexPositionAndName(IndexLocation.Second, args, "Upper")) - { return false; - } return true; } diff --git a/src/Mathematics.NET.SourceGenerators/DifferentialGeometry/TypeArgumentIndexSwapRewriter.cs b/src/Mathematics.NET.SourceGenerators/DifferentialGeometry/TypeArgumentIndexSwapRewriter.cs index 421fca53..347ebc9f 100644 --- a/src/Mathematics.NET.SourceGenerators/DifferentialGeometry/TypeArgumentIndexSwapRewriter.cs +++ b/src/Mathematics.NET.SourceGenerators/DifferentialGeometry/TypeArgumentIndexSwapRewriter.cs @@ -46,18 +46,14 @@ public TypeArgumentIndexSwapRewriter(TypeArgumentListSyntax typeArgumentList) public override SyntaxNode? VisitGenericName(GenericNameSyntax node) { if (node == _indexToContract) - { return _indexToSwap; - } return node; } public override SyntaxNode? VisitIdentifierName(IdentifierNameSyntax node) { if (node == _indexToSwap) - { return _indexToContract; - } return node; } } diff --git a/src/Mathematics.NET.SourceGenerators/Extensions.cs b/src/Mathematics.NET.SourceGenerators/Extensions.cs index 04271dbf..d6ce25e5 100644 --- a/src/Mathematics.NET.SourceGenerators/Extensions.cs +++ b/src/Mathematics.NET.SourceGenerators/Extensions.cs @@ -44,9 +44,7 @@ public static NameSyntax CreateNameSyntaxFromNamespace(this string namespaceStri NameSyntax result = IdentifierName(names[0]); for (int i = 1; i < names.Length; i++) - { result = QualifiedName(result, IdentifierName(names[i])); - } return result; } @@ -58,22 +56,16 @@ public static NameSyntax CreateNameSyntaxFromNamespace(this string namespaceStri public static MethodDeclarationSyntax RemoveAttribute(this MethodDeclarationSyntax methodDeclarationSyntax, string attributeName) { if (attributeName.EndsWith("Attribute")) - { attributeName = attributeName.Remove(attributeName.Length - 9); - } var attributeNode = methodDeclarationSyntax .DescendantNodes() .OfType() .First(x => x.Name.GetLastIdentifierNameValueOrDefault() == attributeName); if (attributeNode.Parent!.ChildNodes().Count() > 1) - { return methodDeclarationSyntax.RemoveNode(attributeNode, SyntaxRemoveOptions.KeepNoTrivia)!; - } else - { return methodDeclarationSyntax.RemoveNode(attributeNode.Parent, SyntaxRemoveOptions.KeepNoTrivia)!; - } } // diff --git a/src/Mathematics.NET.SourceGenerators/Mathematics.NET.SourceGenerators.csproj b/src/Mathematics.NET.SourceGenerators/Mathematics.NET.SourceGenerators.csproj index 71083354..f20b0921 100644 --- a/src/Mathematics.NET.SourceGenerators/Mathematics.NET.SourceGenerators.csproj +++ b/src/Mathematics.NET.SourceGenerators/Mathematics.NET.SourceGenerators.csproj @@ -7,11 +7,10 @@ - - all + runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/src/Mathematics.NET/AutoDiff/GradientTape.cs b/src/Mathematics.NET/AutoDiff/GradientTape.cs index a8410971..4a7f590d 100644 --- a/src/Mathematics.NET/AutoDiff/GradientTape.cs +++ b/src/Mathematics.NET/AutoDiff/GradientTape.cs @@ -243,7 +243,7 @@ public Variable Divide(Variable x, T c) return new(_nodes.Count, x.Value * u); } - public Variable Modulo(Variable x, Variable y) + public Variable Modulo(in Variable x, in Variable y) { if (_isTracking) { @@ -253,7 +253,7 @@ public Variable Modulo(Variable x, Variable y) return new(_nodes.Count, x.Value % y.Value); } - public Variable Modulo(Real c, Variable x) + public Variable Modulo(Real c, in Variable x) { if (_isTracking) { @@ -263,7 +263,7 @@ public Variable Modulo(Real c, Variable x) return new(_nodes.Count, c % x.Value); } - public Variable Modulo(Variable x, Real c) + public Variable Modulo(in Variable x, Real c) { if (_isTracking) { @@ -590,7 +590,7 @@ public Variable Atan(Variable x) return new(_nodes.Count, T.Atan(x.Value)); } - public Variable Atan2(Variable y, Variable x) + public Variable Atan2(in Variable y, in Variable x) { if (_isTracking) { diff --git a/src/Mathematics.NET/AutoDiff/HessianTape.cs b/src/Mathematics.NET/AutoDiff/HessianTape.cs index 55fbd2c4..1fc527bc 100644 --- a/src/Mathematics.NET/AutoDiff/HessianTape.cs +++ b/src/Mathematics.NET/AutoDiff/HessianTape.cs @@ -360,7 +360,7 @@ public Variable Divide(Variable x, T c) return new(_nodes.Count, x.Value * u); } - public Variable Modulo(Variable x, Variable y) + public Variable Modulo(in Variable x, in Variable y) { if (_isTracking) { @@ -370,7 +370,7 @@ public Variable Modulo(Variable x, Variable y) return new(_nodes.Count, x.Value % y.Value); } - public Variable Modulo(Real c, Variable x) + public Variable Modulo(Real c, in Variable x) { if (_isTracking) { @@ -380,7 +380,7 @@ public Variable Modulo(Real c, Variable x) return new(_nodes.Count, c % x.Value); } - public Variable Modulo(Variable x, Real c) + public Variable Modulo(in Variable x, Real c) { if (_isTracking) { @@ -765,7 +765,7 @@ public Variable Atan(Variable x) return new(_nodes.Count, T.Atan(x.Value)); } - public Variable Atan2(Variable y, Variable x) + public Variable Atan2(in Variable y, in Variable x) { if (_isTracking) { diff --git a/src/Mathematics.NET/AutoDiff/ITape.cs b/src/Mathematics.NET/AutoDiff/ITape.cs index 242dc3b9..995037f5 100644 --- a/src/Mathematics.NET/AutoDiff/ITape.cs +++ b/src/Mathematics.NET/AutoDiff/ITape.cs @@ -109,19 +109,19 @@ public interface ITape /// A dividend. /// A divisor. /// mod . - public Variable Modulo(Variable x, Variable y); + public Variable Modulo(in Variable x, in Variable y); /// Compute the modulo of a real value given a divisor. /// A real dividend. /// A variable divisor. /// mod . - public Variable Modulo(Real c, Variable x); + public Variable Modulo(Real c, in Variable x); /// Compute the modulo of a variable given a divisor. /// A variable dividend. /// A real divisor. /// mod . - public Variable Modulo(Variable x, Real c); + public Variable Modulo(in Variable x, Real c); /// Multiply two variables. /// The first variable. @@ -247,7 +247,7 @@ public interface ITape public Variable Atan(Variable x); /// - public Variable Atan2(Variable y, Variable x); + public Variable Atan2(in Variable y, in Variable x); /// public Variable Cos(Variable x); diff --git a/src/Mathematics.NET/Core/Attributes/GeneratorAttributes/GenerateTensorContractionsAttribute.cs b/src/Mathematics.NET/Core/Attributes/GenerateTensorContractionsAttribute.cs similarity index 96% rename from src/Mathematics.NET/Core/Attributes/GeneratorAttributes/GenerateTensorContractionsAttribute.cs rename to src/Mathematics.NET/Core/Attributes/GenerateTensorContractionsAttribute.cs index 56cdc3e4..0bc30550 100644 --- a/src/Mathematics.NET/Core/Attributes/GeneratorAttributes/GenerateTensorContractionsAttribute.cs +++ b/src/Mathematics.NET/Core/Attributes/GenerateTensorContractionsAttribute.cs @@ -25,7 +25,7 @@ // SOFTWARE. // -namespace Mathematics.NET.Core.Attributes.GeneratorAttributes; +namespace Mathematics.NET.Core.Attributes; /// Indicates that index permutations of a tensor contraction should be generated. [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] diff --git a/src/Mathematics.NET/Core/Attributes/GeneratorAttributes/GenerateTensorSelfContractions.cs b/src/Mathematics.NET/Core/Attributes/GenerateTensorSelfContractions.cs similarity index 96% rename from src/Mathematics.NET/Core/Attributes/GeneratorAttributes/GenerateTensorSelfContractions.cs rename to src/Mathematics.NET/Core/Attributes/GenerateTensorSelfContractions.cs index 919f6aea..862e748d 100644 --- a/src/Mathematics.NET/Core/Attributes/GeneratorAttributes/GenerateTensorSelfContractions.cs +++ b/src/Mathematics.NET/Core/Attributes/GenerateTensorSelfContractions.cs @@ -25,7 +25,7 @@ // SOFTWARE. // -namespace Mathematics.NET.Core.Attributes.GeneratorAttributes; +namespace Mathematics.NET.Core.Attributes; /// Indicates that index permutations of a tensor self-contraction should be generated. [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] diff --git a/src/Mathematics.NET/Core/Attributes/SymbolAttribute.cs b/src/Mathematics.NET/Core/Attributes/IndexNameAttribute.cs similarity index 84% rename from src/Mathematics.NET/Core/Attributes/SymbolAttribute.cs rename to src/Mathematics.NET/Core/Attributes/IndexNameAttribute.cs index 5ecac2bb..a43659c6 100644 --- a/src/Mathematics.NET/Core/Attributes/SymbolAttribute.cs +++ b/src/Mathematics.NET/Core/Attributes/IndexNameAttribute.cs @@ -1,4 +1,4 @@ -// +// // Mathematics.NET // https://github.com/HamletTanyavong/Mathematics.NET // @@ -27,6 +27,6 @@ namespace Mathematics.NET.Core.Attributes; -/// Indicates that a type represents a mathematical symbol and that its properties should be generated. +/// Indicates that a type represents an index name and that its properties should be generated. [AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)] -public sealed class SymbolAttribute : Attribute; +public sealed class IndexNameAttribute : Attribute; diff --git a/src/Mathematics.NET/DifferentialGeometry/Christoffel.cs b/src/Mathematics.NET/DifferentialGeometry/Christoffel.cs index 7166aae4..defd8671 100644 --- a/src/Mathematics.NET/DifferentialGeometry/Christoffel.cs +++ b/src/Mathematics.NET/DifferentialGeometry/Christoffel.cs @@ -29,7 +29,6 @@ using System.Runtime.CompilerServices; using Mathematics.NET.DifferentialGeometry.Abstractions; using Mathematics.NET.LinearAlgebra.Abstractions; -using Mathematics.NET.Symbols; namespace Mathematics.NET.DifferentialGeometry; @@ -45,8 +44,8 @@ public struct Christoffel(TCA array) where TCA : ICubicArray where TN : IComplex, IDifferentiableFunctions where TI1 : IIndex - where TI2N : ISymbol - where TI3N : ISymbol + where TI2N : IIndexName + where TI3N : IIndexName { private TCA _array = array; @@ -134,8 +133,8 @@ public struct Christoffel(TCA array) [MethodImpl(MethodImplOptions.AggressiveInlining)] public Christoffel WithIndices() where TNI1 : IIndex - where TNI2N : ISymbol - where TNI3N : ISymbol + where TNI2N : IIndexName + where TNI3N : IIndexName => Unsafe.As, Christoffel>(ref this); /// Reinterpret this Christoffel symbol as one with a new index in the first position. @@ -151,7 +150,7 @@ public Christoffel WithIndex1() /// A Christoffel symbol with a new index name in the second position. [MethodImpl(MethodImplOptions.AggressiveInlining)] public Christoffel WithIndex2Name() - where TNIN : ISymbol + where TNIN : IIndexName => Unsafe.As, Christoffel>(ref this); /// Reinterpret this Christoffel symbol as one with a new index name in the third position. @@ -159,7 +158,7 @@ public Christoffel WithIndex2Name() /// A Christoffel symbol with a new index name in the third position. [MethodImpl(MethodImplOptions.AggressiveInlining)] public Christoffel WithIndex3Name() - where TNIN : ISymbol + where TNIN : IIndexName => Unsafe.As, Christoffel>(ref this); // diff --git a/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs b/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs index abeca649..495e1736 100644 --- a/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs +++ b/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs @@ -27,11 +27,11 @@ using System.Runtime.CompilerServices; using Mathematics.NET.AutoDiff; -using Mathematics.NET.Core.Attributes.GeneratorAttributes; +using Mathematics.NET.Core.Attributes; using Mathematics.NET.DifferentialGeometry.Abstractions; +using Mathematics.NET.DifferentialGeometry.IndexNames; using Mathematics.NET.LinearAlgebra; using Mathematics.NET.LinearAlgebra.Abstractions; -using Mathematics.NET.Symbols; namespace Mathematics.NET.DifferentialGeometry; @@ -63,15 +63,15 @@ public static void Derivative( out Tensor, TN, Index, Index, Index> dMetric) where TT : ITape where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol + where TPIN : IIndexName + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName { - var value = metric.Compute(tape, point); + var value = metric.Compute(tape, point); var invMetricL = value.Inverse(); - var invMetricR = invMetricL.WithIndices(); - Derivative(tape, metric, point, out Tensor, TN, Index, Index, Index> dTensor); + var invMetricR = invMetricL.WithIndices(); + Derivative(tape, metric, point, out Tensor, TN, Index, Index, Index> dTensor); dMetric = -Contract(Contract(dTensor, invMetricL), invMetricR); } @@ -84,15 +84,15 @@ public static void Derivative( out Tensor, TN, Index, Index, Index> dMetric) where TT : ITape where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol + where TPIN : IIndexName + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName { - var value = metric.Compute(tape, point); + var value = metric.Compute(tape, point); var invMetricL = value.Inverse(); - var invMetricR = invMetricL.WithIndices(); - Derivative(tape, metric, point, out Tensor, TN, Index, Index, Index> dTensor); + var invMetricR = invMetricL.WithIndices(); + Derivative(tape, metric, point, out Tensor, TN, Index, Index, Index> dTensor); dMetric = -Contract(Contract(dTensor, invMetricL), invMetricR); } @@ -105,15 +105,15 @@ public static void Derivative( out Tensor, TN, Index, Index, Index> dMetric) where TT : ITape where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol + where TPIN : IIndexName + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName { - var value = metric.Compute(tape, point); + var value = metric.Compute(tape, point); var invMetricL = value.Inverse(); - var invMetricR = invMetricL.WithIndices(); - Derivative(tape, metric, point, out Tensor, TN, Index, Index, Index> dTensor); + var invMetricR = invMetricL.WithIndices(); + Derivative(tape, metric, point, out Tensor, TN, Index, Index, Index> dTensor); dMetric = -Contract(Contract(dTensor, invMetricL), invMetricR); } @@ -137,15 +137,15 @@ public static void Derivative( out Tensor, TN, Index, Index, Index> dMetric) where TT : ITape where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol + where TPIN : IIndexName + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName { - var value = metric.Compute(tape, point); + var value = metric.Compute(tape, point); var invMetricL = value.Inverse(); - var invMetricR = invMetricL.WithIndices(); - Derivative(tape, metric, point, out Tensor, TN, Index, Index, Index> dTensor); + var invMetricR = invMetricL.WithIndices(); + Derivative(tape, metric, point, out Tensor, TN, Index, Index, Index> dTensor); dMetric = -Contract(Contract(dTensor, invMetricL), invMetricR); } @@ -158,15 +158,15 @@ public static void Derivative( out Tensor, TN, Index, Index, Index> dMetric) where TT : ITape where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol + where TPIN : IIndexName + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName { - var value = metric.Compute(tape, point); + var value = metric.Compute(tape, point); var invMetricL = value.Inverse(); - var invMetricR = invMetricL.WithIndices(); - Derivative(tape, metric, point, out Tensor, TN, Index, Index, Index> dTensor); + var invMetricR = invMetricL.WithIndices(); + Derivative(tape, metric, point, out Tensor, TN, Index, Index, Index> dTensor); dMetric = -Contract(Contract(dTensor, invMetricL), invMetricR); } @@ -179,15 +179,15 @@ public static void Derivative( out Tensor, TN, Index, Index, Index> dMetric) where TT : ITape where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol + where TPIN : IIndexName + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName { - var value = metric.Compute(tape, point); + var value = metric.Compute(tape, point); var invMetricL = value.Inverse(); - var invMetricR = invMetricL.WithIndices(); - Derivative(tape, metric, point, out Tensor, TN, Index, Index, Index> dTensor); + var invMetricR = invMetricL.WithIndices(); + Derivative(tape, metric, point, out Tensor, TN, Index, Index, Index> dTensor); dMetric = -Contract(Contract(dTensor, invMetricL), invMetricR); } @@ -213,12 +213,12 @@ public static void Derivative( out Tensor, TN, Index, Index, Index> dTensor) where TT : ITape where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol + where TPIN : IIndexName where TI2P : IIndexPosition where TI3P : IIndexPosition - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName { dTensor = new(); for (int i = 0; i < 2; i++) @@ -245,12 +245,12 @@ public static void Derivative( out Tensor, TN, Index, Index, Index> dTensor) where TT : ITape where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol + where TPIN : IIndexName where TI2P : IIndexPosition where TI3P : IIndexPosition - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName { dTensor = new(); for (int i = 0; i < 3; i++) @@ -278,12 +278,12 @@ public static void Derivative( out Tensor, TN, Index, Index, Index> dTensor) where TT : ITape where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol + where TPIN : IIndexName where TI2P : IIndexPosition where TI3P : IIndexPosition - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName { dTensor = new(); for (int i = 0; i < 4; i++) @@ -312,12 +312,12 @@ public static void Derivative( out Tensor, TN, Index, Index, Index> dTensor) where TT : ITape where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol + where TPIN : IIndexName where TI2P : IIndexPosition where TI3P : IIndexPosition - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName { dTensor = new(); for (int i = 0; i < 2; i++) @@ -344,12 +344,12 @@ public static void Derivative( out Tensor, TN, Index, Index, Index> dTensor) where TT : ITape where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol + where TPIN : IIndexName where TI2P : IIndexPosition where TI3P : IIndexPosition - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName { dTensor = new(); for (int i = 0; i < 3; i++) @@ -377,12 +377,12 @@ public static void Derivative( out Tensor, TN, Index, Index, Index> dTensor) where TT : ITape where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol + where TPIN : IIndexName where TI2P : IIndexPosition where TI3P : IIndexPosition - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName { dTensor = new(); for (int i = 0; i < 4; i++) @@ -423,13 +423,13 @@ public static void SecondDerivative> point, out Tensor, TN, Index, Index, Index, Index> d2Tensor) where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol + where TPIN : IIndexName where TI3P : IIndexPosition where TI4P : IIndexPosition - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol - where TI4N : ISymbol + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName + where TI4N : IIndexName { d2Tensor = new(); for (int i = 0; i < 2; i++) @@ -458,13 +458,13 @@ public static void SecondDerivative> point, out Tensor, TN, Index, Index, Index, Index> d2Tensor) where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol + where TPIN : IIndexName where TI3P : IIndexPosition where TI4P : IIndexPosition - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol - where TI4N : ISymbol + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName + where TI4N : IIndexName { d2Tensor = new(); for (int i = 0; i < 3; i++) @@ -499,13 +499,13 @@ public static void SecondDerivative> point, out Tensor, TN, Index, Index, Index, Index> d2Tensor) where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol + where TPIN : IIndexName where TI3P : IIndexPosition where TI4P : IIndexPosition - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol - where TI4N : ISymbol + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName + where TI4N : IIndexName { d2Tensor = new(); for (int i = 0; i < 4; i++) @@ -548,13 +548,13 @@ public static void SecondDerivative> point, out Tensor, TN, Index, Index, Index, Index> d2Tensor) where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol + where TPIN : IIndexName where TI3P : IIndexPosition where TI4P : IIndexPosition - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol - where TI4N : ISymbol + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName + where TI4N : IIndexName { d2Tensor = new(); for (int i = 0; i < 2; i++) @@ -583,13 +583,13 @@ public static void SecondDerivative> point, out Tensor, TN, Index, Index, Index, Index> d2Tensor) where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol + where TPIN : IIndexName where TI3P : IIndexPosition where TI4P : IIndexPosition - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol - where TI4N : ISymbol + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName + where TI4N : IIndexName { d2Tensor = new(); for (int i = 0; i < 3; i++) @@ -624,13 +624,13 @@ public static void SecondDerivative> point, out Tensor, TN, Index, Index, Index, Index> d2Tensor) where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol + where TPIN : IIndexName where TI3P : IIndexPosition where TI4P : IIndexPosition - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol - where TI4N : ISymbol + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName + where TI4N : IIndexName { d2Tensor = new(); for (int i = 0; i < 4; i++) @@ -688,10 +688,10 @@ public static void Christoffel( out Christoffel, TN, Index, TI2N, TI3N> christoffel) where TT : ITape where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol + where TPIN : IIndexName + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName { christoffel = new(); Derivative(tape, metric, point, out Tensor, TN, Index, Index, Index> derivative); @@ -716,10 +716,10 @@ public static void Christoffel( out Christoffel, TN, Index, TI2N, TI3N> christoffel) where TT : ITape where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol + where TPIN : IIndexName + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName { christoffel = new(); Derivative(tape, metric, point, out Tensor, TN, Index, Index, Index> derivative); @@ -744,10 +744,10 @@ public static void Christoffel( out Christoffel, TN, Index, TI2N, TI3N> christoffel) where TT : ITape where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol + where TPIN : IIndexName + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName { christoffel = new(); Derivative(tape, metric, point, out Tensor, TN, Index, Index, Index> derivative); @@ -782,14 +782,14 @@ public static void Christoffel( out Christoffel, TN, Index, TI2N, TI3N> christoffel) where TT : ITape where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol + where TPIN : IIndexName + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName { - var value = metric.Compute(tape, point); + var value = metric.Compute(tape, point); var invMetric = value.Inverse(); - Christoffel(tape, metric, point, out Christoffel, TN, Index, TI2N, TI3N> christoffelFK); + Christoffel(tape, metric, point, out Christoffel, TN, Index, TI2N, TI3N> christoffelFK); var result = Contract(invMetric, christoffelFK); @@ -807,14 +807,14 @@ public static void Christoffel( out Christoffel, TN, Index, TI2N, TI3N> christoffel) where TT : ITape where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol + where TPIN : IIndexName + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName { - var value = metric.Compute(tape, point); + var value = metric.Compute(tape, point); var invMetric = value.Inverse(); - Christoffel(tape, metric, point, out Christoffel, TN, Index, TI2N, TI3N> christoffelFK); + Christoffel(tape, metric, point, out Christoffel, TN, Index, TI2N, TI3N> christoffelFK); var result = Contract(invMetric, christoffelFK); @@ -832,14 +832,14 @@ public static void Christoffel( out Christoffel, TN, Index, TI2N, TI3N> christoffel) where TT : ITape where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol + where TPIN : IIndexName + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName { - var value = metric.Compute(tape, point); + var value = metric.Compute(tape, point); var invMetric = value.Inverse(); - Christoffel(tape, metric, point, out Christoffel, TN, Index, TI2N, TI3N> christoffelFK); + Christoffel(tape, metric, point, out Christoffel, TN, Index, TI2N, TI3N> christoffelFK); var result = Contract(invMetric, christoffelFK); @@ -866,11 +866,11 @@ public static void DerivativeOfChristoffel( AutoDiffTensor2> point, out Tensor, TN, Index, Index, Index, Index> derivative) where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol - where TI4N : ISymbol + where TPIN : IIndexName + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName + where TI4N : IIndexName { SecondDerivative(tape, metric, point, out Tensor, TN, Index, Index, Index, Index> d2Metric); @@ -897,11 +897,11 @@ public static void DerivativeOfChristoffel( AutoDiffTensor3> point, out Tensor, TN, Index, Index, Index, Index> derivative) where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol - where TI4N : ISymbol + where TPIN : IIndexName + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName + where TI4N : IIndexName { SecondDerivative(tape, metric, point, out Tensor, TN, Index, Index, Index, Index> d2Metric); @@ -928,11 +928,11 @@ public static void DerivativeOfChristoffel( AutoDiffTensor4> point, out Tensor, TN, Index, Index, Index, Index> derivative) where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol - where TI4N : ISymbol + where TPIN : IIndexName + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName + where TI4N : IIndexName { SecondDerivative(tape, metric, point, out Tensor, TN, Index, Index, Index, Index> d2Metric); @@ -969,16 +969,16 @@ public static void DerivativeOfChristoffel( AutoDiffTensor2> point, out Tensor, TN, Index, Index, Index, Index> derivative) where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol - where TI4N : ISymbol + where TPIN : IIndexName + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName + where TI4N : IIndexName { - Derivative(tape, metric, point, out Tensor, TN, Index, Index, Index> dInvMetric); - Christoffel(tape, metric, point, out Christoffel, TN, Index, TI3N, TI4N> christoffel); - var invMetric = metric.ComputeInverse(tape, point); - DerivativeOfChristoffel(tape, metric, point, out Tensor, TN, Index, Index, Index, Index> dChristoffel); + Derivative(tape, metric, point, out Tensor, TN, Index, Index, Index> dInvMetric); + Christoffel(tape, metric, point, out Christoffel, TN, Index, TI3N, TI4N> christoffel); + var invMetric = metric.ComputeInverse(tape, point); + DerivativeOfChristoffel(tape, metric, point, out Tensor, TN, Index, Index, Index, Index> dChristoffel); var firstPart = Contract(dInvMetric, christoffel); var secondPart = Contract(invMetric, dChristoffel); @@ -1006,16 +1006,16 @@ public static void DerivativeOfChristoffel( AutoDiffTensor3> point, out Tensor, TN, Index, Index, Index, Index> derivative) where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol - where TI4N : ISymbol + where TPIN : IIndexName + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName + where TI4N : IIndexName { - Derivative(tape, metric, point, out Tensor, TN, Index, Index, Index> dInvMetric); - Christoffel(tape, metric, point, out Christoffel, TN, Index, TI3N, TI4N> christoffel); - var invMetric = metric.ComputeInverse(tape, point); - DerivativeOfChristoffel(tape, metric, point, out Tensor, TN, Index, Index, Index, Index> dChristoffel); + Derivative(tape, metric, point, out Tensor, TN, Index, Index, Index> dInvMetric); + Christoffel(tape, metric, point, out Christoffel, TN, Index, TI3N, TI4N> christoffel); + var invMetric = metric.ComputeInverse(tape, point); + DerivativeOfChristoffel(tape, metric, point, out Tensor, TN, Index, Index, Index, Index> dChristoffel); var firstPart = Contract(dInvMetric, christoffel); var secondPart = Contract(invMetric, dChristoffel); @@ -1043,16 +1043,16 @@ public static void DerivativeOfChristoffel( AutoDiffTensor4> point, out Tensor, TN, Index, Index, Index, Index> derivative) where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol - where TI4N : ISymbol + where TPIN : IIndexName + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName + where TI4N : IIndexName { - Derivative(tape, metric, point, out Tensor, TN, Index, Index, Index> dInvMetric); - Christoffel(tape, metric, point, out Christoffel, TN, Index, TI3N, TI4N> christoffel); - var invMetric = metric.ComputeInverse(tape, point); - DerivativeOfChristoffel(tape, metric, point, out Tensor, TN, Index, Index, Index, Index> dChristoffel); + Derivative(tape, metric, point, out Tensor, TN, Index, Index, Index> dInvMetric); + Christoffel(tape, metric, point, out Christoffel, TN, Index, TI3N, TI4N> christoffel); + var invMetric = metric.ComputeInverse(tape, point); + DerivativeOfChristoffel(tape, metric, point, out Tensor, TN, Index, Index, Index, Index> dChristoffel); var firstPart = Contract(dInvMetric, christoffel); var secondPart = Contract(invMetric, dChristoffel); @@ -1094,15 +1094,15 @@ public static void Riemann( AutoDiffTensor2> point, out Tensor, TN, Index, Index, Index, Index> riemann) where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol - where TI4N : ISymbol + where TPIN : IIndexName + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName + where TI4N : IIndexName { DerivativeOfChristoffel(tape, metric, point, out Tensor, TN, Index, Index, Index, Index> dChristoffel); - Christoffel(tape, metric, point, out Christoffel, TN, Index, InternalIndex1, TI3N> christoffel); - var cChristoffels = Contract(christoffel, christoffel.WithIndices, TI2N, TI4N>()); + Christoffel(tape, metric, point, out Christoffel, TN, Index, Index1, TI3N> christoffel); + var cChristoffels = Contract(christoffel, christoffel.WithIndices, TI2N, TI4N>()); riemann = new(); for (int r = 0; r < 2; r++) @@ -1128,15 +1128,15 @@ public static void Riemann( AutoDiffTensor3> point, out Tensor, TN, Index, Index, Index, Index> riemann) where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol - where TI4N : ISymbol + where TPIN : IIndexName + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName + where TI4N : IIndexName { DerivativeOfChristoffel(tape, metric, point, out Tensor, TN, Index, Index, Index, Index> dChristoffel); - Christoffel(tape, metric, point, out Christoffel, TN, Index, InternalIndex1, TI3N> christoffel); - var cChristoffels = Contract(christoffel, christoffel.WithIndices, TI2N, TI4N>()); + Christoffel(tape, metric, point, out Christoffel, TN, Index, Index1, TI3N> christoffel); + var cChristoffels = Contract(christoffel, christoffel.WithIndices, TI2N, TI4N>()); riemann = new(); for (int r = 0; r < 3; r++) @@ -1162,15 +1162,15 @@ public static void Riemann( AutoDiffTensor4> point, out Tensor, TN, Index, Index, Index, Index> riemann) where TN : IComplex, IDifferentiableFunctions - where TPIN : ISymbol - where TI1N : ISymbol - where TI2N : ISymbol - where TI3N : ISymbol - where TI4N : ISymbol + where TPIN : IIndexName + where TI1N : IIndexName + where TI2N : IIndexName + where TI3N : IIndexName + where TI4N : IIndexName { DerivativeOfChristoffel(tape, metric, point, out Tensor, TN, Index, Index, Index, Index> dChristoffel); - Christoffel(tape, metric, point, out Christoffel, TN, Index, InternalIndex1, TI3N> christoffel); - var cChristoffels = Contract(christoffel, christoffel.WithIndices, TI2N, TI4N>()); + Christoffel(tape, metric, point, out Christoffel, TN, Index, Index1, TI3N> christoffel); + var cChristoffels = Contract(christoffel, christoffel.WithIndices, TI2N, TI4N>()); riemann = new(); for (int r = 0; r < 4; r++) @@ -1201,7 +1201,7 @@ public static TN Contract(in IRankOneTensor> where TV : IVector where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName { var result = TN.Zero; for (int i = 0; i < TV.E1Components; i++) @@ -1220,7 +1220,7 @@ public static Tensor, TN, TI> Contract( where TR1T : IRankOneTensor, TN, Index> where TR2T : IRankTwoTensor, TN, Index, TI> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI : IIndex { Vector2 vector = new(); @@ -1241,7 +1241,7 @@ public static Tensor, TN, TI> Contract( where TR1T : IRankOneTensor, TN, Index> where TR2T : IRankTwoTensor, TN, Index, TI> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI : IIndex { Vector3 vector = new(); @@ -1262,7 +1262,7 @@ public static Tensor, TN, TI> Contract( where TR1T : IRankOneTensor, TN, Index> where TR2T : IRankTwoTensor, TN, Index, TI> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI : IIndex { Vector4 vector = new(); @@ -1283,7 +1283,7 @@ public static Tensor, TN, TI> Contract( where TR2T : IRankTwoTensor, TN, Index, TI> where TR1T : IRankOneTensor, TN, Index> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI : IIndex { Vector2 vector = new(); @@ -1304,7 +1304,7 @@ public static Tensor, TN, TI> Contract( where TR2T : IRankTwoTensor, TN, Index, TI> where TR1T : IRankOneTensor, TN, Index> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI : IIndex { Vector3 vector = new(); @@ -1325,7 +1325,7 @@ public static Tensor, TN, TI> Contract( where TR2T : IRankTwoTensor, TN, Index, TI> where TR1T : IRankOneTensor, TN, Index> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI : IIndex { Vector4 vector = new(); @@ -1348,7 +1348,7 @@ public static Tensor, TN, TI1, TI2> Contract, TN, Index> where TR3T : IRankThreeTensor, TN, Index, TI1, TI2> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex { @@ -1373,7 +1373,7 @@ public static Tensor, TN, TI1, TI2> Contract, TN, Index> where TR3T : IRankThreeTensor, TN, Index, TI1, TI2> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex { @@ -1398,7 +1398,7 @@ public static Tensor, TN, TI1, TI2> Contract, TN, Index> where TR3T : IRankThreeTensor, TN, Index, TI1, TI2> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex { @@ -1423,7 +1423,7 @@ public static Tensor, TN, TI1, TI2> Contract, TN, Index, TI1, TI2> where TR1T : IRankOneTensor, TN, Index> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex { @@ -1448,7 +1448,7 @@ public static Tensor, TN, TI1, TI2> Contract, TN, Index, TI1, TI2> where TR1T : IRankOneTensor, TN, Index> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex { @@ -1473,7 +1473,7 @@ public static Tensor, TN, TI1, TI2> Contract, TN, Index, TI1, TI2> where TR1T : IRankOneTensor, TN, Index> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex { @@ -1500,7 +1500,7 @@ public static Tensor, TN, TI1, TI2, TI3> Contract, TN, Index> where TR4T : IRankFourTensor, TN, Index, TI1, TI2, TI3> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex @@ -1529,7 +1529,7 @@ public static Tensor, TN, TI1, TI2, TI3> Contract, TN, Index> where TR4T : IRankFourTensor, TN, Index, TI1, TI2, TI3> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex @@ -1558,7 +1558,7 @@ public static Tensor, TN, TI1, TI2, TI3> Contract, TN, Index> where TR4T : IRankFourTensor, TN, Index, TI1, TI2, TI3> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex @@ -1587,7 +1587,7 @@ public static Tensor, TN, TI1, TI2, TI3> Contract, TN, Index, TI1, TI2, TI3> where TR1T : IRankOneTensor, TN, Index> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex @@ -1616,7 +1616,7 @@ public static Tensor, TN, TI1, TI2, TI3> Contract, TN, Index, TI1, TI2, TI3> where TR1T : IRankOneTensor, TN, Index> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex @@ -1645,7 +1645,7 @@ public static Tensor, TN, TI1, TI2, TI3> Contract, TN, Index, TI1, TI2, TI3> where TR1T : IRankOneTensor, TN, Index> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex @@ -1676,7 +1676,7 @@ public static Tensor, TN, TI1, TI2> Contract, TN, Index, TI1> where TRR3T : IRankTwoTensor, TN, Index, TI2> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex { @@ -1701,7 +1701,7 @@ public static Tensor, TN, TI1, TI2> Contract, TN, Index, TI1> where TRR3T : IRankTwoTensor, TN, Index, TI2> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex { @@ -1726,7 +1726,7 @@ public static Tensor, TN, TI1, TI2> Contract, TN, Index, TI1> where TRR3T : IRankTwoTensor, TN, Index, TI2> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex { @@ -1753,7 +1753,7 @@ public static Tensor, TN, TI1, TI2, TI3> Contract, TN, Index, TI1> where TR3T : IRankThreeTensor, TN, Index, TI2, TI3> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex @@ -1782,7 +1782,7 @@ public static Tensor, TN, TI1, TI2, TI3> Contract, TN, Index, TI1> where TR3T : IRankThreeTensor, TN, Index, TI2, TI3> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex @@ -1811,7 +1811,7 @@ public static Tensor, TN, TI1, TI2, TI3> Contract, TN, Index, TI1> where TR3T : IRankThreeTensor, TN, Index, TI2, TI3> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex @@ -1840,7 +1840,7 @@ public static Tensor, TN, TI1, TI2, TI3> Contract, TN, Index, TI1, TI2> where TR2T : IRankTwoTensor, TN, Index, TI3> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex @@ -1869,7 +1869,7 @@ public static Tensor, TN, TI1, TI2, TI3> Contract, TN, Index, TI1, TI2> where TR2T : IRankTwoTensor, TN, Index, TI3> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex @@ -1898,7 +1898,7 @@ public static Tensor, TN, TI1, TI2, TI3> Contract, TN, Index, TI1, TI2> where TR2T : IRankTwoTensor, TN, Index, TI3> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex @@ -1929,7 +1929,7 @@ public static Tensor, TN, TI1, TI2, TI3, TI4> Contract, TN, Index, TI1> where TR4T : IRankFourTensor, TN, Index, TI2, TI3, TI4> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex @@ -1962,7 +1962,7 @@ public static Tensor, TN, TI1, TI2, TI3, TI4> Contract, TN, Index, TI1> where TR4T : IRankFourTensor, TN, Index, TI2, TI3, TI4> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex @@ -1995,7 +1995,7 @@ public static Tensor, TN, TI1, TI2, TI3, TI4> Contract, TN, Index, TI1> where TR4T : IRankFourTensor, TN, Index, TI2, TI3, TI4> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex @@ -2028,7 +2028,7 @@ public static Tensor, TN, TI1, TI2, TI3, TI4> Contract, TN, Index, TI1, TI2, TI3> where TR2T : IRankTwoTensor, TN, Index, TI4> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex @@ -2061,7 +2061,7 @@ public static Tensor, TN, TI1, TI2, TI3, TI4> Contract, TN, Index, TI1, TI2, TI3> where TR2T : IRankTwoTensor, TN, Index, TI4> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex @@ -2094,7 +2094,7 @@ public static Tensor, TN, TI1, TI2, TI3, TI4> Contract, TN, Index, TI1, TI2, TI3> where TR2T : IRankTwoTensor, TN, Index, TI4> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex @@ -2129,7 +2129,7 @@ public static Tensor, TN, TI1, TI2, TI3, TI4> Contract, TN, Index, TI1, TI2> where TRR3T : IRankThreeTensor, TN, Index, TI3, TI4> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex @@ -2162,7 +2162,7 @@ public static Tensor, TN, TI1, TI2, TI3, TI4> Contract, TN, Index, TI1, TI2> where TRR3T : IRankThreeTensor, TN, Index, TI3, TI4> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex @@ -2195,7 +2195,7 @@ public static Tensor, TN, TI1, TI2, TI3, TI4> Contract, TN, Index, TI1, TI2> where TRR3T : IRankThreeTensor, TN, Index, TI3, TI4> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex @@ -2230,7 +2230,7 @@ public static TN Contract(in IRankTwoTensor, Index> where TSM : ISquareMatrix where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName { var result = TN.Zero; for (int i = 0; i < TSM.E1Components; i++) @@ -2244,7 +2244,7 @@ public static TN Contract(in IRankTwoTensor, TN, TI> Contract(in IRankThreeTensor, TN, Index, Index, TI> tensor) where TR3T : IRankThreeTensor, TN, Index, Index, TI> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI : IIndex { Vector2 vector = new(); @@ -2262,7 +2262,7 @@ public static Tensor, TN, TI> Contract(in IRankTh public static Tensor, TN, TI> Contract(in IRankThreeTensor, TN, Index, Index, TI> tensor) where TR3T : IRankThreeTensor, TN, Index, Index, TI> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI : IIndex { Vector3 vector = new(); @@ -2280,7 +2280,7 @@ public static Tensor, TN, TI> Contract(in IRankTh public static Tensor, TN, TI> Contract(in IRankThreeTensor, TN, Index, Index, TI> tensor) where TR3T : IRankThreeTensor, TN, Index, Index, TI> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI : IIndex { Vector4 vector = new(); @@ -2298,7 +2298,7 @@ public static Tensor, TN, TI> Contract(in IRankTh public static Tensor, TN, TI1, TI2> Contract(in IRankFourTensor, TN, Index, Index, TI1, TI2> tensor) where TR4T : IRankFourTensor, TN, Index, Index, TI1, TI2> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex { @@ -2320,7 +2320,7 @@ public static Tensor, TN, TI1, TI2> Contract, TN, TI1, TI2> Contract(in IRankFourTensor, TN, Index, Index, TI1, TI2> tensor) where TR4T : IRankFourTensor, TN, Index, Index, TI1, TI2> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex { @@ -2342,7 +2342,7 @@ public static Tensor, TN, TI1, TI2> Contract, TN, TI1, TI2> Contract(in IRankFourTensor, TN, Index, Index, TI1, TI2> tensor) where TR4T : IRankFourTensor, TN, Index, Index, TI1, TI2> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex { diff --git a/src/Mathematics.NET/DifferentialGeometry/DifGeoExtensions.cs b/src/Mathematics.NET/DifferentialGeometry/DifGeoExtensions.cs index 04c2b625..8e501aac 100644 --- a/src/Mathematics.NET/DifferentialGeometry/DifGeoExtensions.cs +++ b/src/Mathematics.NET/DifferentialGeometry/DifGeoExtensions.cs @@ -30,7 +30,6 @@ using Mathematics.NET.DifferentialGeometry.Abstractions; using Mathematics.NET.LinearAlgebra; using Mathematics.NET.LinearAlgebra.Abstractions; -using Mathematics.NET.Symbols; namespace Mathematics.NET.DifferentialGeometry; @@ -175,8 +174,8 @@ public static AutoDiffTensor4 CreateAutoDiffTensor(this ITape Inverse(this ref readonly MetricTensor metric) where TSM : ISquareMatrix where TN : IComplex, IDifferentiableFunctions - where TI1N : ISymbol - where TI2N : ISymbol + where TI1N : IIndexName + where TI2N : IIndexName { var inverse = Unsafe.As, TSM>(ref Unsafe.AsRef(in metric)).Inverse(); return Unsafe.As>(ref inverse); @@ -192,8 +191,8 @@ public static MetricTensor Inverse Inverse(this ref readonly MetricTensor metric) where TSM : ISquareMatrix where TN : IComplex, IDifferentiableFunctions - where TI1N : ISymbol - where TI2N : ISymbol + where TI1N : IIndexName + where TI2N : IIndexName { var inverse = Unsafe.As, TSM>(ref Unsafe.AsRef(in metric)).Inverse(); return Unsafe.As>(ref inverse); diff --git a/src/Mathematics.NET/Symbols/ISymbol.cs b/src/Mathematics.NET/DifferentialGeometry/IIndexName.cs similarity index 80% rename from src/Mathematics.NET/Symbols/ISymbol.cs rename to src/Mathematics.NET/DifferentialGeometry/IIndexName.cs index 77c6de2e..4a937212 100644 --- a/src/Mathematics.NET/Symbols/ISymbol.cs +++ b/src/Mathematics.NET/DifferentialGeometry/IIndexName.cs @@ -1,4 +1,4 @@ -// +// // Mathematics.NET // https://github.com/HamletTanyavong/Mathematics.NET // @@ -25,13 +25,11 @@ // SOFTWARE. // -namespace Mathematics.NET.Symbols; +namespace Mathematics.NET.DifferentialGeometry; -// TODO: Create source generator for symbols - -/// Defines support for mathematical symbols. -public interface ISymbol +/// Defines support for index names. +public interface IIndexName { - /// Get a string representation of this symbol. + /// Get a string representation of this index name. static abstract string DisplayString { get; } } diff --git a/src/Mathematics.NET/DifferentialGeometry/Index.cs b/src/Mathematics.NET/DifferentialGeometry/Index.cs index 914296e1..43412df2 100644 --- a/src/Mathematics.NET/DifferentialGeometry/Index.cs +++ b/src/Mathematics.NET/DifferentialGeometry/Index.cs @@ -26,16 +26,15 @@ // using Mathematics.NET.DifferentialGeometry.Abstractions; -using Mathematics.NET.Symbols; namespace Mathematics.NET.DifferentialGeometry; /// Represents a tensor index. /// An index position. -/// A symbol. +/// An index name. public readonly struct Index : IIndex where TIP : IIndexPosition - where TIN : ISymbol + where TIN : IIndexName { public static IIndex Instance => new Index(); diff --git a/src/Mathematics.NET/Symbols/InternalIndex2.cs b/src/Mathematics.NET/DifferentialGeometry/IndexNames/Index1.cs similarity index 78% rename from src/Mathematics.NET/Symbols/InternalIndex2.cs rename to src/Mathematics.NET/DifferentialGeometry/IndexNames/Index1.cs index ec5d3a4f..9f3c840a 100644 --- a/src/Mathematics.NET/Symbols/InternalIndex2.cs +++ b/src/Mathematics.NET/DifferentialGeometry/IndexNames/Index1.cs @@ -1,4 +1,4 @@ -// +// // Mathematics.NET // https://github.com/HamletTanyavong/Mathematics.NET // @@ -25,12 +25,11 @@ // SOFTWARE. // -namespace Mathematics.NET.Symbols; +namespace Mathematics.NET.DifferentialGeometry.IndexNames; -public readonly struct InternalIndex2 : ISymbol +internal readonly struct Index1 : IIndexName { - /// - public const string DisplayString = "InternalIndex2"; - - static string ISymbol.DisplayString => DisplayString; + /// + public const string DisplayString = "Index1"; + static string IIndexName.DisplayString => DisplayString; } diff --git a/src/Mathematics.NET/Symbols/InternalIndex1.cs b/src/Mathematics.NET/DifferentialGeometry/IndexNames/Index2.cs similarity index 78% rename from src/Mathematics.NET/Symbols/InternalIndex1.cs rename to src/Mathematics.NET/DifferentialGeometry/IndexNames/Index2.cs index e4e34ec3..c2aa18c5 100644 --- a/src/Mathematics.NET/Symbols/InternalIndex1.cs +++ b/src/Mathematics.NET/DifferentialGeometry/IndexNames/Index2.cs @@ -1,4 +1,4 @@ -// +// // Mathematics.NET // https://github.com/HamletTanyavong/Mathematics.NET // @@ -25,12 +25,11 @@ // SOFTWARE. // -namespace Mathematics.NET.Symbols; +namespace Mathematics.NET.DifferentialGeometry.IndexNames; -internal readonly struct InternalIndex1 : ISymbol +internal readonly struct Index2 : IIndexName { - /// - public const string DisplayString = "InternalIndex1"; - - static string ISymbol.DisplayString => DisplayString; + /// + public const string DisplayString = "Index2"; + static string IIndexName.DisplayString => DisplayString; } diff --git a/src/Mathematics.NET/DifferentialGeometry/MetricTensor.cs b/src/Mathematics.NET/DifferentialGeometry/MetricTensor.cs index 3827e430..207202c1 100644 --- a/src/Mathematics.NET/DifferentialGeometry/MetricTensor.cs +++ b/src/Mathematics.NET/DifferentialGeometry/MetricTensor.cs @@ -31,7 +31,6 @@ using Mathematics.NET.Core.Operations; using Mathematics.NET.DifferentialGeometry.Abstractions; using Mathematics.NET.LinearAlgebra.Abstractions; -using Mathematics.NET.Symbols; namespace Mathematics.NET.DifferentialGeometry; @@ -50,8 +49,8 @@ public struct MetricTensor(TSM matrix) where TSM : ISquareMatrix where TN : IComplex, IDifferentiableFunctions where TIP : IIndexPosition - where TI1N : ISymbol - where TI2N : ISymbol + where TI1N : IIndexName + where TI2N : IIndexName { public static readonly MetricTensor Euclidean = TSM.Identity; @@ -143,8 +142,8 @@ public struct MetricTensor(TSM matrix) /// The name of the second index. /// The inverse of this metric tensor with new index names. public MetricTensor Inverse() - where TNI1N : ISymbol - where TNI2N : ISymbol + where TNI1N : IIndexName + where TNI2N : IIndexName => new(_matrix.Inverse()); /// Compute the square root of the determinant of this metric tensor. @@ -162,8 +161,8 @@ public MetricTensor Inverse() /// A tensor with new index names. [MethodImpl(MethodImplOptions.AggressiveInlining)] public MetricTensor WithIndices() - where TNI1N : ISymbol - where TNI2N : ISymbol + where TNI1N : IIndexName + where TNI2N : IIndexName => Unsafe.As, MetricTensor>(ref this); /// Reinterpret this metric tensor as one with a new index name in the first position. @@ -171,7 +170,7 @@ public MetricTensor WithIndices() /// A tensor with a new index name in the first position. [MethodImpl(MethodImplOptions.AggressiveInlining)] public MetricTensor WithIndex1Name() - where TNIN : ISymbol + where TNIN : IIndexName => Unsafe.As, MetricTensor>(ref this); /// Reinterpret this metric tensor as one with a new index name in the second position. @@ -179,7 +178,7 @@ public MetricTensor WithIndex1Name() /// A tensor with a new index name in the second position. [MethodImpl(MethodImplOptions.AggressiveInlining)] public MetricTensor WithIndex2Name() - where TNIN : ISymbol + where TNIN : IIndexName => Unsafe.As, MetricTensor>(ref this); // diff --git a/src/Mathematics.NET/DifferentialGeometry/MetricTensorField2x2.cs b/src/Mathematics.NET/DifferentialGeometry/MetricTensorField2x2.cs index 77cd1e64..5ebf1e51 100644 --- a/src/Mathematics.NET/DifferentialGeometry/MetricTensorField2x2.cs +++ b/src/Mathematics.NET/DifferentialGeometry/MetricTensorField2x2.cs @@ -28,7 +28,6 @@ using Mathematics.NET.AutoDiff; using Mathematics.NET.DifferentialGeometry.Abstractions; using Mathematics.NET.LinearAlgebra; -using Mathematics.NET.Symbols; namespace Mathematics.NET.DifferentialGeometry; @@ -50,8 +49,8 @@ public MetricTensorField2x2() { } /// A point on the manifold. /// A metric tensor. public new MetricTensor, TN, Lower, TI1N, TI2N> Compute(TT tape, AutoDiffTensor2 point) - where TI1N : ISymbol - where TI2N : ISymbol + where TI1N : IIndexName + where TI2N : IIndexName { tape.IsTracking = false; @@ -76,8 +75,8 @@ public MetricTensorField2x2() { } /// A point on the manifold. /// An inverse metric tensor. public MetricTensor, TN, Upper, TI1N, TI2N> ComputeInverse(TT tape, AutoDiffTensor2 point) - where TI1N : ISymbol - where TI2N : ISymbol + where TI1N : IIndexName + where TI2N : IIndexName { var value = Compute(tape, point); return value.Inverse(); diff --git a/src/Mathematics.NET/DifferentialGeometry/MetricTensorField3x3.cs b/src/Mathematics.NET/DifferentialGeometry/MetricTensorField3x3.cs index 8b0145d8..83a1d255 100644 --- a/src/Mathematics.NET/DifferentialGeometry/MetricTensorField3x3.cs +++ b/src/Mathematics.NET/DifferentialGeometry/MetricTensorField3x3.cs @@ -28,7 +28,6 @@ using Mathematics.NET.AutoDiff; using Mathematics.NET.DifferentialGeometry.Abstractions; using Mathematics.NET.LinearAlgebra; -using Mathematics.NET.Symbols; namespace Mathematics.NET.DifferentialGeometry; @@ -45,8 +44,8 @@ public MetricTensorField3x3() { } /// public new MetricTensor, TN, Lower, TI1N, TI2N> Compute(TT tape, AutoDiffTensor3 point) - where TI1N : ISymbol - where TI2N : ISymbol + where TI1N : IIndexName + where TI2N : IIndexName { tape.IsTracking = false; @@ -66,8 +65,8 @@ public MetricTensorField3x3() { } /// public MetricTensor, TN, Upper, TI1N, TI2N> ComputeInverse(TT tape, AutoDiffTensor3 point) - where TI1N : ISymbol - where TI2N : ISymbol + where TI1N : IIndexName + where TI2N : IIndexName { var value = Compute(tape, point); return value.Inverse(); diff --git a/src/Mathematics.NET/DifferentialGeometry/MetricTensorField4x4.cs b/src/Mathematics.NET/DifferentialGeometry/MetricTensorField4x4.cs index dc768479..09cbbdc0 100644 --- a/src/Mathematics.NET/DifferentialGeometry/MetricTensorField4x4.cs +++ b/src/Mathematics.NET/DifferentialGeometry/MetricTensorField4x4.cs @@ -28,7 +28,6 @@ using Mathematics.NET.AutoDiff; using Mathematics.NET.DifferentialGeometry.Abstractions; using Mathematics.NET.LinearAlgebra; -using Mathematics.NET.Symbols; namespace Mathematics.NET.DifferentialGeometry; @@ -45,8 +44,8 @@ public MetricTensorField4x4() { } /// public new MetricTensor, TN, Lower, TI1N, TI2N> Compute(TT tape, AutoDiffTensor4 point) - where TI1N : ISymbol - where TI2N : ISymbol + where TI1N : IIndexName + where TI2N : IIndexName { tape.IsTracking = false; @@ -66,8 +65,8 @@ public MetricTensorField4x4() { } /// public MetricTensor, TN, Upper, TI1N, TI2N> ComputeInverse(TT tape, AutoDiffTensor4 point) - where TI1N : ISymbol - where TI2N : ISymbol + where TI1N : IIndexName + where TI2N : IIndexName { var value = Compute(tape, point); return value.Inverse(); diff --git a/src/Mathematics.NET/DifferentialGeometry/TensorField2x2.cs b/src/Mathematics.NET/DifferentialGeometry/TensorField2x2.cs index e6db1fd4..6c18f16f 100644 --- a/src/Mathematics.NET/DifferentialGeometry/TensorField2x2.cs +++ b/src/Mathematics.NET/DifferentialGeometry/TensorField2x2.cs @@ -30,7 +30,6 @@ using Mathematics.NET.Core.Buffers; using Mathematics.NET.DifferentialGeometry.Abstractions; using Mathematics.NET.LinearAlgebra; -using Mathematics.NET.Symbols; namespace Mathematics.NET.DifferentialGeometry; @@ -67,8 +66,8 @@ public TensorField2x2() { } /// A point on the manifold. /// A rank-two tensor. public Tensor, TN, Index, Index> Compute(TT tape, AutoDiffTensor2 point) - where TI1N : ISymbol - where TI2N : ISymbol + where TI1N : IIndexName + where TI2N : IIndexName { tape.IsTracking = false; diff --git a/src/Mathematics.NET/DifferentialGeometry/TensorField3x3.cs b/src/Mathematics.NET/DifferentialGeometry/TensorField3x3.cs index 3728e678..d9130372 100644 --- a/src/Mathematics.NET/DifferentialGeometry/TensorField3x3.cs +++ b/src/Mathematics.NET/DifferentialGeometry/TensorField3x3.cs @@ -30,7 +30,6 @@ using Mathematics.NET.Core.Buffers; using Mathematics.NET.DifferentialGeometry.Abstractions; using Mathematics.NET.LinearAlgebra; -using Mathematics.NET.Symbols; namespace Mathematics.NET.DifferentialGeometry; @@ -62,8 +61,8 @@ public TensorField3x3() { } /// public Tensor, TN, Index, Index> Compute(TT tape, AutoDiffTensor3 x) - where TI1N : ISymbol - where TI2N : ISymbol + where TI1N : IIndexName + where TI2N : IIndexName { tape.IsTracking = false; diff --git a/src/Mathematics.NET/DifferentialGeometry/TensorField4x4.cs b/src/Mathematics.NET/DifferentialGeometry/TensorField4x4.cs index 6d960efd..4bba0b8c 100644 --- a/src/Mathematics.NET/DifferentialGeometry/TensorField4x4.cs +++ b/src/Mathematics.NET/DifferentialGeometry/TensorField4x4.cs @@ -30,7 +30,6 @@ using Mathematics.NET.Core.Buffers; using Mathematics.NET.DifferentialGeometry.Abstractions; using Mathematics.NET.LinearAlgebra; -using Mathematics.NET.Symbols; namespace Mathematics.NET.DifferentialGeometry; @@ -62,8 +61,8 @@ public TensorField4x4() { } /// public Tensor, TN, Index, Index> Compute(TT tape, AutoDiffTensor4 point) - where TI1N : ISymbol - where TI2N : ISymbol + where TI1N : IIndexName + where TI2N : IIndexName { tape.IsTracking = false; diff --git a/src/Mathematics.NET/GPU/OpenCL/IComputeService.cs b/src/Mathematics.NET/GPU/IComputeService.cs similarity index 96% rename from src/Mathematics.NET/GPU/OpenCL/IComputeService.cs rename to src/Mathematics.NET/GPU/IComputeService.cs index 82dbd84e..db246184 100644 --- a/src/Mathematics.NET/GPU/OpenCL/IComputeService.cs +++ b/src/Mathematics.NET/GPU/IComputeService.cs @@ -25,7 +25,9 @@ // SOFTWARE. // -namespace Mathematics.NET.GPU.OpenCL; +using Mathematics.NET.GPU.OpenCL; + +namespace Mathematics.NET.GPU; /// Defines support for GPU compute services. public interface IComputeService : IDisposable @@ -54,7 +56,7 @@ public interface IComputeService : IDisposable /// A vector. /// A scalar. /// A new vector. - ReadOnlySpan CompVecMulScalar(Device device, nuint globalWorkSize, nuint localWorkSize, ReadOnlySpan vector, Complex scalar); + ReadOnlySpan CompVecMulScalar(Device device, nuint globalWorkSize, nuint localWorkSize, ReadOnlySpan vector, in Complex scalar); /// Multipy two matrices. /// Padded matrices should have zeros added to their right and bottom. @@ -69,6 +71,6 @@ public interface IComputeService : IDisposable /// ReadOnlySpan2D MatMul(Device device, WorkSize2D globalWorkSize, WorkSize2D localWorkSize, ReadOnlySpan2D left, ReadOnlySpan2D right); - /// + /// ReadOnlySpan VecMulScalar(Device device, nuint globalWorkSize, nuint localWorkSize, ReadOnlySpan vector, Real scalar); } diff --git a/src/Mathematics.NET/GPU/OpenCL/OpenCLService.cs b/src/Mathematics.NET/GPU/OpenCL/OpenCLService.cs index 5851286f..e440a341 100644 --- a/src/Mathematics.NET/GPU/OpenCL/OpenCLService.cs +++ b/src/Mathematics.NET/GPU/OpenCL/OpenCLService.cs @@ -151,7 +151,7 @@ public void Dispose() // TODO: Consider putting this in another file. - public unsafe ReadOnlySpan CompVecMulScalar(Device device, nuint globalWorkSize, nuint localWorkSize, ReadOnlySpan vector, Complex scalar) + public unsafe ReadOnlySpan CompVecMulScalar(Device device, nuint globalWorkSize, nuint localWorkSize, ReadOnlySpan vector, in Complex scalar) { var length = vector.Length; var result = new Complex[length]; @@ -168,7 +168,7 @@ public unsafe ReadOnlySpan CompVecMulScalar(Device device, nuint global // Set kernel arguments. var kernel = _program.Kernels["comp_vec_mul_scalar"].Handle; var error = _cl.SetKernelArg(kernel, 0, (nuint)sizeof(nint), &vectorBuffer); - error |= _cl.SetKernelArg(kernel, 1, (nuint)sizeof(Complex), &scalar); + error |= _cl.SetKernelArg(kernel, 1, (nuint)sizeof(Complex), in scalar); error |= _cl.SetKernelArg(kernel, 2, (nuint)sizeof(nint), &resultBuffer); #if DEBUG if (error != (int)ErrorCodes.Success) diff --git a/src/Mathematics.NET/Mathematics.NET.csproj b/src/Mathematics.NET/Mathematics.NET.csproj index a420b39e..e4199e6e 100644 --- a/src/Mathematics.NET/Mathematics.NET.csproj +++ b/src/Mathematics.NET/Mathematics.NET.csproj @@ -35,10 +35,10 @@ - - - - + + + + diff --git a/tests/Mathematics.NET.Benchmarks.Implementations/AutoDiff/GradientTapeWithLinkedList.cs b/tests/Mathematics.NET.Benchmarks.Implementations/AutoDiff/GradientTapeWithLinkedList.cs index 4e2c938a..a2229f17 100644 --- a/tests/Mathematics.NET.Benchmarks.Implementations/AutoDiff/GradientTapeWithLinkedList.cs +++ b/tests/Mathematics.NET.Benchmarks.Implementations/AutoDiff/GradientTapeWithLinkedList.cs @@ -166,7 +166,7 @@ public Variable Divide(Variable x, T c) return new(_nodes.Count, x.Value * u); } - public Variable Modulo(Variable x, Variable y) + public Variable Modulo(in Variable x, in Variable y) { if (_isTracking) { @@ -176,7 +176,7 @@ public Variable Modulo(Variable x, Variable y) return new(_nodes.Count, x.Value % y.Value); } - public Variable Modulo(Real c, Variable x) + public Variable Modulo(Real c, in Variable x) { if (_isTracking) { @@ -186,7 +186,7 @@ public Variable Modulo(Real c, Variable x) return new(_nodes.Count, c % x.Value); } - public Variable Modulo(Variable x, Real c) + public Variable Modulo(in Variable x, Real c) { if (_isTracking) { @@ -513,7 +513,7 @@ public Variable Atan(Variable x) return new(_nodes.Count, T.Atan(x.Value)); } - public Variable Atan2(Variable y, Variable x) + public Variable Atan2(in Variable y, in Variable x) { if (_isTracking) { diff --git a/tests/Mathematics.NET.Benchmarks.Implementations/DifferentialGeometry/DifGeoImplementations.cs b/tests/Mathematics.NET.Benchmarks.Implementations/DifferentialGeometry/DifGeoImplementations.cs index d930f711..abf06387 100644 --- a/tests/Mathematics.NET.Benchmarks.Implementations/DifferentialGeometry/DifGeoImplementations.cs +++ b/tests/Mathematics.NET.Benchmarks.Implementations/DifferentialGeometry/DifGeoImplementations.cs @@ -30,7 +30,6 @@ using Mathematics.NET.DifferentialGeometry.Abstractions; using Mathematics.NET.LinearAlgebra; using Mathematics.NET.LinearAlgebra.Abstractions; -using Mathematics.NET.Symbols; namespace Mathematics.NET.Benchmarks.Implementations.DifferentialGeometry; @@ -42,7 +41,7 @@ public static W ContractRankOneTensorWithNoInKeyword(IRankOneTen where U : IRankOneTensor> where V : IVector where W : IComplex, IDifferentiableFunctions - where IC : ISymbol + where IC : IIndexName { var result = W.Zero; for (int i = 0; i < V.E1Components; i++) @@ -58,7 +57,7 @@ public static W ContractRankOneTensorWithInKeyword(in IRankOneTe where U : IRankOneTensor> where V : IVector where W : IComplex, IDifferentiableFunctions - where IC : ISymbol + where IC : IIndexName { var result = W.Zero; for (int i = 0; i < V.E1Components; i++) @@ -75,7 +74,7 @@ public static Tensor, V, I1, I2, I3, I4> ContractRankThreeTensor where T : IRankThreeTensor, V, I1, Index, I2> where U : IRankThreeTensor, V, I3, Index, I4> where V : IComplex, IDifferentiableFunctions - where IC : ISymbol + where IC : IIndexName where I1 : IIndex where I2 : IIndex where I3 : IIndex @@ -108,7 +107,7 @@ public static Tensor, V, I1, I2, I3, I4> ContractRankThreeTensor where T : IRankThreeTensor, V, I1, Index, I2> where U : IRankThreeTensor, V, I3, Index, I4> where V : IComplex, IDifferentiableFunctions - where IC : ISymbol + where IC : IIndexName where I1 : IIndex where I2 : IIndex where I3 : IIndex @@ -139,7 +138,7 @@ public static Tensor, V, I1, I2, I3, I4> ContractRankThreeTensor ref readonly Tensor, V, I1, Index, I2> a, ref readonly Tensor, V, I3, Index, I4> b) where V : IComplex, IDifferentiableFunctions - where IC : ISymbol + where IC : IIndexName where I1 : IIndex where I2 : IIndex where I3 : IIndex diff --git a/tests/Mathematics.NET.Benchmarks.Implementations/DifferentialGeometry/Symbols/Alpha.cs b/tests/Mathematics.NET.Benchmarks.Implementations/DifferentialGeometry/Symbols/Alpha.cs index a7d03b26..84c5333c 100644 --- a/tests/Mathematics.NET.Benchmarks.Implementations/DifferentialGeometry/Symbols/Alpha.cs +++ b/tests/Mathematics.NET.Benchmarks.Implementations/DifferentialGeometry/Symbols/Alpha.cs @@ -25,11 +25,11 @@ // SOFTWARE. // -using Mathematics.NET.Symbols; +using Mathematics.NET.DifferentialGeometry; namespace Mathematics.NET.Benchmarks.Implementations.DifferentialGeometry.Symbols; -public readonly struct Alpha : ISymbol +public readonly struct Alpha : IIndexName { public static string DisplayString => "Alpha"; } diff --git a/tests/Mathematics.NET.Benchmarks.Implementations/DifferentialGeometry/Symbols/Beta.cs b/tests/Mathematics.NET.Benchmarks.Implementations/DifferentialGeometry/Symbols/Beta.cs index 053e6aa2..660421bd 100644 --- a/tests/Mathematics.NET.Benchmarks.Implementations/DifferentialGeometry/Symbols/Beta.cs +++ b/tests/Mathematics.NET.Benchmarks.Implementations/DifferentialGeometry/Symbols/Beta.cs @@ -25,11 +25,11 @@ // SOFTWARE. // -using Mathematics.NET.Symbols; +using Mathematics.NET.DifferentialGeometry; namespace Mathematics.NET.Benchmarks.Implementations.DifferentialGeometry.Symbols; -public readonly struct Beta : ISymbol +public readonly struct Beta : IIndexName { public static string DisplayString => "Beta"; } diff --git a/tests/Mathematics.NET.Benchmarks.Implementations/DifferentialGeometry/Symbols/Delta.cs b/tests/Mathematics.NET.Benchmarks.Implementations/DifferentialGeometry/Symbols/Delta.cs index d7b17b27..b287082b 100644 --- a/tests/Mathematics.NET.Benchmarks.Implementations/DifferentialGeometry/Symbols/Delta.cs +++ b/tests/Mathematics.NET.Benchmarks.Implementations/DifferentialGeometry/Symbols/Delta.cs @@ -25,11 +25,11 @@ // SOFTWARE. // -using Mathematics.NET.Symbols; +using Mathematics.NET.DifferentialGeometry; namespace Mathematics.NET.Benchmarks.Implementations.DifferentialGeometry.Symbols; -public readonly struct Delta : ISymbol +public readonly struct Delta : IIndexName { public static string DisplayString => "Delta"; } diff --git a/tests/Mathematics.NET.Benchmarks.Implementations/DifferentialGeometry/Symbols/Epsilon.cs b/tests/Mathematics.NET.Benchmarks.Implementations/DifferentialGeometry/Symbols/Epsilon.cs index 90ab03a2..fa650da3 100644 --- a/tests/Mathematics.NET.Benchmarks.Implementations/DifferentialGeometry/Symbols/Epsilon.cs +++ b/tests/Mathematics.NET.Benchmarks.Implementations/DifferentialGeometry/Symbols/Epsilon.cs @@ -25,11 +25,11 @@ // SOFTWARE. // -using Mathematics.NET.Symbols; +using Mathematics.NET.DifferentialGeometry; namespace Mathematics.NET.Benchmarks.Implementations.DifferentialGeometry.Symbols; -public readonly struct Epsilon : ISymbol +public readonly struct Epsilon : IIndexName { public static string DisplayString => "Epsilon"; } diff --git a/tests/Mathematics.NET.Benchmarks.Implementations/DifferentialGeometry/Symbols/Gamma.cs b/tests/Mathematics.NET.Benchmarks.Implementations/DifferentialGeometry/Symbols/Gamma.cs index 2d07c62f..4b4fa005 100644 --- a/tests/Mathematics.NET.Benchmarks.Implementations/DifferentialGeometry/Symbols/Gamma.cs +++ b/tests/Mathematics.NET.Benchmarks.Implementations/DifferentialGeometry/Symbols/Gamma.cs @@ -25,11 +25,11 @@ // SOFTWARE. // -using Mathematics.NET.Symbols; +using Mathematics.NET.DifferentialGeometry; namespace Mathematics.NET.Benchmarks.Implementations.DifferentialGeometry.Symbols; -public readonly struct Gamma : ISymbol +public readonly struct Gamma : IIndexName { public static string DisplayString => "Gamma"; } diff --git a/tests/Mathematics.NET.Benchmarks/Solvers/RK4IntegrationBenchmarks.cs b/tests/Mathematics.NET.Benchmarks/Solvers/RK4IntegrationBenchmarks.cs index f9fc3d38..5cc4c80a 100644 --- a/tests/Mathematics.NET.Benchmarks/Solvers/RK4IntegrationBenchmarks.cs +++ b/tests/Mathematics.NET.Benchmarks/Solvers/RK4IntegrationBenchmarks.cs @@ -1,4 +1,4 @@ -// +// // Mathematics.NET // https://github.com/HamletTanyavong/Mathematics.NET // diff --git a/tests/Mathematics.NET.Tests.SourceGenerators.Public/Symbols/SymbolGeneratorTests.cs b/tests/Mathematics.NET.Tests.SourceGenerators.Public/IndexNames/IndexNameGeneratorTests.cs similarity index 67% rename from tests/Mathematics.NET.Tests.SourceGenerators.Public/Symbols/SymbolGeneratorTests.cs rename to tests/Mathematics.NET.Tests.SourceGenerators.Public/IndexNames/IndexNameGeneratorTests.cs index cb4566a9..76bc76d8 100644 --- a/tests/Mathematics.NET.Tests.SourceGenerators.Public/Symbols/SymbolGeneratorTests.cs +++ b/tests/Mathematics.NET.Tests.SourceGenerators.Public/IndexNames/IndexNameGeneratorTests.cs @@ -1,4 +1,4 @@ -// +// // Mathematics.NET // https://github.com/HamletTanyavong/Mathematics.NET // @@ -25,58 +25,58 @@ // SOFTWARE. // -using Mathematics.NET.SourceGenerators.Public.Symbols; +using Mathematics.NET.SourceGenerators.Public.IndexNames; using Microsoft.CodeAnalysis.CSharp; -namespace Mathematics.NET.Tests.SourceGenerators.Public.Symbols; +namespace Mathematics.NET.Tests.SourceGenerators.Public.IndexNames; [TestClass] -[TestCategory("Source Generator"), TestCategory("Symbols")] -public sealed class SymbolGeneratorTests : VerifyBase +[TestCategory("Source Generator"), TestCategory("DifGeo")] +public sealed class IndexNameGeneratorTests : VerifyBase { [TestMethod] - public void SourceGenerator_StructWithSymbolAttribute_AutoImplementsISymbol() + public void SourceGenerator_StructWithIndexNameAttribute_AutoImplementsIIndexName() { var source = """ namespace A { - [Symbol] public partial struct Alpha; - [Symbol] public partial struct Beta; + [IndexName] public partial struct Alpha; + [IndexName] public partial struct Beta; } namespace A { - [Symbol] public partial struct Gamma; + [IndexName] public partial struct Gamma; } namespace A.B { - [Symbol] public partial struct Delta; + [IndexName] public partial struct Delta; } namespace B.C { - [Symbol] public partial struct Epsilon; + [IndexName] public partial struct Epsilon; } namespace B.C.D { - [Symbol] public partial struct Zeta; - [Symbol] public partial struct Eta; + [IndexName] public partial struct Zeta; + [IndexName] public partial struct Eta; } """; - SetupAndVerify(source); + _ = SetupAndVerify(source); } [TestMethod] - public void SourceGenerator_SymbolNotDeclaredInANamespace_ReturnsAnError() + public void SourceGenerator_IndexNameNotDeclaredInANamespace_ReturnsAnError() { var source = """ - [Symbol] public partial struct Alpha; + [IndexName] public partial struct Alpha; """; - SetupAndVerify(source); + _ = SetupAndVerify(source); } public Task SetupAndVerify(string source) @@ -86,7 +86,7 @@ public Task SetupAndVerify(string source) assemblyName: "TestAssembly", syntaxTrees: [syntaxTree]); - var generator = new SymbolGenerator(); + var generator = new IndexNameGenerator(); var driver = CSharpGeneratorDriver.Create(generator); driver = (CSharpGeneratorDriver)driver.RunGenerators(compilation); diff --git a/tests/Mathematics.NET.Tests.SourceGenerators.Public/IndexNames/Snapshots/IndexNameGeneratorTests.SourceGenerator_IndexNameNotDeclaredInANamespace_ReturnsAnError.verified.txt b/tests/Mathematics.NET.Tests.SourceGenerators.Public/IndexNames/Snapshots/IndexNameGeneratorTests.SourceGenerator_IndexNameNotDeclaredInANamespace_ReturnsAnError.verified.txt new file mode 100644 index 00000000..c5036944 --- /dev/null +++ b/tests/Mathematics.NET.Tests.SourceGenerators.Public/IndexNames/Snapshots/IndexNameGeneratorTests.SourceGenerator_IndexNameNotDeclaredInANamespace_ReturnsAnError.verified.txt @@ -0,0 +1,15 @@ +{ + Diagnostics: [ + { + Id: DG0001, + Title: Invalid index name declaration., + Severity: Error, + WarningLevel: 0, + Location: : (0,34)-(0,39), + HelpLink: https://mathematics.hamlettanyavong.com/guide/diagnostic_messages/difgeo/dg0001.html, + MessageFormat: Index names must be declared in namespaces., + Message: Index names must be declared in namespaces., + Category: DifGeo + } + ] +} diff --git a/tests/Mathematics.NET.Tests.SourceGenerators.Public/IndexNames/Snapshots/IndexNameGeneratorTests.SourceGenerator_StructWithIndexNameAttribute_AutoImplementsIIndexName#IndexNames.A.B.g.verified.cs b/tests/Mathematics.NET.Tests.SourceGenerators.Public/IndexNames/Snapshots/IndexNameGeneratorTests.SourceGenerator_StructWithIndexNameAttribute_AutoImplementsIIndexName#IndexNames.A.B.g.verified.cs new file mode 100644 index 00000000..838930e6 --- /dev/null +++ b/tests/Mathematics.NET.Tests.SourceGenerators.Public/IndexNames/Snapshots/IndexNameGeneratorTests.SourceGenerator_StructWithIndexNameAttribute_AutoImplementsIIndexName#IndexNames.A.B.g.verified.cs @@ -0,0 +1,13 @@ +//HintName: IndexNames.A.B.g.cs +// Auto-generated code + +using Mathematics.NET.DifferentialGeometry; + +namespace A.B; + +public readonly partial struct Delta : IIndexName +{ + /// + public const string DisplayString = "Delta"; + static string IIndexName.DisplayString => DisplayString; +} diff --git a/tests/Mathematics.NET.Tests.SourceGenerators.Public/IndexNames/Snapshots/IndexNameGeneratorTests.SourceGenerator_StructWithIndexNameAttribute_AutoImplementsIIndexName#IndexNames.A.g.verified.cs b/tests/Mathematics.NET.Tests.SourceGenerators.Public/IndexNames/Snapshots/IndexNameGeneratorTests.SourceGenerator_StructWithIndexNameAttribute_AutoImplementsIIndexName#IndexNames.A.g.verified.cs new file mode 100644 index 00000000..49f98d60 --- /dev/null +++ b/tests/Mathematics.NET.Tests.SourceGenerators.Public/IndexNames/Snapshots/IndexNameGeneratorTests.SourceGenerator_StructWithIndexNameAttribute_AutoImplementsIIndexName#IndexNames.A.g.verified.cs @@ -0,0 +1,27 @@ +//HintName: IndexNames.A.g.cs +// Auto-generated code + +using Mathematics.NET.DifferentialGeometry; + +namespace A; + +public readonly partial struct Alpha : IIndexName +{ + /// + public const string DisplayString = "Alpha"; + static string IIndexName.DisplayString => DisplayString; +} + +public readonly partial struct Beta : IIndexName +{ + /// + public const string DisplayString = "Beta"; + static string IIndexName.DisplayString => DisplayString; +} + +public readonly partial struct Gamma : IIndexName +{ + /// + public const string DisplayString = "Gamma"; + static string IIndexName.DisplayString => DisplayString; +} diff --git a/tests/Mathematics.NET.Tests.SourceGenerators.Public/IndexNames/Snapshots/IndexNameGeneratorTests.SourceGenerator_StructWithIndexNameAttribute_AutoImplementsIIndexName#IndexNames.B.C.D.g.verified.cs b/tests/Mathematics.NET.Tests.SourceGenerators.Public/IndexNames/Snapshots/IndexNameGeneratorTests.SourceGenerator_StructWithIndexNameAttribute_AutoImplementsIIndexName#IndexNames.B.C.D.g.verified.cs new file mode 100644 index 00000000..97bfdcee --- /dev/null +++ b/tests/Mathematics.NET.Tests.SourceGenerators.Public/IndexNames/Snapshots/IndexNameGeneratorTests.SourceGenerator_StructWithIndexNameAttribute_AutoImplementsIIndexName#IndexNames.B.C.D.g.verified.cs @@ -0,0 +1,20 @@ +//HintName: IndexNames.B.C.D.g.cs +// Auto-generated code + +using Mathematics.NET.DifferentialGeometry; + +namespace B.C.D; + +public readonly partial struct Zeta : IIndexName +{ + /// + public const string DisplayString = "Zeta"; + static string IIndexName.DisplayString => DisplayString; +} + +public readonly partial struct Eta : IIndexName +{ + /// + public const string DisplayString = "Eta"; + static string IIndexName.DisplayString => DisplayString; +} diff --git a/tests/Mathematics.NET.Tests.SourceGenerators.Public/IndexNames/Snapshots/IndexNameGeneratorTests.SourceGenerator_StructWithIndexNameAttribute_AutoImplementsIIndexName#IndexNames.B.C.g.verified.cs b/tests/Mathematics.NET.Tests.SourceGenerators.Public/IndexNames/Snapshots/IndexNameGeneratorTests.SourceGenerator_StructWithIndexNameAttribute_AutoImplementsIIndexName#IndexNames.B.C.g.verified.cs new file mode 100644 index 00000000..dc203fbe --- /dev/null +++ b/tests/Mathematics.NET.Tests.SourceGenerators.Public/IndexNames/Snapshots/IndexNameGeneratorTests.SourceGenerator_StructWithIndexNameAttribute_AutoImplementsIIndexName#IndexNames.B.C.g.verified.cs @@ -0,0 +1,13 @@ +//HintName: IndexNames.B.C.g.cs +// Auto-generated code + +using Mathematics.NET.DifferentialGeometry; + +namespace B.C; + +public readonly partial struct Epsilon : IIndexName +{ + /// + public const string DisplayString = "Epsilon"; + static string IIndexName.DisplayString => DisplayString; +} diff --git a/tests/Mathematics.NET.Tests.SourceGenerators.Public/Mathematics.NET.Tests.SourceGenerators.Public.csproj b/tests/Mathematics.NET.Tests.SourceGenerators.Public/Mathematics.NET.Tests.SourceGenerators.Public.csproj index 0e982e87..e4b1b3a9 100644 --- a/tests/Mathematics.NET.Tests.SourceGenerators.Public/Mathematics.NET.Tests.SourceGenerators.Public.csproj +++ b/tests/Mathematics.NET.Tests.SourceGenerators.Public/Mathematics.NET.Tests.SourceGenerators.Public.csproj @@ -7,7 +7,7 @@ - + diff --git a/tests/Mathematics.NET.Tests.SourceGenerators.Public/Symbols/Snapshots/SymbolGeneratorTests.SourceGenerator_StructWithSymbolAttribute_AutoImplementsISymbol#Symbols.A.B.g.verified.cs b/tests/Mathematics.NET.Tests.SourceGenerators.Public/Symbols/Snapshots/SymbolGeneratorTests.SourceGenerator_StructWithSymbolAttribute_AutoImplementsISymbol#Symbols.A.B.g.verified.cs deleted file mode 100644 index 5548dbf8..00000000 --- a/tests/Mathematics.NET.Tests.SourceGenerators.Public/Symbols/Snapshots/SymbolGeneratorTests.SourceGenerator_StructWithSymbolAttribute_AutoImplementsISymbol#Symbols.A.B.g.verified.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Auto-generated code - -using Mathematics.NET.Symbols; - -namespace A.B; - -public readonly partial struct Delta : ISymbol -{ - /// - public const string DisplayString = "Delta"; - - static string ISymbol.DisplayString => DisplayString; -} diff --git a/tests/Mathematics.NET.Tests.SourceGenerators.Public/Symbols/Snapshots/SymbolGeneratorTests.SourceGenerator_StructWithSymbolAttribute_AutoImplementsISymbol#Symbols.A.g.verified.cs b/tests/Mathematics.NET.Tests.SourceGenerators.Public/Symbols/Snapshots/SymbolGeneratorTests.SourceGenerator_StructWithSymbolAttribute_AutoImplementsISymbol#Symbols.A.g.verified.cs deleted file mode 100644 index b473e059..00000000 --- a/tests/Mathematics.NET.Tests.SourceGenerators.Public/Symbols/Snapshots/SymbolGeneratorTests.SourceGenerator_StructWithSymbolAttribute_AutoImplementsISymbol#Symbols.A.g.verified.cs +++ /dev/null @@ -1,29 +0,0 @@ -// Auto-generated code - -using Mathematics.NET.Symbols; - -namespace A; - -public readonly partial struct Alpha : ISymbol -{ - /// - public const string DisplayString = "Alpha"; - - static string ISymbol.DisplayString => DisplayString; -} - -public readonly partial struct Beta : ISymbol -{ - /// - public const string DisplayString = "Beta"; - - static string ISymbol.DisplayString => DisplayString; -} - -public readonly partial struct Gamma : ISymbol -{ - /// - public const string DisplayString = "Gamma"; - - static string ISymbol.DisplayString => DisplayString; -} diff --git a/tests/Mathematics.NET.Tests.SourceGenerators.Public/Symbols/Snapshots/SymbolGeneratorTests.SourceGenerator_StructWithSymbolAttribute_AutoImplementsISymbol#Symbols.B.C.D.g.verified.cs b/tests/Mathematics.NET.Tests.SourceGenerators.Public/Symbols/Snapshots/SymbolGeneratorTests.SourceGenerator_StructWithSymbolAttribute_AutoImplementsISymbol#Symbols.B.C.D.g.verified.cs deleted file mode 100644 index 21fe215d..00000000 --- a/tests/Mathematics.NET.Tests.SourceGenerators.Public/Symbols/Snapshots/SymbolGeneratorTests.SourceGenerator_StructWithSymbolAttribute_AutoImplementsISymbol#Symbols.B.C.D.g.verified.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Auto-generated code - -using Mathematics.NET.Symbols; - -namespace B.C.D; - -public readonly partial struct Zeta : ISymbol -{ - /// - public const string DisplayString = "Zeta"; - - static string ISymbol.DisplayString => DisplayString; -} - -public readonly partial struct Eta : ISymbol -{ - /// - public const string DisplayString = "Eta"; - - static string ISymbol.DisplayString => DisplayString; -} diff --git a/tests/Mathematics.NET.Tests.SourceGenerators.Public/Symbols/Snapshots/SymbolGeneratorTests.SourceGenerator_StructWithSymbolAttribute_AutoImplementsISymbol#Symbols.B.C.g.verified.cs b/tests/Mathematics.NET.Tests.SourceGenerators.Public/Symbols/Snapshots/SymbolGeneratorTests.SourceGenerator_StructWithSymbolAttribute_AutoImplementsISymbol#Symbols.B.C.g.verified.cs deleted file mode 100644 index 6a134c33..00000000 --- a/tests/Mathematics.NET.Tests.SourceGenerators.Public/Symbols/Snapshots/SymbolGeneratorTests.SourceGenerator_StructWithSymbolAttribute_AutoImplementsISymbol#Symbols.B.C.g.verified.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Auto-generated code - -using Mathematics.NET.Symbols; - -namespace B.C; - -public readonly partial struct Epsilon : ISymbol -{ - /// - public const string DisplayString = "Epsilon"; - - static string ISymbol.DisplayString => DisplayString; -} diff --git a/tests/Mathematics.NET.Tests.SourceGenerators.Public/Symbols/Snapshots/SymbolGeneratorTests.SourceGenerator_SymbolNotDeclaredInANamespace_ReturnsAnError.verified.txt b/tests/Mathematics.NET.Tests.SourceGenerators.Public/Symbols/Snapshots/SymbolGeneratorTests.SourceGenerator_SymbolNotDeclaredInANamespace_ReturnsAnError.verified.txt deleted file mode 100644 index 9241acc3..00000000 --- a/tests/Mathematics.NET.Tests.SourceGenerators.Public/Symbols/Snapshots/SymbolGeneratorTests.SourceGenerator_SymbolNotDeclaredInANamespace_ReturnsAnError.verified.txt +++ /dev/null @@ -1,15 +0,0 @@ -{ - Diagnostics: [ - { - Id: SGS0001, - Title: Invalid symbol declaration, - Severity: Error, - WarningLevel: 0, - Location: : (0,31)-(0,36), - HelpLink: https://mathematics.hamlettanyavong.com/guide/diagnostic_messages/symbols/sgs0001.html, - MessageFormat: Symbols must be declared in namespaces., - Message: Symbols must be declared in namespaces., - Category: Symbols - } - ] -} diff --git a/tests/Mathematics.NET.Tests.SourceGenerators/DifferentialGeometry/Snapshots/TensorContractionGeneratorTests.SourceGenerator_RankThreeTensors_GeneratesContractions#DifGeo.Contractions.g.verified.cs b/tests/Mathematics.NET.Tests.SourceGenerators/DifferentialGeometry/Snapshots/TensorContractionGeneratorTests.SourceGenerator_RankThreeTensors_GeneratesContractions#DifGeo.Contractions.g.verified.cs index 5b7eec17..81580f81 100644 --- a/tests/Mathematics.NET.Tests.SourceGenerators/DifferentialGeometry/Snapshots/TensorContractionGeneratorTests.SourceGenerator_RankThreeTensors_GeneratesContractions#DifGeo.Contractions.g.verified.cs +++ b/tests/Mathematics.NET.Tests.SourceGenerators/DifferentialGeometry/Snapshots/TensorContractionGeneratorTests.SourceGenerator_RankThreeTensors_GeneratesContractions#DifGeo.Contractions.g.verified.cs @@ -1,14 +1,14 @@ -// Auto-generated code +//HintName: DifGeo.Contractions.g.cs +// Auto-generated code using Mathematics.NET.DifferentialGeometry.Abstractions; using Mathematics.NET.LinearAlgebra; using Mathematics.NET.LinearAlgebra.Abstractions; -using Mathematics.NET.Symbols; namespace Mathematics.NET.DifferentialGeometry; public static partial class DifGeo { public static Tensor, TN, TI1, TI2, TI3, TI4> Contract(in IRankThreeTensor, TN, Index, TI1, TI2> a, in IRankThreeTensor, TN, Index, TI3, TI4> b) - where TLR3T : IRankThreeTensor, TN, Index, TI1, TI2> where TRR3T : IRankThreeTensor, TN, Index, TI3, TI4> where TN : IComplex, IDifferentiableFunctions where TCI : ISymbol where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex + where TLR3T : IRankThreeTensor, TN, Index, TI1, TI2> where TRR3T : IRankThreeTensor, TN, Index, TI3, TI4> where TN : IComplex, IDifferentiableFunctions where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex { Array4x4x4x4 array = new(); for (int i = 0; i < 4; i++) @@ -32,7 +32,7 @@ public static Tensor, TN, TI1, TI2, TI3, TI4> Contract, TN, TI1, TI2, TI3, TI4> Contract(in IRankThreeTensor, TN, Index, TI1, TI2> a, in IRankThreeTensor, TN, TI3, Index, TI4> b) - where TLR3T : IRankThreeTensor, TN, Index, TI1, TI2> where TRR3T : IRankThreeTensor, TN, TI3, Index, TI4> where TN : IComplex, IDifferentiableFunctions where TCI : ISymbol where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex + where TLR3T : IRankThreeTensor, TN, Index, TI1, TI2> where TRR3T : IRankThreeTensor, TN, TI3, Index, TI4> where TN : IComplex, IDifferentiableFunctions where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex { Array4x4x4x4 array = new(); for (int i = 0; i < 4; i++) @@ -56,7 +56,7 @@ public static Tensor, TN, TI1, TI2, TI3, TI4> Contract, TN, TI1, TI2, TI3, TI4> Contract(in IRankThreeTensor, TN, Index, TI1, TI2> a, in IRankThreeTensor, TN, TI3, Index, TI4> b) - where TLR3T : IRankThreeTensor, TN, Index, TI1, TI2> where TRR3T : IRankThreeTensor, TN, TI3, Index, TI4> where TN : IComplex, IDifferentiableFunctions where TCI : ISymbol where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex + where TLR3T : IRankThreeTensor, TN, Index, TI1, TI2> where TRR3T : IRankThreeTensor, TN, TI3, Index, TI4> where TN : IComplex, IDifferentiableFunctions where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex { Array4x4x4x4 array = new(); for (int i = 0; i < 4; i++) @@ -80,7 +80,7 @@ public static Tensor, TN, TI1, TI2, TI3, TI4> Contract, TN, TI1, TI2, TI3, TI4> Contract(in IRankThreeTensor, TN, Index, TI1, TI2> a, in IRankThreeTensor, TN, TI3, TI4, Index> b) - where TLR3T : IRankThreeTensor, TN, Index, TI1, TI2> where TRR3T : IRankThreeTensor, TN, TI3, TI4, Index> where TN : IComplex, IDifferentiableFunctions where TCI : ISymbol where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex + where TLR3T : IRankThreeTensor, TN, Index, TI1, TI2> where TRR3T : IRankThreeTensor, TN, TI3, TI4, Index> where TN : IComplex, IDifferentiableFunctions where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex { Array4x4x4x4 array = new(); for (int i = 0; i < 4; i++) @@ -104,7 +104,7 @@ public static Tensor, TN, TI1, TI2, TI3, TI4> Contract, TN, TI1, TI2, TI3, TI4> Contract(in IRankThreeTensor, TN, Index, TI1, TI2> a, in IRankThreeTensor, TN, TI3, TI4, Index> b) - where TLR3T : IRankThreeTensor, TN, Index, TI1, TI2> where TRR3T : IRankThreeTensor, TN, TI3, TI4, Index> where TN : IComplex, IDifferentiableFunctions where TCI : ISymbol where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex + where TLR3T : IRankThreeTensor, TN, Index, TI1, TI2> where TRR3T : IRankThreeTensor, TN, TI3, TI4, Index> where TN : IComplex, IDifferentiableFunctions where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex { Array4x4x4x4 array = new(); for (int i = 0; i < 4; i++) @@ -128,7 +128,7 @@ public static Tensor, TN, TI1, TI2, TI3, TI4> Contract, TN, TI1, TI2, TI3, TI4> Contract(in IRankThreeTensor, TN, TI1, Index, TI2> a, in IRankThreeTensor, TN, Index, TI3, TI4> b) - where TLR3T : IRankThreeTensor, TN, TI1, Index, TI2> where TRR3T : IRankThreeTensor, TN, Index, TI3, TI4> where TN : IComplex, IDifferentiableFunctions where TCI : ISymbol where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex + where TLR3T : IRankThreeTensor, TN, TI1, Index, TI2> where TRR3T : IRankThreeTensor, TN, Index, TI3, TI4> where TN : IComplex, IDifferentiableFunctions where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex { Array4x4x4x4 array = new(); for (int i = 0; i < 4; i++) @@ -152,7 +152,7 @@ public static Tensor, TN, TI1, TI2, TI3, TI4> Contract, TN, TI1, TI2, TI3, TI4> Contract(in IRankThreeTensor, TN, TI1, Index, TI2> a, in IRankThreeTensor, TN, Index, TI3, TI4> b) - where TLR3T : IRankThreeTensor, TN, TI1, Index, TI2> where TRR3T : IRankThreeTensor, TN, Index, TI3, TI4> where TN : IComplex, IDifferentiableFunctions where TCI : ISymbol where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex + where TLR3T : IRankThreeTensor, TN, TI1, Index, TI2> where TRR3T : IRankThreeTensor, TN, Index, TI3, TI4> where TN : IComplex, IDifferentiableFunctions where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex { Array4x4x4x4 array = new(); for (int i = 0; i < 4; i++) @@ -176,7 +176,7 @@ public static Tensor, TN, TI1, TI2, TI3, TI4> Contract, TN, TI1, TI2, TI3, TI4> Contract(in IRankThreeTensor, TN, TI1, Index, TI2> a, in IRankThreeTensor, TN, TI3, Index, TI4> b) - where TLR3T : IRankThreeTensor, TN, TI1, Index, TI2> where TRR3T : IRankThreeTensor, TN, TI3, Index, TI4> where TN : IComplex, IDifferentiableFunctions where TCI : ISymbol where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex + where TLR3T : IRankThreeTensor, TN, TI1, Index, TI2> where TRR3T : IRankThreeTensor, TN, TI3, Index, TI4> where TN : IComplex, IDifferentiableFunctions where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex { Array4x4x4x4 array = new(); for (int i = 0; i < 4; i++) @@ -200,7 +200,7 @@ public static Tensor, TN, TI1, TI2, TI3, TI4> Contract, TN, TI1, TI2, TI3, TI4> Contract(in IRankThreeTensor, TN, TI1, Index, TI2> a, in IRankThreeTensor, TN, TI3, Index, TI4> b) - where TLR3T : IRankThreeTensor, TN, TI1, Index, TI2> where TRR3T : IRankThreeTensor, TN, TI3, Index, TI4> where TN : IComplex, IDifferentiableFunctions where TCI : ISymbol where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex + where TLR3T : IRankThreeTensor, TN, TI1, Index, TI2> where TRR3T : IRankThreeTensor, TN, TI3, Index, TI4> where TN : IComplex, IDifferentiableFunctions where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex { Array4x4x4x4 array = new(); for (int i = 0; i < 4; i++) @@ -224,7 +224,7 @@ public static Tensor, TN, TI1, TI2, TI3, TI4> Contract, TN, TI1, TI2, TI3, TI4> Contract(in IRankThreeTensor, TN, TI1, Index, TI2> a, in IRankThreeTensor, TN, TI3, TI4, Index> b) - where TLR3T : IRankThreeTensor, TN, TI1, Index, TI2> where TRR3T : IRankThreeTensor, TN, TI3, TI4, Index> where TN : IComplex, IDifferentiableFunctions where TCI : ISymbol where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex + where TLR3T : IRankThreeTensor, TN, TI1, Index, TI2> where TRR3T : IRankThreeTensor, TN, TI3, TI4, Index> where TN : IComplex, IDifferentiableFunctions where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex { Array4x4x4x4 array = new(); for (int i = 0; i < 4; i++) @@ -248,7 +248,7 @@ public static Tensor, TN, TI1, TI2, TI3, TI4> Contract, TN, TI1, TI2, TI3, TI4> Contract(in IRankThreeTensor, TN, TI1, Index, TI2> a, in IRankThreeTensor, TN, TI3, TI4, Index> b) - where TLR3T : IRankThreeTensor, TN, TI1, Index, TI2> where TRR3T : IRankThreeTensor, TN, TI3, TI4, Index> where TN : IComplex, IDifferentiableFunctions where TCI : ISymbol where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex + where TLR3T : IRankThreeTensor, TN, TI1, Index, TI2> where TRR3T : IRankThreeTensor, TN, TI3, TI4, Index> where TN : IComplex, IDifferentiableFunctions where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex { Array4x4x4x4 array = new(); for (int i = 0; i < 4; i++) @@ -272,7 +272,7 @@ public static Tensor, TN, TI1, TI2, TI3, TI4> Contract, TN, TI1, TI2, TI3, TI4> Contract(in IRankThreeTensor, TN, TI1, TI2, Index> a, in IRankThreeTensor, TN, Index, TI3, TI4> b) - where TLR3T : IRankThreeTensor, TN, TI1, TI2, Index> where TRR3T : IRankThreeTensor, TN, Index, TI3, TI4> where TN : IComplex, IDifferentiableFunctions where TCI : ISymbol where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex + where TLR3T : IRankThreeTensor, TN, TI1, TI2, Index> where TRR3T : IRankThreeTensor, TN, Index, TI3, TI4> where TN : IComplex, IDifferentiableFunctions where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex { Array4x4x4x4 array = new(); for (int i = 0; i < 4; i++) @@ -296,7 +296,7 @@ public static Tensor, TN, TI1, TI2, TI3, TI4> Contract, TN, TI1, TI2, TI3, TI4> Contract(in IRankThreeTensor, TN, TI1, TI2, Index> a, in IRankThreeTensor, TN, Index, TI3, TI4> b) - where TLR3T : IRankThreeTensor, TN, TI1, TI2, Index> where TRR3T : IRankThreeTensor, TN, Index, TI3, TI4> where TN : IComplex, IDifferentiableFunctions where TCI : ISymbol where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex + where TLR3T : IRankThreeTensor, TN, TI1, TI2, Index> where TRR3T : IRankThreeTensor, TN, Index, TI3, TI4> where TN : IComplex, IDifferentiableFunctions where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex { Array4x4x4x4 array = new(); for (int i = 0; i < 4; i++) @@ -320,7 +320,7 @@ public static Tensor, TN, TI1, TI2, TI3, TI4> Contract, TN, TI1, TI2, TI3, TI4> Contract(in IRankThreeTensor, TN, TI1, TI2, Index> a, in IRankThreeTensor, TN, TI3, Index, TI4> b) - where TLR3T : IRankThreeTensor, TN, TI1, TI2, Index> where TRR3T : IRankThreeTensor, TN, TI3, Index, TI4> where TN : IComplex, IDifferentiableFunctions where TCI : ISymbol where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex + where TLR3T : IRankThreeTensor, TN, TI1, TI2, Index> where TRR3T : IRankThreeTensor, TN, TI3, Index, TI4> where TN : IComplex, IDifferentiableFunctions where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex { Array4x4x4x4 array = new(); for (int i = 0; i < 4; i++) @@ -344,7 +344,7 @@ public static Tensor, TN, TI1, TI2, TI3, TI4> Contract, TN, TI1, TI2, TI3, TI4> Contract(in IRankThreeTensor, TN, TI1, TI2, Index> a, in IRankThreeTensor, TN, TI3, Index, TI4> b) - where TLR3T : IRankThreeTensor, TN, TI1, TI2, Index> where TRR3T : IRankThreeTensor, TN, TI3, Index, TI4> where TN : IComplex, IDifferentiableFunctions where TCI : ISymbol where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex + where TLR3T : IRankThreeTensor, TN, TI1, TI2, Index> where TRR3T : IRankThreeTensor, TN, TI3, Index, TI4> where TN : IComplex, IDifferentiableFunctions where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex { Array4x4x4x4 array = new(); for (int i = 0; i < 4; i++) @@ -368,7 +368,7 @@ public static Tensor, TN, TI1, TI2, TI3, TI4> Contract, TN, TI1, TI2, TI3, TI4> Contract(in IRankThreeTensor, TN, TI1, TI2, Index> a, in IRankThreeTensor, TN, TI3, TI4, Index> b) - where TLR3T : IRankThreeTensor, TN, TI1, TI2, Index> where TRR3T : IRankThreeTensor, TN, TI3, TI4, Index> where TN : IComplex, IDifferentiableFunctions where TCI : ISymbol where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex + where TLR3T : IRankThreeTensor, TN, TI1, TI2, Index> where TRR3T : IRankThreeTensor, TN, TI3, TI4, Index> where TN : IComplex, IDifferentiableFunctions where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex { Array4x4x4x4 array = new(); for (int i = 0; i < 4; i++) @@ -392,7 +392,7 @@ public static Tensor, TN, TI1, TI2, TI3, TI4> Contract, TN, TI1, TI2, TI3, TI4> Contract(in IRankThreeTensor, TN, TI1, TI2, Index> a, in IRankThreeTensor, TN, TI3, TI4, Index> b) - where TLR3T : IRankThreeTensor, TN, TI1, TI2, Index> where TRR3T : IRankThreeTensor, TN, TI3, TI4, Index> where TN : IComplex, IDifferentiableFunctions where TCI : ISymbol where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex + where TLR3T : IRankThreeTensor, TN, TI1, TI2, Index> where TRR3T : IRankThreeTensor, TN, TI3, TI4, Index> where TN : IComplex, IDifferentiableFunctions where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex where TI4 : IIndex { Array4x4x4x4 array = new(); for (int i = 0; i < 4; i++) diff --git a/tests/Mathematics.NET.Tests.SourceGenerators/DifferentialGeometry/Snapshots/TensorSelfContractionGeneratorTests.SourceGenerator_RankFourTensor_GeneratesSelfContractions#DifGeo.SelfContractions.g.verified.cs b/tests/Mathematics.NET.Tests.SourceGenerators/DifferentialGeometry/Snapshots/TensorSelfContractionGeneratorTests.SourceGenerator_RankFourTensor_GeneratesSelfContractions#DifGeo.SelfContractions.g.verified.cs index 40a7e466..c6e865e6 100644 --- a/tests/Mathematics.NET.Tests.SourceGenerators/DifferentialGeometry/Snapshots/TensorSelfContractionGeneratorTests.SourceGenerator_RankFourTensor_GeneratesSelfContractions#DifGeo.SelfContractions.g.verified.cs +++ b/tests/Mathematics.NET.Tests.SourceGenerators/DifferentialGeometry/Snapshots/TensorSelfContractionGeneratorTests.SourceGenerator_RankFourTensor_GeneratesSelfContractions#DifGeo.SelfContractions.g.verified.cs @@ -1,14 +1,14 @@ -// Auto-generated code +//HintName: DifGeo.SelfContractions.g.cs +// Auto-generated code using Mathematics.NET.DifferentialGeometry.Abstractions; using Mathematics.NET.LinearAlgebra; using Mathematics.NET.LinearAlgebra.Abstractions; -using Mathematics.NET.Symbols; namespace Mathematics.NET.DifferentialGeometry; public static partial class DifGeo { public static Tensor, TN, TI1, TI2> Contract(in IRankFourTensor, TN, Index, Index, TI1, TI2> a) - where TR4T : IRankFourTensor, TN, Index, Index, TI1, TI2> where TN : IComplex, IDifferentiableFunctions where TCI : ISymbol where TI1 : IIndex where TI2 : IIndex + where TR4T : IRankFourTensor, TN, Index, Index, TI1, TI2> where TN : IComplex, IDifferentiableFunctions where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex { Matrix4x4 matrix = new(); for (int i = 0; i < 4; i++) @@ -26,7 +26,7 @@ public static Tensor, TN, TI1, TI2> Contract, TN, TI1, TI2> Contract(in IRankFourTensor, TN, Index, TI1, Index, TI2> a) - where TR4T : IRankFourTensor, TN, Index, TI1, Index, TI2> where TN : IComplex, IDifferentiableFunctions where TCI : ISymbol where TI1 : IIndex where TI2 : IIndex + where TR4T : IRankFourTensor, TN, Index, TI1, Index, TI2> where TN : IComplex, IDifferentiableFunctions where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex { Matrix4x4 matrix = new(); for (int i = 0; i < 4; i++) @@ -44,7 +44,7 @@ public static Tensor, TN, TI1, TI2> Contract, TN, TI1, TI2> Contract(in IRankFourTensor, TN, Index, TI1, Index, TI2> a) - where TR4T : IRankFourTensor, TN, Index, TI1, Index, TI2> where TN : IComplex, IDifferentiableFunctions where TCI : ISymbol where TI1 : IIndex where TI2 : IIndex + where TR4T : IRankFourTensor, TN, Index, TI1, Index, TI2> where TN : IComplex, IDifferentiableFunctions where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex { Matrix4x4 matrix = new(); for (int i = 0; i < 4; i++) @@ -62,7 +62,7 @@ public static Tensor, TN, TI1, TI2> Contract, TN, TI1, TI2> Contract(in IRankFourTensor, TN, Index, TI1, TI2, Index> a) - where TR4T : IRankFourTensor, TN, Index, TI1, TI2, Index> where TN : IComplex, IDifferentiableFunctions where TCI : ISymbol where TI1 : IIndex where TI2 : IIndex + where TR4T : IRankFourTensor, TN, Index, TI1, TI2, Index> where TN : IComplex, IDifferentiableFunctions where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex { Matrix4x4 matrix = new(); for (int i = 0; i < 4; i++) @@ -80,7 +80,7 @@ public static Tensor, TN, TI1, TI2> Contract, TN, TI1, TI2> Contract(in IRankFourTensor, TN, Index, TI1, TI2, Index> a) - where TR4T : IRankFourTensor, TN, Index, TI1, TI2, Index> where TN : IComplex, IDifferentiableFunctions where TCI : ISymbol where TI1 : IIndex where TI2 : IIndex + where TR4T : IRankFourTensor, TN, Index, TI1, TI2, Index> where TN : IComplex, IDifferentiableFunctions where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex { Matrix4x4 matrix = new(); for (int i = 0; i < 4; i++) @@ -98,7 +98,7 @@ public static Tensor, TN, TI1, TI2> Contract, TN, TI1, TI2> Contract(in IRankFourTensor, TN, TI1, Index, Index, TI2> a) - where TR4T : IRankFourTensor, TN, TI1, Index, Index, TI2> where TN : IComplex, IDifferentiableFunctions where TCI : ISymbol where TI1 : IIndex where TI2 : IIndex + where TR4T : IRankFourTensor, TN, TI1, Index, Index, TI2> where TN : IComplex, IDifferentiableFunctions where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex { Matrix4x4 matrix = new(); for (int i = 0; i < 4; i++) @@ -116,7 +116,7 @@ public static Tensor, TN, TI1, TI2> Contract, TN, TI1, TI2> Contract(in IRankFourTensor, TN, TI1, Index, Index, TI2> a) - where TR4T : IRankFourTensor, TN, TI1, Index, Index, TI2> where TN : IComplex, IDifferentiableFunctions where TCI : ISymbol where TI1 : IIndex where TI2 : IIndex + where TR4T : IRankFourTensor, TN, TI1, Index, Index, TI2> where TN : IComplex, IDifferentiableFunctions where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex { Matrix4x4 matrix = new(); for (int i = 0; i < 4; i++) @@ -134,7 +134,7 @@ public static Tensor, TN, TI1, TI2> Contract, TN, TI1, TI2> Contract(in IRankFourTensor, TN, TI1, Index, TI2, Index> a) - where TR4T : IRankFourTensor, TN, TI1, Index, TI2, Index> where TN : IComplex, IDifferentiableFunctions where TCI : ISymbol where TI1 : IIndex where TI2 : IIndex + where TR4T : IRankFourTensor, TN, TI1, Index, TI2, Index> where TN : IComplex, IDifferentiableFunctions where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex { Matrix4x4 matrix = new(); for (int i = 0; i < 4; i++) @@ -152,7 +152,7 @@ public static Tensor, TN, TI1, TI2> Contract, TN, TI1, TI2> Contract(in IRankFourTensor, TN, TI1, Index, TI2, Index> a) - where TR4T : IRankFourTensor, TN, TI1, Index, TI2, Index> where TN : IComplex, IDifferentiableFunctions where TCI : ISymbol where TI1 : IIndex where TI2 : IIndex + where TR4T : IRankFourTensor, TN, TI1, Index, TI2, Index> where TN : IComplex, IDifferentiableFunctions where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex { Matrix4x4 matrix = new(); for (int i = 0; i < 4; i++) @@ -170,7 +170,7 @@ public static Tensor, TN, TI1, TI2> Contract, TN, TI1, TI2> Contract(in IRankFourTensor, TN, TI1, TI2, Index, Index> a) - where TR4T : IRankFourTensor, TN, TI1, TI2, Index, Index> where TN : IComplex, IDifferentiableFunctions where TCI : ISymbol where TI1 : IIndex where TI2 : IIndex + where TR4T : IRankFourTensor, TN, TI1, TI2, Index, Index> where TN : IComplex, IDifferentiableFunctions where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex { Matrix4x4 matrix = new(); for (int i = 0; i < 4; i++) @@ -188,7 +188,7 @@ public static Tensor, TN, TI1, TI2> Contract, TN, TI1, TI2> Contract(in IRankFourTensor, TN, TI1, TI2, Index, Index> a) - where TR4T : IRankFourTensor, TN, TI1, TI2, Index, Index> where TN : IComplex, IDifferentiableFunctions where TCI : ISymbol where TI1 : IIndex where TI2 : IIndex + where TR4T : IRankFourTensor, TN, TI1, TI2, Index, Index> where TN : IComplex, IDifferentiableFunctions where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex { Matrix4x4 matrix = new(); for (int i = 0; i < 4; i++) diff --git a/tests/Mathematics.NET.Tests.SourceGenerators/DifferentialGeometry/TensorContractionGeneratorTests.cs b/tests/Mathematics.NET.Tests.SourceGenerators/DifferentialGeometry/TensorContractionGeneratorTests.cs index dd2f6979..adc22482 100644 --- a/tests/Mathematics.NET.Tests.SourceGenerators/DifferentialGeometry/TensorContractionGeneratorTests.cs +++ b/tests/Mathematics.NET.Tests.SourceGenerators/DifferentialGeometry/TensorContractionGeneratorTests.cs @@ -47,7 +47,7 @@ public static Tensor, TN, TI1, TI2, TI3, TI4> Contract, TN, Index, TI1, TI2> where TRR3T : IRankThreeTensor, TN, Index, TI3, TI4> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex where TI3 : IIndex diff --git a/tests/Mathematics.NET.Tests.SourceGenerators/DifferentialGeometry/TensorSelfContractionGeneratorTests.cs b/tests/Mathematics.NET.Tests.SourceGenerators/DifferentialGeometry/TensorSelfContractionGeneratorTests.cs index 0b6798b8..8b6b4bce 100644 --- a/tests/Mathematics.NET.Tests.SourceGenerators/DifferentialGeometry/TensorSelfContractionGeneratorTests.cs +++ b/tests/Mathematics.NET.Tests.SourceGenerators/DifferentialGeometry/TensorSelfContractionGeneratorTests.cs @@ -44,7 +44,7 @@ namespace TestNamespace; public static Tensor, TN, TI1, TI2> Contract(in IRankFourTensor, TN, Index, Index, TI1, TI2> a) where TR4T : IRankFourTensor, TN, Index, Index, TI1, TI2> where TN : IComplex, IDifferentiableFunctions - where TCI : ISymbol + where TCI : IIndexName where TI1 : IIndex where TI2 : IIndex { @@ -63,7 +63,7 @@ public static Tensor, TN, TI1, TI2> Contract - + diff --git a/tests/Mathematics.NET.Tests/AutoDiff/GradientTapeOfRealTests.cs b/tests/Mathematics.NET.Tests/AutoDiff/GradientTapeOfRealTests.cs index 8d63fe40..c520d02a 100644 --- a/tests/Mathematics.NET.Tests/AutoDiff/GradientTapeOfRealTests.cs +++ b/tests/Mathematics.NET.Tests/AutoDiff/GradientTapeOfRealTests.cs @@ -207,9 +207,13 @@ public void Atan_Variable_ReturnsValue(double input, double expected) [DataRow(1.23, 2.34, 0.334835801674179, -0.1760034342133505)] public void Atan2_TwoVariables_ReturnsGradient(double left, double right, double expectedLeft, double expectedRight) { + var y = _tape.CreateVariable(left); + var x = _tape.CreateVariable(right); + _ = _tape.Atan2(y, x); + Real[] expected = [expectedLeft, expectedRight]; - var actual = ComputeGradient(_tape.Atan2, left, right); + _tape.ReverseAccumulate(out var actual); Assert.AreApproximatelyEqual(expected, actual, 1e-15); } @@ -218,7 +222,10 @@ public void Atan2_TwoVariables_ReturnsGradient(double left, double right, double [DataRow(1.23, 2.34, 0.4839493878600246)] public void Atan2_TwoVariables_ReturnsValue(double left, double right, double expected) { - var actual = ComputeValue(_tape.Atan2, left, right); + var y = _tape.CreateVariable(left); + var x = _tape.CreateVariable(right); + + var actual = _tape.Atan2(y, x).Value; Assert.AreApproximatelyEqual(expected, actual, 1e-15); } @@ -328,10 +335,11 @@ public void CustomOperation_Binary_ReturnsGradient(double left, double right, do var x = _tape.CreateVariable(right); var u = Real.One / (x.Value * x.Value + y.Value * y.Value); _ = _tape.CustomOperation(y, x, Real.Atan2, (y, x) => x * u, (y, x) => -y * u); - _tape.ReverseAccumulate(out var actual); Real[] expected = [expectedLeft, expectedRight]; + _tape.ReverseAccumulate(out var actual); + Assert.AreApproximatelyEqual(expected, actual, 1e-15); } @@ -572,9 +580,13 @@ public void Log10_Variable_ReturnsValue(double input, double expected) [DataRow(1.23, 2.34, 1, 0)] public void Modulo_TwoVariables_ReturnsGradient(double left, double right, double expectedLeft, double expectedRight) { + var x = _tape.CreateVariable(left); + var y = _tape.CreateVariable(right); + _ = _tape.Modulo(x, y); + Real[] expected = [expectedLeft, expectedRight]; - var actual = ComputeGradient(_tape.Modulo, left, right); + _tape.ReverseAccumulate(out var actual); Assert.AreApproximatelyEqual(expected, actual, Real.Zero); } @@ -583,7 +595,10 @@ public void Modulo_TwoVariables_ReturnsGradient(double left, double right, doubl [DataRow(3.14, 2.34, 0.8)] public void Modulo_TwoVariables_ReturnsValue(double left, double right, double expected) { - var actual = ComputeValue(_tape.Modulo, left, right); + var x = _tape.CreateVariable(left); + var y = _tape.CreateVariable(right); + + var actual = _tape.Modulo(x, y).Value; Assert.AreApproximatelyEqual(expected, actual, 1e-15); } diff --git a/tests/Mathematics.NET.Tests/AutoDiff/HessianTapeOfRealTests.cs b/tests/Mathematics.NET.Tests/AutoDiff/HessianTapeOfRealTests.cs index e59a97e9..948af819 100644 --- a/tests/Mathematics.NET.Tests/AutoDiff/HessianTapeOfRealTests.cs +++ b/tests/Mathematics.NET.Tests/AutoDiff/HessianTapeOfRealTests.cs @@ -289,9 +289,13 @@ public void Atan_Variable_ReturnsValue(double input, double expected) [DataRow(1.23, 2.34, 0.334835801674179, -0.1760034342133505)] public void Atan2_TwoVariables_ReturnsGradient(double left, double right, double expectedLeft, double expectedRight) { + var y = _tape.CreateVariable(left); + var x = _tape.CreateVariable(right); + _ = _tape.Atan2(y, x); + Real[] expected = [expectedLeft, expectedRight]; - var actual = ComputeGradient(_tape.Atan2, left, right); + _tape.ReverseAccumulate(out ReadOnlySpan actual); Assert.AreApproximatelyEqual(expected, actual, 1e-15); } @@ -300,9 +304,13 @@ public void Atan2_TwoVariables_ReturnsGradient(double left, double right, double [DataRow(1.23, 2.34, -0.1178645019844717, -0.081137805227897, 0.1178645019844717)] public void Atan2_TwoVariables_ReturnsHessian(double left, double right, double expectedXX, double expectedXY, double expectedYY) { + var y = _tape.CreateVariable(left); + var x = _tape.CreateVariable(right); + _ = _tape.Atan2(y, x); + Real[,] expected = new Real[2, 2] { { expectedXX, expectedXY }, { expectedXY, expectedYY } }; - var actual = ComputeHessian(_tape.Atan2, left, right); + _tape.ReverseAccumulate(out ReadOnlySpan2D actual); Assert.AreApproximatelyEqual(expected, actual, 1e-14); } @@ -311,7 +319,10 @@ public void Atan2_TwoVariables_ReturnsHessian(double left, double right, double [DataRow(1.23, 2.34, 0.4839493878600246)] public void Atan2_TwoVariables_ReturnsValue(double left, double right, double expected) { - var actual = ComputeValue(_tape.Atan2, left, right); + var y = _tape.CreateVariable(left); + var x = _tape.CreateVariable(right); + + var actual = _tape.Atan2(y, x).Value; Assert.AreApproximatelyEqual(expected, actual, 1e-15); } @@ -499,9 +510,7 @@ public void CustomOperation_Binary_ReturnsHessian(double left, double right, dou Real[,] expected = new Real[2, 2] { { expectedXX, expectedXY }, { expectedXY, expectedYY } }; - _tape.ReverseAccumulate(out ReadOnlySpan2D hessian); - - var actual = hessian.ToArray(); + _tape.ReverseAccumulate(out ReadOnlySpan2D actual); Assert.AreApproximatelyEqual(expected, actual, 1e-14); } @@ -875,9 +884,13 @@ public void Log10_Variable_ReturnsValue(double input, double expected) [DataRow(1.23, 2.34, 1, 0)] public void Modulo_TwoVariables_ReturnsGradient(double left, double right, double expectedLeft, double expectedRight) { + var x = _tape.CreateVariable(left); + var y = _tape.CreateVariable(right); + _ = _tape.Modulo(x, y); + Real[] expected = [expectedLeft, expectedRight]; - var actual = ComputeGradient(_tape.Modulo, left, right); + _tape.ReverseAccumulate(out ReadOnlySpan actual); Assert.AreApproximatelyEqual(expected, actual, Real.Zero); } @@ -886,9 +899,13 @@ public void Modulo_TwoVariables_ReturnsGradient(double left, double right, doubl [DataRow(1.23, 2.34, 0, 0, 0)] public void Modulo_TwoVariables_ReturnsHessian(double left, double right, double expectedXX, double expectedXY, double expectedYY) { + var x = _tape.CreateVariable(left); + var y = _tape.CreateVariable(right); + _ = _tape.Modulo(x, y); + Real[,] expected = new Real[2, 2] { { expectedXX, expectedXY }, { expectedXY, expectedYY } }; - var actual = ComputeHessian(_tape.Modulo, left, right); + _tape.ReverseAccumulate(out ReadOnlySpan2D actual); Assert.AreApproximatelyEqual(expected, actual, Real.Zero); } @@ -897,7 +914,10 @@ public void Modulo_TwoVariables_ReturnsHessian(double left, double right, double [DataRow(3.14, 2.34, 0.8)] public void Modulo_TwoVariables_ReturnsValue(double left, double right, double expected) { - var actual = ComputeValue(_tape.Modulo, left, right); + var x = _tape.CreateVariable(left); + var y = _tape.CreateVariable(right); + + var actual = _tape.Modulo(x, y).Value; Assert.AreApproximatelyEqual(expected, actual, 1e-15); } diff --git a/tests/Mathematics.NET.Tests/DifferentialGeometry/DifGeoTestHelpers.cs b/tests/Mathematics.NET.Tests/DifferentialGeometry/DifGeoTestHelpers.cs index 105004be..8b80961b 100644 --- a/tests/Mathematics.NET.Tests/DifferentialGeometry/DifGeoTestHelpers.cs +++ b/tests/Mathematics.NET.Tests/DifferentialGeometry/DifGeoTestHelpers.cs @@ -28,7 +28,6 @@ using Mathematics.NET.AutoDiff; using Mathematics.NET.DifferentialGeometry; using Mathematics.NET.DifferentialGeometry.Abstractions; -using Mathematics.NET.Symbols; namespace Mathematics.NET.Tests.DifferentialGeometry; @@ -107,42 +106,42 @@ private void Initialize() // Symbols // -public readonly struct Alpha : ISymbol +public readonly struct Alpha : IIndexName { - /// + /// public const string DisplayString = "Alpha"; - static string ISymbol.DisplayString => DisplayString; + static string IIndexName.DisplayString => DisplayString; } -public readonly struct Beta : ISymbol +public readonly struct Beta : IIndexName { - /// + /// public const string DisplayString = "Beta"; - static string ISymbol.DisplayString => DisplayString; + static string IIndexName.DisplayString => DisplayString; } -public readonly struct Gamma : ISymbol +public readonly struct Gamma : IIndexName { - /// + /// public const string DisplayString = "Gamma"; - static string ISymbol.DisplayString => DisplayString; + static string IIndexName.DisplayString => DisplayString; } -public readonly struct Delta : ISymbol +public readonly struct Delta : IIndexName { - /// + /// public const string DisplayString = "Delta"; - static string ISymbol.DisplayString => DisplayString; + static string IIndexName.DisplayString => DisplayString; } -public readonly struct Epsilon : ISymbol +public readonly struct Epsilon : IIndexName { - /// + /// public const string DisplayString = "Epsilon"; - static string ISymbol.DisplayString => DisplayString; + static string IIndexName.DisplayString => DisplayString; } diff --git a/tests/Mathematics.NET.Tests/Mathematics.NET.Tests.csproj b/tests/Mathematics.NET.Tests/Mathematics.NET.Tests.csproj index 503b9966..bff34e9a 100644 --- a/tests/Mathematics.NET.Tests/Mathematics.NET.Tests.csproj +++ b/tests/Mathematics.NET.Tests/Mathematics.NET.Tests.csproj @@ -7,7 +7,7 @@ - +